コード例 #1
0
 /**
  * request
  *
  * @return  bool
  *
  * @throws \Exception
  */
 protected function request()
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         $this->setRedirect($this->router->http('forgot'), Translator::translate('windwalker.user.no.email'));
         return false;
     }
     $view = $this->getView();
     $token = md5($this->app->get('secret') . uniqid() . CryptHelper::genRandomBytes());
     $link = $this->router->http('forgot', array('task' => 'confirm', 'token' => $token), Router::TYPE_FULL);
     $user = User::get(array('email' => $email));
     if ($user->notNull()) {
         $password = new Password();
         $user->reset_token = $password->create($token);
         $user->reset_last = DateTime::create('now', DateTime::TZ_LOCALE)->toSql(true);
         User::save($user);
     }
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $view->setLayout('email')->render();
     // Please send email here.
     // ----------------------------------------------------
     // ----------------------------------------------------
     $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), array('This is test message.', $body));
     return true;
 }
コード例 #2
0
ファイル: SocialMethod.php プロジェクト: asika32764/natika
 /**
  * postAuthenticate
  *
  * @param UserData                 $user
  * @param Data                     $socialMapping
  * @param Credential               $credential
  * @param \Hybrid_Provider_Adapter $adapter
  *
  * @return  void
  */
 protected function postAuthenticate(UserData $user, Data $socialMapping, Credential $credential, \Hybrid_Provider_Adapter $adapter)
 {
     unset($credential->username);
     $user->id = $socialMapping->user_id;
     $user->bind($credential);
     User::save($user);
 }
コード例 #3
0
 /**
  * doExecute
  *
  * @return mixed
  * @throws \Exception
  */
 protected function doExecute()
 {
     $username = $this->input->getUsername('username');
     $token = $this->input->getUsername('token');
     $password = $this->input->getString('password');
     $password2 = $this->input->getString('password2');
     try {
         if (!trim($password)) {
             throw new ValidFailException(Translator::translate('windwalker.user.password.not.entered'));
         }
         if ($password != $password2) {
             throw new ValidFailException(Translator::translate('windwalker.user.password.not.match'));
         }
         $user = User::get(array('username' => $username));
         if ($user->isNull()) {
             throw new ValidFailException(Translator::translate('windwalker.user.not.found'));
         }
         $passwordObject = new Password();
         if (!$passwordObject->verify($token, $user->reset_token)) {
             throw new ValidFailException(Translator::translate('windwalker.user.invalid.token'));
         }
         $user->password = $passwordObject->create($password);
         $user->reset_token = '';
         $user->last_reset = '';
         User::save($user);
     } catch (ValidFailException $e) {
         $this->setRedirect($this->router->http('reset', array('task' => 'reset', 'username' => $username, 'token' => $token)), $e->getMessage(), Bootstrap::MSG_DANGER);
         return false;
     }
     $this->setRedirect($this->router->http('reset', array('task' => 'complete')));
     return true;
 }
コード例 #4
0
 /**
  * register
  *
  * @param array $user
  *
  * @throws \Exception
  * @return  bool
  */
 public function register($user)
 {
     $user = new Data($user);
     if ($user->password != $user->password2) {
         throw new \Exception('Password not match.');
     }
     $password = new Password();
     $user->password = $password->create($user->password);
     unset($user->password2);
     User::save($user);
     return true;
 }