You are here

function tokenauth_reset_user in Token authentication 7

Same name and namespace in other branches
  1. 6.2 tokenauth.inc \tokenauth_reset_user()
  2. 6 tokenauth.inc \tokenauth_reset_user()

API Function to reset a user's token.

Parameters

$uid: [optional] User ID of the user whose token to reset. Defaults to current user.

$token: [optional] A specific string to use as the token. Defaults to a string generated randomly with user_password().

$update: [optional] If true, will update the user's token entry. Otherwise will insert a new one.

Return value

The token string to which the user has been inserted/updated. FALSE if it fails.

2 calls to tokenauth_reset_user()
tokenauth_reset in ./tokenauth.inc
API function to reset all tokens.
tokenauth_user_update in ./tokenauth.module
Implements hook_user_update().

File

./tokenauth.inc, line 47
Provides tokenauth API for Token Authentication module.

Code

function tokenauth_reset_user($uid = NULL, $token = NULL, $update = TRUE) {
  if (is_null($uid)) {
    $uid = $GLOBALS['user']->uid;
  }
  $entry = array(
    'uid' => $uid,
    'token' => isset($token) ? $token : user_password(variable_get('tokenauth_length', TOKENAUTH_DEFAULT_TOKEN_LENGTH)),
  );
  if (!$update) {

    // drupal_write_record mysteriously failing from tokenauth_enable().
    $return = db_insert('tokenauth_tokens')
      ->fields($entry)
      ->execute();
  }
  else {
    $return = db_update('tokenauth_tokens')
      ->fields($entry)
      ->condition('uid', $entry['uid'])
      ->execute();
  }
  tokenauth_get_token($uid, TRUE);
  return $return === FALSE ? FALSE : $entry['token'];
}