/** * @param mixed $value * * @return bool */ public function validate($value) { if (!trim($value)) { $this->addError(L10n::msg('Value is empty.')); } return !$this->getErrorStack()->hasErrors(); }
/** * @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'))); }
/** * @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(); }
/** * @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; }