示例#1
0
 /**
  * Test value and return boolean
  *
  * @param mixed $value
  *
  * @return bool
  * @throws ValidateFailException
  */
 protected function test($value)
 {
     $user = User::get(array($this->field => $value));
     if ($user->notNull()) {
         throw new ValidateFailException(Translator::sprintf('warder.user.save.message.exists', $this->field, $value));
     }
     return true;
 }
示例#2
0
 /**
  * getDefaultData
  *
  * @return array
  */
 public function getFormDefaultData()
 {
     $sessionData = (array) $this['form.data'];
     $pk = $this['item.pk'];
     $item = User::get($pk);
     if (ArrayHelper::getValue($sessionData, 'id') == $item->id) {
         unset($sessionData['password']);
         unset($sessionData['password2']);
         return $sessionData;
     }
     unset($item->password);
     return $item->dump();
 }
示例#3
0
 /**
  * getItem
  *
  * @param   mixed $pk
  *
  * @return  Data
  */
 public function getItem($pk = null)
 {
     $state = $this->state;
     $pk = $pk ?: $state['load.conditions'];
     return $this->fetch('item.' . json_encode($pk), function () use($pk, $state) {
         if (!$pk) {
             return new UserData();
         }
         $item = User::get($pk);
         $this->postGetItem($item);
         return $item;
     });
 }
示例#4
0
 /**
  * prepareExecute
  *
  * @return  void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     $this->view['email'] = $this->input->getEmail('email');
     $this->view['token'] = $this->input->get('token');
     // Check email and token
     $user = User::get(array('email' => $this->view['email']));
     if ($user->isNull()) {
         $this->backToConfirm(Translator::translate($this->langPrefix . 'user.not.found'));
         return;
     }
     if (!UserHelper::verifyPassword($this->view['token'], $user->reset_token)) {
         $this->backToConfirm('Invalid Token');
         return;
     }
 }
示例#5
0
 /**
  * authenticate
  *
  * @param Credential $credential
  *
  * @return  integer
  */
 public function authenticate(Credential $credential)
 {
     $loginName = $this->warder->getLoginName();
     if (!$credential->{$loginName} || !$credential->password) {
         $this->status = Authentication::EMPTY_CREDENTIAL;
         return false;
     }
     /** @var UserData $user */
     $user = User::get(array($loginName => $credential->{$loginName}));
     if ($user->isNull()) {
         $this->status = Authentication::USER_NOT_FOUND;
         return false;
     }
     if (!UserHelper::verifyPassword($credential->password, $user->password)) {
         $this->status = Authentication::INVALID_PASSWORD;
         return false;
     }
     $credential->bind($user);
     $this->status = Authentication::SUCCESS;
     return true;
 }
示例#6
0
 /**
  * validate
  *
  * @param  DataInterface $data
  *
  * @return  void
  *
  * @throws ValidateFailException
  */
 protected function validate(DataInterface $data)
 {
     $validator = new EmailValidator();
     if (!$validator->validate($data->email)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.email.invalid'));
     }
     parent::validate($data);
     $loginName = WarderHelper::getLoginName();
     if ($loginName != 'email') {
         $user = User::get(array($loginName => $data->{$loginName}));
         if ($user->notNull() && $user->id != $data->id) {
             throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.account.exists'));
         }
     }
     $user = User::get(array('email' => $data->email));
     if ($user->notNull() && $user->id != $data->id) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.email.exists'));
     }
     if ('' !== (string) $data->password) {
         if ($data->password != $data->password2) {
             throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match'));
         }
         unset($data->password2);
     } else {
         unset($data->password);
     }
 }
示例#7
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;
 }
示例#8
0
 /**
  * authenticate
  *
  * @param Credential $credential
  *
  * @return  integer
  * @throws \Exception
  */
 public function authenticate(Credential $credential)
 {
     if (!class_exists('Hybrid_Auth')) {
         throw new \LogicException('Please install hybridauth/hybridauth first.');
     }
     if (!$credential->_provider) {
         $this->status = Authentication::INVALID_CREDENTIAL;
         return false;
     }
     $provider = $credential->_provider;
     $providers = $this->warder->app->get('social_login', array());
     // Check provider supported
     if (!in_array($provider, array_keys($providers))) {
         if (WINDWALKER_DEBUG) {
             throw new \DomainException('Social Login Provider: ' . $provider . ' not supported.');
         }
         $this->status = Authentication::INVALID_CREDENTIAL;
         return false;
     }
     // Start auth
     $auth = $this->getHybridAuth($this->getHAConfig());
     $adapter = $this->doAuthenticate($provider, $auth);
     // Process different data
     $method = 'process' . ucfirst($provider);
     if (!is_callable(array($this, $method))) {
         throw new \LogicException(__CLASS__ . '::' . $method . '() not exists.');
     }
     // Process for different providers
     $this->{$method}($adapter, $credential);
     $userProfile = $adapter->getUserProfile();
     // Default data
     $credential->avatar = $userProfile->photoURL;
     $credential->params = json_encode(array('raw_profile' => $userProfile));
     $this->prepareUserData($adapter, $credential);
     // Check User Socials
     $userSocialMapper = new UserSocialMapper();
     $mapping = array('identifier' => $userProfile->identifier, 'provider' => $provider);
     $socialMapping = $userSocialMapper->findOne($mapping);
     // Check Socials
     if ($socialMapping->isNull() || User::get($socialMapping->user_id)->isNull()) {
         $createUser = true;
         // Check user exists
         if ($credential->_loginName) {
             $user = User::get(array($credential->_loginName => $credential->{$credential->_loginName}));
             $createUser = $user->isNull();
         }
         if ($createUser) {
             $user = $this->createUser($credential);
         }
         $socialMapping = new Data($mapping);
         $socialMapping->user_id = $user->id;
         $userSocialMapper->createOne($socialMapping);
     }
     $user = User::get($socialMapping->user_id);
     $this->postAuthenticate($user, $socialMapping, $credential, $adapter);
     $credential->bind($user);
     $this->status = Authentication::SUCCESS;
     return true;
 }
示例#9
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);
 }
示例#10
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;
 }
示例#11
0
 /**
  * onViewBeforeRender
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onViewBeforeRender(Event $event)
 {
     if (!$event['view'] instanceof HtmlView) {
         return;
     }
     $data = $event['data'];
     if (!$data->user) {
         $data->user = User::get();
     }
 }
示例#12
0
 /**
  * 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;
 }