Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
In no particular order...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like alphabetical order for my arbitrary orderings.


Ada Taylor '16
Luke O'Malley '14
Lars Johnson '15
Allen Park '15
Amol Bhave '17
Tim Wilczynski '14
Jesse Orlowski '16
Cosmos Darwin '15
Will Oursler '15
405 changes: 0 additions & 405 deletions src/rooms/cosmos_db.py

This file was deleted.

22 changes: 15 additions & 7 deletions src/rooms/rooms.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
#!/usr/bin/python

# Setup flask basics.
from ..utils import db
from flask import Flask, jsonify
app = Flask(__name__)

import cosmos_db

@app.route('/')
def serve_rooms():
roomnums = [ room.num for room in cosmos_db.allRooms ]
room_db = db.init('room')
rooms = room_db.query(db.Room).all()
roomnums = [ room.num for room in rooms ]
return jsonify( rooms = roomnums )

@app.route('/<roomnum>/')
def serve_room( roomnum ):
room = cosmos_db.find( roomnum )
room_db = db.init('room')
room = room_db.query(db.Room).get(roomnum)

return jsonify(
roomnum = room.num,
grt = room.grt,
capacity = room.capacity,
sq_ft = room.size,
side = room.view )
type = room.type,
size = room.size,
view = room.view,
X = room.X,
Y = room.Y,
hasCurvyWall = room.hasCurvyWall,
bathroom = room.bathroom
)

if __name__ == "__main__":
app.debug = True # TODO: Remove in production.
Expand Down
41 changes: 0 additions & 41 deletions src/testing.py

This file was deleted.

4 changes: 3 additions & 1 deletion src/utils/db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ init-db:
@# TODO: List from db.py?
python db.py init user
python db.py init group
python db.py init room

populate-db:
python authcore_setup.py
python init_auth.py
python init_rooms.py

# Remove all runtime based information.
# Should return the repo to a "source-only" state.
Expand Down
22 changes: 0 additions & 22 deletions src/utils/db/authcore_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,3 @@

from db import *

user_db = init('user')
user = user_db.query(User).get( 'admin' )
if user:
exit()
newuser = User()
newuser.username = 'admin'
newuser.salt = base64.b64encode( os.urandom(128) )
newuser.passhash = pbkdf2.PBKDF2( 'password', newuser.salt ).hexread(32)
user_db.add( newuser )
user_db.commit()

group_db = init('group')
group = group_db.query(Group).get( 'accounts-admin' )
if group:
exit()
newgroup = Group()
newgroup.groupname = 'accounts-admin'
newgroup.owner = 'accounts-admin'
newgroup.immediate_members = json.dumps(['admin'])
newgroup.subgroups = json.dumps([])
group_db.add( newgroup )
group_db.commit()
16 changes: 16 additions & 0 deletions src/utils/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

UserBase = declarative_base()
GroupBase = declarative_base()
RoomBase = declarative_base()

class User(UserBase):
__tablename__= "user"
Expand All @@ -24,6 +25,21 @@ class Group(GroupBase):
immediate_members = Column(String(512))
subgroups = Column(String(512))

class Room(RoomBase):
__tablename__ = "room"
num = Column(String, primary_key=True)
type = Column(String)
size = Column(String)
view = Column(String)
X = Column(Integer)
Y = Column(Integer)
hasCurvyWall = Column(String)
bathroom = Column(String)

class Section(RoomBase):
__tablename__ = "section"
label = Column(String, primary_key=True)

def dbsetup(name, base):
thisdir = os.path.dirname(os.path.abspath(__file__))
dbdir = os.path.join(thisdir, 'db', name)
Expand Down
32 changes: 32 additions & 0 deletions src/utils/db/init_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import base64
import pbkdf2
import os
import json

from db import *

# TODO: init_users
# TODO init_groups
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it doesn't matter, but the blatent inconsistency in formatting here makes me sad.


user_db = init('user')
user = user_db.query(User).get( 'admin' )
if user:
exit() # TODO: Shouldn't exit because other stuff runs below.
newuser = User()
newuser.username = 'admin'
newuser.salt = base64.b64encode( os.urandom(128) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generating a salted hash strikes me as something that can go in utils, although I'm not sure how often it'd be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be mostly removed once we have SRP; but if it stays around, I'll probalby move most of this code into an auth submodule (there are going to be submodules for each identity provider).

I dont think salted hashes have use outside of authentication, so I don't think it's appropriate to treat this as a first class utility.

newuser.passhash = pbkdf2.PBKDF2( 'password', newuser.salt ).hexread(32)
user_db.add( newuser )
user_db.commit()

group_db = init('group')
group = group_db.query(Group).get( 'accounts-admin' )
if group:
exit()
newgroup = Group()
newgroup.groupname = 'accounts-admin'
newgroup.owner = 'accounts-admin'
newgroup.immediate_members = json.dumps(['admin'])
newgroup.subgroups = json.dumps([])
group_db.add( newgroup )
group_db.commit()
Loading