def unfollow(request, encrypted_uid): """Unfollow another user """ user = request.user other_user = resolve_encrypted_uid(encrypted_uid) if other_user: user.profile.unfollow_user(other_user) response = json_response_okay() else: response = json_response_error() return response
def unfollow(request, encrypted_uid): """Unfollow another user """ user = request.user other_user = resolve_encrypted_uid(encrypted_uid) if other_user: user.profile.unfollow_user(other_user) response = json_response_okay() else: response = json_response_error() return response
def validate_user_token_auth_token(token): """Validates a user token-auth token Returns a 2-tuple of `(user, is_valid,)` Defaults to `(None, False,)` """ user = None is_valid = False try: data = json.loads(base64.b64decode(token)) except ValueError: data = None if data is not None: # verify expiration of token expires_timestamp = data.get('expires', 0) expires = unix_time_to_datetime(expires_timestamp) if expires > utcnow(): # token has not expired encrypted_uid = data.get('user', -1) user = resolve_encrypted_uid(encrypted_uid) if user: # found a matching user # verify hash received_hash = data.get('hash', None) expected_hash = get_user_token_auth_hash( user, expires_timestamp) if received_hash == expected_hash: # hash matches is_valid = True else: # hash does not match user = None else: # no user found pass else: # token has expired pass return ( user, is_valid, )
def validate_user_token_auth_token(token): """Validates a user token-auth token Returns a 2-tuple of `(user, is_valid,)` Defaults to `(None, False,)` """ user = None is_valid = False try: data = json.loads(base64.b64decode(token)) except ValueError: data = None if data is not None: # verify expiration of token expires_timestamp = data.get('expires', 0) expires = unix_time_to_datetime(expires_timestamp) if expires > utcnow(): # token has not expired encrypted_uid = data.get('user', -1) user = resolve_encrypted_uid(encrypted_uid) if user: # found a matching user # verify hash received_hash = data.get('hash', None) expected_hash = get_user_token_auth_hash(user, expires_timestamp) if received_hash == expected_hash: # hash matches is_valid = True else: # hash does not match user = None else: # no user found pass else: # token has expired pass return (user, is_valid,)