コード例 #1
0
ファイル: LoginDefinition.php プロジェクト: lyrasoft/warder
 /**
  * Define the form fields.
  *
  * @param Form $form The Windwalker form object.
  *
  * @return  void
  */
 public function define(Form $form)
 {
     $loginName = WarderHelper::getLoginName();
     $langPrefix = WarderHelper::getPackage()->get('frontend.language.prefix', 'warder.');
     $form->add($loginName, new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.' . $loginName));
     $form->add('password', new Field\PasswordField())->label(Translator::translate($langPrefix . 'user.field.password'));
     $form->add('remember', new Field\CheckboxField())->label(Translator::translate($langPrefix . 'user.field.remember'));
 }
コード例 #2
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return void
  */
 protected function doSave(DataInterface $data)
 {
     $options = array();
     $provider = $this->input->get('provider');
     $loginName = WarderHelper::getLoginName();
     if ($provider) {
         $options['provider'] = strtolower($provider);
         $data->{$loginName} = null;
         $data->password = null;
     }
     $this->model->login($data->{$loginName}, $data->password, $data->remember, $options);
 }
コード例 #3
0
 /**
  * Define the form fields.
  *
  * @param Form $form The Windwalker form object.
  *
  * @return  void
  */
 public function define(Form $form)
 {
     $loginName = WarderHelper::getLoginName();
     $langPrefix = WarderHelper::getPackage()->get('frontend.language.prefix', 'warder.');
     $form->wrap('basic', null, function (Form $form) use($loginName, $langPrefix) {
         $form->add('name', new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.name'))->required();
         if (strtolower($loginName) != 'email') {
             $form->add($loginName, new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.' . $loginName))->setValidator(new UserExistsValidator($loginName))->required();
         }
         $form->add('email', new Field\EmailField())->label(Translator::translate($langPrefix . 'user.field.email'))->setValidator(new UserExistsValidator('email'))->required();
         $form->add('password', new Field\PasswordField())->label(Translator::translate($langPrefix . 'user.field.password'))->set('autocomplete', 'off');
         $form->add('password2', new Field\PasswordField())->label(Translator::translate($langPrefix . 'user.field.password.confirm'))->set('autocomplete', 'off');
     });
 }
コード例 #4
0
ファイル: UserRecord.php プロジェクト: lyrasoft/warder
 /**
  * check
  *
  * @return  static
  */
 public function check()
 {
     $loginName = WarderHelper::getLoginName();
     if (!$this->{$loginName}) {
         throw new \InvalidArgumentException(Translator::translate('warder.user.account.empty'));
     }
     $exists = UserMapper::findOne(array($loginName => $this->{$loginName}));
     if ($exists->notNull() && $this->id != $exists->id) {
         throw new \InvalidArgumentException(Translator::sprintf('warder.user.save.message.exists', $loginName, $this->{$loginName}));
     }
     if ($this->email) {
         $exists = UserMapper::findOne(array('email' => $this->email));
         if ($exists->notNull() && $this->id != $exists->id) {
             throw new \InvalidArgumentException(Translator::sprintf('warder.user.save.message.exists', $loginName, $this->email));
         }
     }
     return $this;
 }
コード例 #5
0
ファイル: GridDefinition.php プロジェクト: lyrasoft/warder
 /**
  * Define the form fields.
  *
  * @param Form $form The Windwalker form object.
  *
  * @return  void
  */
 protected function doDefine(Form $form)
 {
     $warder = WarderHelper::getPackage();
     $loginName = WarderHelper::getLoginName();
     $langPrefix = $warder->get('admin.language.prefix');
     /*
      * Search Control
      * -------------------------------------------------
      * Add search fields as options, by default, model will search all columns.
      * If you hop that user can choose a field to search, change "display" to true.
      */
     $this->wrap(null, 'search', function (Form $form) use($loginName, $langPrefix) {
         // Search Field
         $fieldField = $this->list('field')->label(Translator::translate('phoenix.grid.search.user.field.label'))->set('display', false)->defaultValue('*')->option(Translator::translate('phoenix.core.all'), '*');
         if ($loginName != 'email') {
             $fieldField->option(Translator::translate($langPrefix . 'user.field.' . $loginName), 'user.' . $loginName);
         }
         $fieldField->option(Translator::translate($langPrefix . 'user.field.name'), 'user.name')->option(Translator::translate($langPrefix . 'user.field.email'), 'user.email')->option(Translator::translate($langPrefix . 'user.field.id'), 'user.id');
         // Search Content
         $this->text('content')->label(Translator::translate('phoenix.grid.search.label'))->set('placeholder', Translator::translate('phoenix.grid.search.label'));
     });
     /*
      * Filter Control
      * -------------------------------------------------
      * Add filter fields to this section.
      * Remember to add onchange event => this.form.submit(); or Phoenix.post();
      *
      * You can override filter actions in UsersModel::configureFilters()
      */
     $this->wrap(null, 'filter', function (Form $form) use($loginName, $langPrefix) {
         // Activated
         $this->list('activation')->label($langPrefix . 'filter.activation.label')->option('', '')->option(Translator::translate($langPrefix . 'filter.activation.select'), '')->option(Translator::translate($langPrefix . 'filter.activation.activated'), '1')->option(Translator::translate($langPrefix . 'filter.activation.unactivated'), '0')->set('onchange', 'this.form.submit()');
         // State
         $this->list('user.blocked')->label($langPrefix . 'filter.block.label')->option('', '')->option(Translator::translate($langPrefix . 'filter.block.select'), '')->option(Translator::translate($langPrefix . 'filter.block.blocked'), '1')->option(Translator::translate($langPrefix . 'filter.block.unblocked'), '0')->set('onchange', 'this.form.submit()');
     });
     /*
      * This is batch form definition.
      * -----------------------------------------------
      * Every field is a table column.
      * For example, you can add a 'category_id' field to update item category.
      */
     $this->wrap(null, 'batch', function (Form $form) {
     });
 }
コード例 #6
0
ファイル: EditDefinition.php プロジェクト: lyrasoft/warder
 /**
  * Define the form fields.
  *
  * @param Form $form The Windwalker form object.
  *
  * @return  void
  */
 public function define(Form $form)
 {
     $warder = WarderHelper::getPackage();
     $loginName = WarderHelper::getLoginName();
     $langPrefix = $warder->get('admin.language.prefix', 'warder.');
     // Basic fieldset
     $form->wrap('basic', null, function (Form $form) use($loginName, $langPrefix) {
         // Name
         $form->add('name', new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.name'))->required(true);
         if ($loginName != 'email') {
             // Name
             $form->add($loginName, new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.' . $loginName))->required(true);
         }
         // Email
         $form->add('email', new Field\EmailField())->label(Translator::translate($langPrefix . 'user.field.email'))->required();
         // Password
         $form->add('password', new Field\PasswordField())->label(Translator::translate($langPrefix . 'user.field.password'));
         // Password
         $form->add('password2', new Field\PasswordField())->label(Translator::translate($langPrefix . 'user.field.password.confirm'));
     });
     // Created fieldset
     $form->wrap('created', null, function (Form $form) use($langPrefix) {
         if (class_exists(SingleImageDragField::class)) {
             // Avatar
             $form->add('avatar', new SingleImageDragField())->label(Translator::translate($langPrefix . 'user.field.avatar'))->set('default_image', AvatarUploadHelper::getDefaultImage());
         }
         // Blocked
         $form->add('blocked', new Field\RadioField())->label(Translator::translate($langPrefix . 'user.field.name'))->set('class', 'btn-group')->set('default', 0)->option(Translator::translate($langPrefix . 'user.field.blocked.block'), 1)->option(Translator::translate($langPrefix . 'user.field.blocked.unblock'), 0);
         // ID
         $form->add('id', new Field\TextField())->label(Translator::translate($langPrefix . 'user.field.id'))->readonly();
         // Registered
         $form->add('registered', new CalendarField())->label(Translator::translate($langPrefix . 'user.field.registered'))->disabled();
         // Last Login
         $form->add('last_login', new CalendarField())->label(Translator::translate($langPrefix . 'user.field.last.login'))->disabled();
         // Last Reset
         //			$form->add('last_reset', new CalendarField)
         //				->label(Translator::translate($langPrefix . 'user.field.last.reset'))
         //				->set('readonly', true);
     });
 }
コード例 #7
0
ファイル: UserModel.php プロジェクト: lyrasoft/warder
 /**
  * login
  *
  * @param string $account
  * @param string $password
  * @param bool   $remember
  * @param array  $options
  *
  * @return bool
  * @throws ValidateFailException
  */
 public function login($account, $password, $remember = false, $options = array())
 {
     $loginName = WarderHelper::getLoginName();
     $credential = new Credential();
     $credential->{$loginName} = $account;
     $credential->password = $password;
     if (isset($options['provider'])) {
         $credential->_provider = $options['provider'];
     }
     try {
         $result = User::login($credential, (bool) $remember, $options);
     } catch (AuthenticateFailException $e) {
         $langPrefix = WarderHelper::getPackage()->get('admin.language.prefix', 'warder.');
         switch (array_values($e->getMessages())[0]) {
             case Authentication::USER_NOT_FOUND:
                 $message = Translator::translate($langPrefix . 'login.message.user.not.found');
                 break;
             case Authentication::EMPTY_CREDENTIAL:
                 $message = Translator::translate($langPrefix . 'login.message.empty.credential');
                 break;
             case Authentication::INVALID_CREDENTIAL:
                 $message = Translator::translate($langPrefix . 'login.message.invalid.credential');
                 break;
             case Authentication::INVALID_PASSWORD:
                 $message = Translator::translate($langPrefix . 'login.message.invalid.password');
                 break;
             case Authentication::INVALID_USERNAME:
                 $message = Translator::translate($langPrefix . 'login.message.invalid.username');
                 break;
             default:
                 $message = $e->getMessage();
         }
         throw new ValidateFailException($message);
     }
     return $result;
 }
コード例 #8
0
ファイル: SaveController.php プロジェクト: lyrasoft/warder
 /**
  * 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);
     }
 }
コード例 #9
0
 /**
  * doSave
  *
  * @param DataInterface $data
  *
  * @return void
  */
 protected function doSave(DataInterface $data)
 {
     $loginName = WarderHelper::getLoginName();
     $this->model->login($data->{$loginName}, $data->password, $data->remember, []);
 }