Guest User

Untitled

a guest
Aug 15th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. auth = HTTPBasicAuth()
  2.  
  3. @app.route("/clothesInfo")
  4. @auth.login_required
  5. def show_info():
  6. return jsonify(blah blah blah)
  7.  
  8. auth = HTTPBasicAuth()
  9.  
  10. @auth.verify_password
  11. def verify_password(username, password):
  12. if username == '' or password == '':
  13. # anonymous user, we still let them in
  14. g.current_user = None
  15. return True
  16. g.current_user = my_verify_function(username, password)
  17. return g.current_user is not None
  18.  
  19. @app.route("/clothesInfo")
  20. @auth.login_required
  21. def show_info():
  22. if g.current_user:
  23. # prepare data for authenticated users here
  24. pass
  25. else:
  26. # prepare data for anonymous users here
  27. pass
  28. return jsonify(data)
  29.  
  30. # a dummy callable to execute the login_required logic
  31. login_required_dummy_view = auth.login_required(lambda: None)
  32.  
  33. def is_authenticated():
  34. try:
  35. # default implementation returns a string error
  36. return login_required_dummy_view() is None
  37. except HTTPException:
  38. # in case auth_error_callback raises a real error
  39. return False
  40.  
  41. @app.route('/info')
  42. def info():
  43. if is_authenticated():
  44. # logged in view
  45.  
  46. else:
  47. # basic view
Add Comment
Please, Sign In to add comment