Example #1
0
 def get(self, username=None):
     if username:
         users_resp = Users.get_by_username(username)
     else:
         users_resp = Users.get_all()
     if users_resp is not None:
         self.write(dumps(users_resp))
     else:
         raise tornado.web.HTTPError(404)
Example #2
0
 def put(self, username):
     print('update user: '******'utf-8'))
     result = Users.update_by_id(username, doc)
     if not result:
         print('Problem updating user')
     self.write(dumps(result))
Example #3
0
 def post(self):
     print('create user')
     doc = json_decode(self.request.body.decode('utf-8'))
     user_id = Users.insert(doc)
     if not user_id:
         print('Problem inserting new user')
     self.write(dumps(res))
 def _check_password(self, username, password):
     user = Users.get_by_username(username, ['password', 'salt'])
     if not user:
         return False
     stored_pass = user['password']
     password_bytes = password.encode('utf-8')
     salt_bytes = user['salt']
     hashed_password = hashlib.sha512(
         password_bytes + salt_bytes).hexdigest()
     return stored_pass == hashed_password
 def setup_frame(self, frame):
     print('AdminManager::setup_frame')
     users = Users.get_by_frame_id(frame['_id'])
     # for each user, if the user is connected, send frame:updated event to
     # websocket client (i.e. to admin page)
     for user in users:
         user_id = user['_id']
         if user_id in self.admins:
             for ws_uuid in self.admins[user_id]:
                 data = {'frame': frame}
                 self.admins[user_id][ws_uuid].send('frame:setup', data)
 def update_admin_frame(self, frame=None, frame_id=None):
     print('AdminManager::update_admin_frame')
     print(frame)
     if frame_id is not None:
         frame = Frames.get_by_id(frame_id)
     # get users for this frame
     users = Users.get_by_frame_id(frame['_id'])
     # for each user, if the user is connected, send frame:updated event to
     # websocket client (i.e. to admin page)
     for user in users:
         user_id = user['_id']
         if user_id in self.admins:
             for ws_uuid in self.admins[user_id]:
                 self.admins[user_id][ws_uuid].send(
                     'frame:frame_updated', frame)
 def remove_frame_connection(self, frame_ws):
     print('AdminManager::remove_frame_connection: ' + frame_ws.frame_id)
     # get frame object from db
     frame = Frames.get_by_id(frame_ws.frame_id)
     # get users for this frame
     users = Users.get_by_frame_id(frame_ws.frame_id)
     # for each user, if the user is connected,
     # send frame:disconnected to the
     # websocket client
     for user in users:
         user_id = user['_id']
         if user_id in self.admins:
             for ws_uuid in self.admins[user_id]:
                 self.admins[user_id][ws_uuid].send(
                     'frame:disconnected', frame)
 def add_frame_connection(self, frame_ws):
     print('AdminManager::add_frame_connection: ' + frame_ws.frame_id)
     # get frame object from websocket object
     frame = frame_ws.frame
     # get users for this frame
     users = Users.get_by_frame_id(frame['_id'])
     # for each user, if the user is connected,
     # send frame:connected event to each
     # websocket client they have open (i.e. to admin page)
     for user in users:
         user_id = user['_id']
         if user_id in self.admins:
             for ws_uuid in self.admins[user_id]:
                 self.admins[user_id][ws_uuid].send(
                     'frame:connected', frame)
    def open(self, username):
        print("WebSocket opened " + username)
        self.user = Users.get_by_username(username)

        # admin websocket connections get a uuid since an admin user
        # might have multiple admin devices open
        self.uuid = uuid.uuid4()

        # publish this event, handled in AdminManager
        self.pubsub.publish("admin:connected", admin_ws=self)

        # listen for 'frame:update_frame' events via websockets
        self.on('frame:update_frame', self._update_frame)
        # listen for 'frame:update_content' events via websockets
        self.on('frame:mirror_frame', self._mirror_frame)
 def post(self):
     username = self.get_argument('username', '')
     password = self.get_argument('password', '')
     password_confirm = self.get_argument('password_confirm', '')
     if not password == password_confirm:
         print('passwords do not match')
         self.render('create_account.html',
                     error="Passwords do not match.")
         return
     user_id = Users.create_user(username, password)
     if user_id:
         # LOGIN
         self.login(username, '/' + username)
     else:
         self.render('create_account.html',
                     error="Problem creating account.")
Example #11
0
 def delete(self, username):
     res = Users.delete_by_id(username)
     self.write(dumps(res.acknowledged))