Ejemplo n.º 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.")
Ejemplo n.º 2
0
 def put(self) -> Response:
     """Endpoint (private) responsible for updating a user's password.
     
     Returns:
         Response -- The Flask response object.
     """
     args = UPDATE_PARSER.parse_args()
     if len(args['new_password']) < 6:
         return abort(
             400, "Your {new_password} must be of length >= 6 characters.")
     auth = Auth.authenticate(get_jwt_identity(), args['old_password'])
     if auth is None:
         return abort(401, "Invalid credentials supplied.")
     auth.update_password(args['new_password'])
     auth.save()
     return make_response(
         jsonify(
             {"msg": "The user password has been successfully updated."}),
         200)
Ejemplo n.º 3
0
def before():
    from models.auth import Auth
    request.full_view, request.current_user = Auth.authenticate(request.url)