Skip to content

Instantly share code, notes, and snippets.

@oleg-agapov
Last active May 8, 2018 14:03
Show Gist options
  • Save oleg-agapov/8e71f32b2935072c7dc501f03f530847 to your computer and use it in GitHub Desktop.
Save oleg-agapov/8e71f32b2935072c7dc501f03f530847 to your computer and use it in GitHub Desktop.
# 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