Beispiel #1
0
 def post():
     """[Signup]
     
     Raises:
         SchemaValidationError: [Error in data]
         EmailAlreadyExistsError: [Email exists]
         InternalServerError: [Query error]
     
     Returns:
         [json] -- [Json object with message and status code]
     """
     try:
         body = request.get_json()
         user = User(**body)
         user.hash_password()
         user.save()
         userId = user.id
         return tokenCreation(user, body, "Successfully signed up", userId)
     except FieldDoesNotExist as e:
         print(e)
         raise SchemaValidationError
     except NotUniqueError as e:
         print(e)
         for field in User._fields:  # You could also loop in User._fields to make something generic
             if field in str(e):
                 if field == 'username':
                     raise UserNameDoesnotExistsError
                 if field == 'email':
                     raise EmailAlreadyExistsError
     except Exception as e:
         print(e)
         raise InternalServerError
Beispiel #2
0
def sign_up():
    body = request.get_json()
    user = User(**body)
    user.hash_password()
    user.save()
    id = user.id
    return {'id': str(id)}, 200