Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validate_api_or_user(f):
- @wraps(f)
- def decorated(*args, **kwargs):
- auth = request.authorization
- print auth
- if not auth: # no header set
- if current_user.is_authenticated: # check active session
- g.user = current_user
- return f(*args, **kwargs)
- else:
- abort(401)
- user = User.objects.get(username=auth.username)
- if user is None or not user.verify(auth.password):
- abort(401)
- g.user = user
- return f(*args, **kwargs)
- return decorated
Add Comment
Please, Sign In to add comment