コード例 #1
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;
 }
コード例 #2
0
 /**
  * register
  *
  * @param Data $user
  *
  * @return  Data
  */
 public function register(Data $user)
 {
     $password = new Password();
     $user->password = $password->create($user->password);
     unset($user->password2);
     $user = User::save($user);
     return $user;
 }
コード例 #3
0
ファイル: UserSeeder.php プロジェクト: Trult/windspeaker-demo
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = \Faker\Factory::create();
     $password = new Password();
     $userMapper = new DataMapper('users');
     foreach (range(1, 10) as $i) {
         $data = array('username' => $faker->userName, 'email' => $faker->email, 'password' => $password->create('1234'));
         $userMapper->createOne($data);
     }
 }
コード例 #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;
 }
コード例 #5
0
 /**
  * confirm
  *
  * @return  boolean
  */
 protected function confirm()
 {
     $token = $this->input->get('token');
     $username = $this->input->getUsername('username');
     $user = User::get(array('username' => $username));
     if ($user->isNull()) {
         $this->setRedirect($this->router->http('forgot', array('task' => 'confirm', 'token' => $token)), Translator::translate('windwalker.user.no.user.found'));
         return false;
     }
     // Check token
     $password = new Password();
     if (!$password->verify($token, $user->reset_token)) {
         $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), Translator::translate('windwalker.user.invalid.token'));
         return false;
     }
     $this->setRedirect($this->router->http('reset', array('username' => $username, 'token' => $token)));
     return true;
 }
コード例 #6
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return  bool
  *
  * @throws ValidateFailException
  */
 protected function doSave(DataInterface $data)
 {
     $user = User::get(array('email' => $this->data['email']));
     if ($user->isNull()) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'user.not.found'));
     }
     // Check token
     $password = new Password();
     if (!$password->verify($this->data['token'], $user->reset_token)) {
         throw new ValidateFailException('Invalid Token');
     }
     return true;
 }
コード例 #7
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return  bool
  *
  * @throws ValidateFailException
  */
 protected function doSave(DataInterface $data)
 {
     if (!trim($this->data['password'])) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.entered'));
     }
     if ($this->data['password'] != $this->data['password2']) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match'));
     }
     /** @var UserRecord $user */
     $user = User::get(array('email' => $this->data['email']));
     if ($user->isNull()) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $passwordObject = new Password();
     if (!$passwordObject->verify($this->data['token'], $user->reset_token)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.invalid.token'));
     }
     $user->password = $passwordObject->create($this->data['password']);
     $user->reset_token = '';
     $user->last_reset = '';
     User::save($user);
 }
コード例 #8
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return  bool
  *
  * @throws ValidateFailException
  * @throws \Exception
  */
 protected function doSave(DataInterface $data)
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $view = $this->getView();
     $user = User::get(array('email' => $email));
     if ($user->isNull()) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found'));
     }
     $token = UserHelper::getToken($user->email);
     $link = $this->router->route('forget_confirm', array('token' => $token, 'email' => $email), CoreRouter::TYPE_FULL);
     $password = new Password();
     $user->reset_token = $password->create($token);
     $user->last_reset = DateTime::create()->toSql();
     User::save($user);
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $this->getMailBody($view);
     $this->sendEmail($user->email, $body);
     return true;
 }
コード例 #9
0
ファイル: PasswordTest.php プロジェクト: im286er/windwalker
 /**
  * Method to test create().
  *
  * @return void
  *
  * @covers Windwalker\Crypt\Password::create
  * @covers Windwalker\Crypt\Password::verify
  */
 public function testCreateBlowfish()
 {
     $this->instance->setType(Password::BLOWFISH);
     $pass = $this->instance->create('windwalker');
     $prefix = version_compare(PHP_VERSION, '5.3.7') >= 0 ? '$2y$' : '$2a$';
     $this->assertEquals(crypt('windwalker', $prefix . '10$sakurasakurasakurasaku$'), $pass);
     $this->assertTrue($this->instance->verify('windwalker', $pass));
     // Use default
     $password = new Password();
     $this->assertTrue($password->verify('windwalker', $password->create('windwalker')));
 }
コード例 #10
0
 /**
  * validate
  *
  * @param Data $data
  *
  * @throws  ValidFailException
  * @return  boolean
  */
 protected function validate($data)
 {
     $model = new ProfileModel();
     $form = $model->getForm($data);
     if (!$form->validate()) {
         $errors = $form->getErrors();
         foreach ($errors as $error) {
             $this->addFlash($error->getMessage(), 'danger');
         }
         $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $data->id ?: '']));
         return false;
     }
     if ($data->password) {
         if ($data->password2 != $data->password) {
             throw new ValidFailException('Password not match');
         }
         $password = new Password();
         $data->password = $password->create($data->password);
     } else {
         unset($data->password);
     }
     return true;
 }