Guest User

Untitled

a guest
Nov 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. def validate_api_or_user(f):
  2. @wraps(f)
  3. def decorated(*args, **kwargs):
  4. auth = request.authorization
  5. print auth
  6. if not auth: # no header set
  7. if current_user.is_authenticated: # check active session
  8. g.user = current_user
  9. return f(*args, **kwargs)
  10. else:
  11. abort(401)
  12. user = User.objects.get(username=auth.username)
  13. if user is None or not user.verify(auth.password):
  14. abort(401)
  15. g.user = user
  16. return f(*args, **kwargs)
  17. return decorated
Add Comment
Please, Sign In to add comment