You are here

function tokenauth_reset_user in Token authentication 6.2

Same name and namespace in other branches
  1. 6 tokenauth.inc \tokenauth_reset_user()
  2. 7 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.

3 calls to tokenauth_reset_user()
tokenauth_reset in ./tokenauth.inc
API function to reset all tokens.
tokenauth_user in ./tokenauth.module
Implementation of hook_user().
tokenauth_user_reset in ./tokenauth.inc
API function to reset a user's token.

File

./tokenauth.inc, line 48
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_query("INSERT INTO {tokenauth_tokens} (uid,token) VALUES (%d,'%s')", $entry['uid'], $entry['token']);
  }
  else {
    $return = drupal_write_record('tokenauth_tokens', $entry, 'uid');
  }
  tokenauth_get_token($uid, TRUE);
  return $return === FALSE ? FALSE : $entry['token'];
}