Esempio n. 1
0
 /**
  * Generate a new unique token for an existing user.
  *
  * @param User $user The user to generate a token for.
  * @param string $tokenType The type of token to be generated. Always make sure to supply this param as a constant
  *                                                             e.g. Token::TYPE_EMAIL_VERIFICATION
  * @return string A 32 character long randomized token
  */
 public function generateToken(User $user, $tokenType)
 {
     if (!isset($this->timeToLive[$tokenType])) {
         user_error('Please specify a timeToLive for the tokenType "' . $tokenType . '" at Token::$timeToLive.', E_USER_ERROR);
     }
     do {
         $token = md5(microtime(true) . Configure::read('Security.salt') . $user->get('id') . $user->get('email'));
     } while ((bool) $this->tokenExists($token));
     $this->save(new Entity(['user_id' => $user->get('id'), 'token' => $token, 'token_type' => $tokenType, 'expires' => new DateTime($this->timeToLive[$tokenType])]));
     return $token;
 }
Esempio n. 2
0
 /**
  * Deactivate the given $user.
  *
  * @param User $user The user to deactivate.
  * @return bool|\Cake\Datasource\EntityInterface
  */
 public function deactivate(User $user)
 {
     return $this->save($user->deactivate());
 }