dongocanh96

Untitled

Apr 14th, 2021
453
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def login():
  2.     auth = request.authorization
  3.  
  4.     if not auth or not auth.username or not auth.password:
  5.         return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
  6.  
  7.     user = Account.query.filter_by(name=auth.username).first()
  8.  
  9.     if not user:
  10.         return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
  11.  
  12.     if user.check_password(auth.password):
  13.         token = jwt.encode({"id" : user.id, "exp" : datetime.utcnow() + timedelta(minutes=30)}, app.config["SECRET_KEY"])
  14.  
  15.         return jsonify({"token" : token.decode("UTF-8")})
  16.  
  17.     return make_response("Could not verify", 401, {"WWW-Authenticate" : "Basic realm='Login required!'"})
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×