You are here

function drush_tokenauth_reset in Token authentication 6.2

Same name and namespace in other branches
  1. 6 tokenauth.drush.inc \drush_tokenauth_reset()
  2. 7 tokenauth.drush.inc \drush_tokenauth_reset()

Drush command callback for "tokenauth-reset".

File

./tokenauth.drush.inc, line 50
Tokenauth drush commands.

Code

function drush_tokenauth_reset($user = NULL) {
  if (is_null($user)) {
    drush_log(dt('No user specified.'), 'warning');
    return;
  }
  elseif (is_numeric($user)) {
    $account = user_load($user);
  }
  else {
    $account = user_load(array(
      'name' => $user,
    ));
  }
  if (!$account) {
    drush_log(dt('User !user does not exist.', array(
      '!user' => $user,
    )), 'warning');
    return;
  }
  $message = dt('Are you sure you want to reset the token of user !user <!uid>?', array(
    '!user' => $account->name,
    '!uid' => $account->uid,
  ));
  if (!drush_confirm($message)) {
    return;
  }
  $return = tokenauth_reset($account->uid);
  if ($return !== FALSE) {
    drush_log(dt('Token has been reset.'), 'success');
    return;
  }
  drush_log(dt('Token failed to reset.'), 'error');
}