Skip to content

Instantly share code, notes, and snippets.

@cosmic-byte
Created March 30, 2018 12:59
Show Gist options
  • Select an option

  • Save cosmic-byte/b1a91bcd34f0c3602b3789969aaa82db to your computer and use it in GitHub Desktop.

Select an option

Save cosmic-byte/b1a91bcd34f0c3602b3789969aaa82db to your computer and use it in GitHub Desktop.

Revisions

  1. cosmic-byte created this gist Mar 30, 2018.
    16 changes: 16 additions & 0 deletions generat_token.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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