Last active
May 8, 2018 14:03
-
-
Save oleg-agapov/8e71f32b2935072c7dc501f03f530847 to your computer and use it in GitHub Desktop.
This file contains 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
# app/auth/resources.py | |
# import section | |
from flask_jwt_extended import get_raw_jwt | |
from app.auth.utils import add_token_to_db, revoke_token | |
class UserRegistration(Resource): | |
def post(self): | |
#... | |
try: | |
#... | |
access_token = create_access_token(identity=new_user.email) | |
add_token_to_db(access_token) | |
#... | |
except: | |
#... | |
class UserLogin(Resource): | |
def post(self): | |
#... | |
if current_user.password == data['password']: | |
access_token = create_access_token(identity=current_user.email) | |
add_token_to_db(access_token) | |
#... | |
else: | |
#... | |
class UserLogout(Resource): | |
@jwt_required | |
def get(self): | |
token = get_raw_jwt() | |
revoke_token(token) | |
return {'message': 'Successful logout'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment