Ejemplo n.º 1
0
 /**
  * @param mixed $value
  *
  * @return bool
  */
 public function validate($value)
 {
     if (!trim($value)) {
         $this->addError(L10n::msg('Value is empty.'));
     }
     return !$this->getErrorStack()->hasErrors();
 }
Ejemplo n.º 2
0
 /**
  * @param string $id
  * @throws \Loo\Exception\InvalidTypeException
  */
 public function __construct($id)
 {
     parent::__construct($id);
     $this->setMethod(Request::POST);
     $this->add($this->getElementFactory()->getInputText('name', 'Name')->addAttributes(['placeholder' => L10n::msg('Name'), 'required', 'autofocus']));
     $this->add($this->getElementFactory()->getInputPassword('password', 'Password')->addAttributes(['placeholder' => L10n::msg('Password'), 'required']));
     $this->add($this->getElementFactory()->getSubmit('submit', L10n::msg('Login')));
 }
Ejemplo n.º 3
0
 /**
  * @param string $value
  *
  * @return bool
  */
 public function validate($value)
 {
     if (strlen($value) < $this->min) {
         $this->addError(L10n::msg('Value is too short'));
     } elseif (strlen($value) > $this->max) {
         $this->addError(L10n::msg('Value is too long'));
     }
     return !$this->getErrorStack()->hasErrors();
 }
Ejemplo n.º 4
0
 /**
  * @param string $name
  * @param string $password
  * @return Result
  */
 public function login($name, $password)
 {
     $result = new Result();
     $name = Type::string($name);
     $password = Type::string($password);
     if ($this->isLoggedIn()) {
         $result->addValue($this->session->get('user_id'));
         return $result;
     }
     $user = $this->users->getUserByLoginData($name, $password);
     if ($user) {
         $this->session->set('user_id', $user->getId());
         $result->addValue($user->getId());
     } else {
         $result->addError(L10n::msgReplace('%s is a invalid user or wrong password.', $name));
     }
     return $result;
 }