Exemple #1
0
 /**
  * register
  *
  * @param DataInterface|UserDataTrait $user
  *
  * @return  bool
  *
  * @throws \Exception
  */
 public function register(DataInterface $user)
 {
     if ($user->password) {
         $user->password = UserHelper::hashPassword($user->password);
     }
     $this->prepareDefaultData($user);
     $user->id = User::save($user)->id;
     return true;
 }
 /**
  * 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);
 }
Exemple #3
0
 /**
  * save
  *
  * @param DataInterface|UserRecord $user
  *
  * @return bool
  * @throws ValidateFailException
  */
 public function save(DataInterface $user)
 {
     if ('' !== (string) $user->password) {
         $user->password = UserHelper::hashPassword($user->password);
     } else {
         unset($user->password);
     }
     unset($user->password2);
     $this->prepareDefaultData($user);
     $user->bind(User::save($user));
     return true;
 }
 /**
  * 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;
 }
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return bool
  *
  * @throws ValidateFailException
  */
 protected function doSave(DataInterface $data)
 {
     $user = User::get(['email' => $this->data['email']]);
     if (!UserHelper::verifyPassword($this->data['token'], $user->activation)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.activate.fail'));
     }
     $user->activation = '';
     $user->blocked = 0;
     User::save($user);
     return true;
 }