Skip to content

Instantly share code, notes, and snippets.

@cosmic-byte
Created March 30, 2018 12:59
Show Gist options
  • Save cosmic-byte/b1a91bcd34f0c3602b3789969aaa82db to your computer and use it in GitHub Desktop.
Save cosmic-byte/b1a91bcd34f0c3602b3789969aaa82db to your computer and use it in GitHub Desktop.
def generate_token(user):
try:
# generate the auth token
auth_token = user.encode_auth_token(user.id)
response_object = {
'status': 'success',
'message': 'Successfully registered.',
'Authorization': auth_token.decode()
}
return response_object, 201
except Exception as e:
response_object = {
'status': 'fail',
'message': 'Some error occurred. Please try again.'
}
return response_object, 401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment