Created
March 30, 2018 14:16
-
-
Save cosmic-byte/82daeb7ee7b002455a8ef45b1eaa311a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| from flask import request | |
| from app.main.service.auth_helper import Auth | |
| def token_required(f): | |
| @wraps(f) | |
| def decorated(*args, **kwargs): | |
| data, status = Auth.get_logged_in_user(request) | |
| token = data.get('data') | |
| if not token: | |
| return data, status | |
| return f(*args, **kwargs) | |
| return decorated | |
| def admin_token_required(f): | |
| @wraps(f) | |
| def decorated(*args, **kwargs): | |
| data, status = Auth.get_logged_in_user(request) | |
| token = data.get('data') | |
| if not token: | |
| return data, status | |
| admin = token.get('admin') | |
| if not admin: | |
| response_object = { | |
| 'status': 'fail', | |
| 'message': 'admin token required' | |
| } | |
| return response_object, 401 | |
| return f(*args, **kwargs) | |
| return decorated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment