Esempio n. 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * doExecute
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     User::logout();
     $return = $this->input->getBase64($this->package->get('admin.login.return_key', 'return'));
     if ($return) {
         $this->setRedirect(base64_decode($return));
         return true;
     }
     $this->setRedirect($this->router->route(WarderHelper::getPackage()->get('admin.redirect.logout', 'home')));
     return true;
 }
Esempio n. 4
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();
 }
Esempio n. 5
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;
     }
 }
Esempio n. 6
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;
 }
Esempio n. 7
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);
     }
 }
Esempio n. 8
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;
 }
Esempio n. 9
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;
 }
Esempio n. 10
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);
 }
Esempio n. 11
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;
 }
Esempio n. 12
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;
 }
Esempio n. 13
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();
     }
 }
Esempio n. 14
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;
 }
Esempio n. 15
0
 /**
  * isLogin
  *
  * @return  boolean
  */
 public static function isLogin()
 {
     $user = User::getUser();
     return $user->isMember();
 }
Esempio n. 16
0
 /**
  * getUserData
  *
  * @param array $conditions
  *
  * @return  \Windwalker\Core\User\UserDataInterface
  */
 public function getUserData($conditions = [])
 {
     return User::getUser($conditions);
 }