def post(self, email=None, password=None): """ ' PURPOSE ' Given and email and password, create a new user. ' Returns the new user's identifier ' PARAMETERS ' <str email> ' <str password> ' RETURNS ' dict( id ) ' id -> the identifier of the created user """ user = UserModel(email=email) user.set_password(password) user.save() return { 'id': user.key.id }
def post(self, name=None, author=None): """ ' PURPOSE ' Given a trip name and author identifier, create ' a new trip. Returns the identifier of the new trip. ' PARAMETERS ' <str name> ' <str author> identifier ' RETURNS ' dict( id ) ' id -> the identifier of the created trip """ author_key = UserModel.key_from_id(author) trip = TripModel(name=name, author=author_key).save() return { 'id': trip.key.id }
def handle(*args, **kwargs): basic = request.authorization if not basic: return abort(401) email = basic.username password = basic.password users = UserModel.fetch(UserModel.email == email) if len(users) == 0: return abort(401) user = users[0] if not user.check_password(password): return abort(401) kwargs['current_user'] = user return f(*args, **kwargs)