public function resetToken($reference, array $options = [])
{
if (empty($reference)) {
throw new InvalidArgumentException(__d('CakeDC/Users', "Reference cannot be null"));
}
$expiration = Hash::get($options, 'expiration');
if (empty($expiration)) {
throw new InvalidArgumentException(__d('CakeDC/Users', "Token expiration cannot be empty"));
}
$user = $this->_getUser($reference);
if (empty($user)) {
throw new UserNotFoundException(__d('CakeDC/Users', "User not found"));
}
if (Hash::get($options, 'checkActive')) {
if ($user->active) {
throw new UserAlreadyActiveException(__d('CakeDC/Users', "User account already validated"));
}
$user->active = false;
$user->activation_date = null;
}
if (Hash::get($options, 'ensureActive')) {
if (!$user['active']) {
throw new UserNotActiveException(__d('CakeDC/Users', "User not active"));
}
}
$user->updateToken($expiration);
$saveResult = $this->_table->save($user);
$template = !empty($options['emailTemplate']) ? $options['emailTemplate'] : 'CakeDC/Users.reset_password';
if (Hash::get($options, 'sendEmail')) {
$this->Email->sendResetPasswordEmail($saveResult, null, $template);
}
return $saveResult;
}