public function handleRequest(ChainContainer $chain) { $action = $chain->getRequest()['action']; if (!isset($this->actionsMap[$action])) { RespondError::make($chain->getFrom()); return; } $user = $chain->getFrom(); $request = $chain->getRequest(); try { $form = (new Form())->import($request)->addRule('login', Rules::email(), 'Некорректный формат email')->addRule('password', Rules::password(), 'Пароль должен быть от 8 до 20 символов'); } catch (WrongRuleNameException $e) { RespondError::make($user, ['property' => 'Некорректно указано свойство']); return; } if (!$form->validate()) { RespondError::make($user, $form->getErrors()); return; } $this->{$this->actionsMap[$action]}($chain); }
use SocioChat\Forms\Rules; use Zend\Config\Config; require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config.php'; $container = DI::get()->container(); DIBuilder::setupNormal($container); $config = $container->get('config'); /* @var $config Config */ $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : null; $code = isset($_REQUEST['code']) ? $_REQUEST['code'] : null; $validation = null; if (!$email || !$code) { exit; } $form = new Form(); $form->import($_REQUEST); $form->addRule(ActivationsDAO::EMAIL, Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')->addRule(ActivationsDAO::EMAIL, function ($val) { $user = UserDAO::create()->getByEmail($val); return (bool) $user->getId(); }, 'Такой email не найден в системе.', 'userSearch'); $validation = $form->validate(); if (!$validation) { $heading = 'Ошибка!'; $message = 'Email невалиден.'; require_once "pages/common_page.php"; exit; } $activation = ActivationsDAO::create(); $result = $activation->getActivation($email, $code); $activation = $result[0]; /* @var $activation ActivationsDAO */ if (!$activation->getId() || $activation->getIsUsed()) {