Example #1
0
 def post(self) -> Response:
     """Endpoint (public) is responsible for authenticating an end user.
     
     Returns:
         Response -- The Flask response object.
     """
     args = LOGIN_PARSER.parse_args()
     if Auth.authenticate(args['email'], args['password']) is not None:
         REST_LOGGER.info("auth/login -> Authenticated login for user %s",
                          args['email'])
         tokens = Auth.generate_tokens(args['email'])
         return make_response(jsonify(tokens), 200)
     REST_LOGGER.info("auth/login -> Denied login for user %s",
                      args['email'])
     return abort(401, "Invalid {email} or {password} given.")
Example #2
0
 def post(self) -> Response:
     """Endpoint (public) for registering a user account on the platform.
     
     Returns:
         Response -- The Flask response object.
     """
     args = REGISTER_PARSER.parse_args()
     if args['email'] == "":
         return abort(400, "The {email} field cannot be empty.")
     if args['fullname'] == "":
         return abort(400, "The {fullname} field cannot be empty.")
     if "@" not in args['email']:
         return abort(400, "The {email} specified is invalid.")
     if len(args['password']) < 6:
         return abort(400, "The {password} given must be >= 6 characters.")
     check_auth = Auth.get_by_email(args['email'])
     if check_auth is not None:
         REST_LOGGER.info(
             "auth/register -> Duplicate registration attempt for email %s",
             args['email'])
         return abort(409, "A user already exists with that {email}.")
     user_auth = Auth.create(args['email'], args['password'])
     if user_auth is None:
         REST_LOGGER.info(
             "auth/register -> Fail on Auth.create() with email %s",
             args['email'])
         return abort(
             401, "Failed to create an account with the given {email}.")
     user = User.create(args['email'], args['fullname'])
     if user is None:
         REST_LOGGER.error(
             "auth/register -> Fail on User.create() with email %s",
             args['email'])
         return abort(
             401, "Failed to create an account with the given {email}.")
     REST_LOGGER.info("auth/register -> User registered with email %s",
                      args['email'])
     return make_response(jsonify(Auth.generate_tokens(args['email'])))