def getS3objects(): request = app.current_request username = get_authorized_username(app.current_request) user = User.find(username) try: return {'image_url': user.get_profile_pic()} except ClientError as e: raise NotFoundError('image')
def upload(): files = _get_parts() username = get_authorized_username(app.current_request) user = User.find(username) user.update_profile_pic(files['file'].filename, files['file'].value) return { "uploaded": "true", "profile_pic_url": user.get_profile_pic(), }
def update_current_user(): body = app.current_request.json_body username = get_authorized_username(app.current_request) user = User.find(username) if user != None: user.update_attributes(body) return_data = user.attributes() else: return_data = {'error': 'Record not found.'} return return_data
def s3objects(file_name): request = app.current_request username = get_authorized_username(app.current_request) user = User.find(username) body = app.current_request.raw_body user.update_profile_pic(file_name, body) return { "uploaded": "true", "profile_pic_url": user.get_profile_pic(), }
def login(): body = app.current_request.json_body user = User.find(body['username']) if user == None: return {'error': 'User name or password is invalid.'} else: record = user.attributes() record['hash'] = user.hash record['salt'] = user.salt record['rounds'] = user.rounds record['hashed'] = user.hashed jwt_token = auth.get_jwt_token(body['username'], body['password'], record) return {'token': jwt_token}
def create_user(): # This is the JSON body the user sent in their POST request. user_as_json = app.current_request.json_body table_name = get_table_name() table = boto3.resource('dynamodb').Table(table_name) username = user_as_json['username'] user_detail = User.find(user_as_json['username']) if user_detail != None: return {'error': 'Username has been taken.'} else: user = User(user_as_json) user.save() record = user.attributes() record['hash'] = user.hash record['salt'] = user.salt record['rounds'] = user.rounds record['hashed'] = user.hashed jwt_token = auth.get_jwt_token(user_as_json['username'], user_as_json['password'], record) # We'll echo the json body back to the user in a 'user' key. return { 'success': 'User was successfully created.', 'token': jwt_token }
def get_user(): username = get_authorized_username(app.current_request) user = User.find(username) return user.attributes()
def user_update_password(): return User.validate_reset_password_token(app.current_request.json_body)
def forgot_password(): return User.generate_reset_password_token(app.current_request.json_body)