コード例 #1
0
ファイル: auth.py プロジェクト: pkkup/django-htk
def get_user_token_auth_hash(user, expires_timestamp):
    """Generates the hash portion of a user token-auth token
    """
    encrypted_uid = encrypt_uid(user)
    salt = user.profile.salt
    key = htk_setting('HTK_USER_TOKEN_AUTH_ENCRYPTION_KEY')

    prehash = '%s|%s|%s|%s' % (
        encrypted_uid,
        salt,
        expires_timestamp,
        key,
    )

    hashed = hashlib.sha256(prehash).hexdigest()

    return hashed
コード例 #2
0
ファイル: auth.py プロジェクト: aweandreverence/django-htk
def get_user_token_auth_hash(user, expires_timestamp):
    """Generates the hash portion of a user token-auth token
    """
    encrypted_uid = encrypt_uid(user)
    salt = user.profile.salt
    key = htk_setting('HTK_USER_TOKEN_AUTH_ENCRYPTION_KEY')

    prehash = '%s|%s|%s|%s' % (
        encrypted_uid,
        salt,
        expires_timestamp,
        key,
    )

    hashed = hashlib.sha256(prehash.encode()).hexdigest()

    return hashed
コード例 #3
0
ファイル: auth.py プロジェクト: pkkup/django-htk
def get_user_token_auth_token(user, expires_minutes=None):
    """Returns the token to auth/log in the `user`

    Typically would want to include the generated token in an email
    so that that user can directly log in to the app.
    """
    encrypted_uid = encrypt_uid(user)

    expires_minutes = expires_minutes if expires_minutes else htk_setting('HTK_USER_TOKEN_AUTH_EXPIRES_MINUTES')
    expires = utcnow() + datetime.timedelta(minutes=expires_minutes)
    expires_timestamp = datetime_to_unix_time(expires)

    hashed = get_user_token_auth_hash(user, expires_timestamp)

    data = {
        'user' : encrypted_uid,
        'expires' : expires_timestamp,
        'hash' : hashed,
    }

    token = base64.b64encode(json.dumps(data))
    return token
コード例 #4
0
ファイル: auth.py プロジェクト: aweandreverence/django-htk
def get_user_token_auth_token(user, expires_minutes=None):
    """Returns the token to auth/log in the `user`

    Typically would want to include the generated token in an email
    so that that user can directly log in to the app.
    """
    encrypted_uid = encrypt_uid(user)

    expires_minutes = expires_minutes if expires_minutes else htk_setting('HTK_USER_TOKEN_AUTH_EXPIRES_MINUTES')
    expires = utcnow() + datetime.timedelta(minutes=expires_minutes)
    expires_timestamp = datetime_to_unix_time(expires)

    hashed = get_user_token_auth_hash(user, expires_timestamp)

    data = {
        'user' : encrypted_uid,
        'expires' : expires_timestamp,
        'hash' : hashed,
    }

    token = base64.b64encode(json.dumps(data).encode('utf-8')).decode('utf-8')
    return token
コード例 #5
0
ファイル: models.py プロジェクト: PocketGM/django-htk
 def get_unfollow_uri(self):
     unfollow_user_url_name = htk_setting('HTK_API_USERS_UNFOLLOW_URL_NAME')
     unfollow_uri = reverse(unfollow_user_url_name, args=(encrypt_uid(self.user),))
     return unfollow_uri
コード例 #6
0
ファイル: models.py プロジェクト: yacine15/django-htk
 def get_unfollow_uri(self):
     unfollow_user_url_name = htk_setting('HTK_API_USERS_UNFOLLOW_URL_NAME')
     unfollow_uri = reverse(unfollow_user_url_name,
                            args=(encrypt_uid(self.user), ))
     return unfollow_uri