Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def login():
- auth = request.authorization
- if not auth or not auth.username or not auth.password:
- return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
- user = Account.query.filter_by(name=auth.username).first()
- if not user:
- return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
- if user.check_password(auth.password):
- token = jwt.encode({"id" : user.id, "exp" : datetime.utcnow() + timedelta(minutes=30)}, app.config["SECRET_KEY"])
- return jsonify({"token" : token.decode("UTF-8")})
- return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
Add Comment
Please, Sign In to add comment