Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auth = HTTPBasicAuth()
- @app.route("/clothesInfo")
- @auth.login_required
- def show_info():
- return jsonify(blah blah blah)
- auth = HTTPBasicAuth()
- @auth.verify_password
- def verify_password(username, password):
- if username == '' or password == '':
- # anonymous user, we still let them in
- g.current_user = None
- return True
- g.current_user = my_verify_function(username, password)
- return g.current_user is not None
- @app.route("/clothesInfo")
- @auth.login_required
- def show_info():
- if g.current_user:
- # prepare data for authenticated users here
- pass
- else:
- # prepare data for anonymous users here
- pass
- return jsonify(data)
- # a dummy callable to execute the login_required logic
- login_required_dummy_view = auth.login_required(lambda: None)
- def is_authenticated():
- try:
- # default implementation returns a string error
- return login_required_dummy_view() is None
- except HTTPException:
- # in case auth_error_callback raises a real error
- return False
- @app.route('/info')
- def info():
- if is_authenticated():
- # logged in view
- else:
- # basic view
Add Comment
Please, Sign In to add comment