def post(self, *args, **kwargs): mongo_conn = asyncmongo.Client(pool_id='credentials', host=settings.MONGO_HOST, port=settings.MONGO_PORT, dbname=settings.MONGO_NAME) app_id = self.get_argument('app_id') sign_key = str(uuid.uuid4()) auth_key = str(uuid.uuid4()) user = yield to_future(mongo_conn.users.find_one)( dict( email=self.get_argument('email'), password=self.get_argument('hashed_pswd') ) ) if not user: self.set_status(401) self.write(dict(status='error', message='unauthorized')) self.finish() return yield to_future(mongo_conn.credentials.update)( dict(application_id=app_id, user_id=user['_id']), dict( application_id=app_id, user_id=user['_id'], sign_key=sign_key, auth_key=auth_key, created_at=datetime.datetime.now() ), upsert=True ) self.write(dict(sign_key=sign_key, auth_key=auth_key, status='success')) self.finish()
def post(self, *args, **kwargs): mongo_conn = asyncmongo.Client(pool_id='credentials', host=settings.MONGO_HOST, port=settings.MONGO_PORT, dbname=settings.MONGO_NAME) yield to_future(mongo_conn.users.insert)( dict( email=self.get_argument('email'), password=self.get_argument('hashed_pswd') ), safe=True ) self.set_status(200) self.finish()