public function handle() { if ($this->request->action_is('login')) { $login = new LoginValidator($this->request); if ($login->successful()) { $this->t->flash('You have been logged in.', 'success'); $login->user->login(); NeechyResponse::redirect($login->user->url()); } else { $this->t->data('validation-errors', $login->errors); $this->t->data('login-name', $this->request->post('login-name')); $content = $this->render_view('login'); } $this->t->data('alert', 'logging in'); } elseif ($this->request->action_is('signup')) { $validator = new SignUpValidator($this->request); if ($validator->is_valid()) { $user = User::register($this->request->post('signup-name'), $this->request->post('signup-email'), $this->request->post('signup-pass')); $page = $this->save_user_page($user); NeechyResponse::redirect($page->url()); } else { $this->t->data('validation-errors', $validator->errors); $this->t->data('signup-name', $this->request->post('signup-name')); $this->t->data('signup-email', $this->request->post('signup-email')); $content = $this->render_view('login'); } } elseif ($this->request->page_is('logout')) { $this->t->flash('You have been logged out.', 'success'); User::logout_current(); $content = $this->render_view('login'); } else { $content = $this->render_view('login'); } return $this->respond($content); }
<?php function __autoload($class_name) { require_once 'classes/' . $class_name . '.php'; } $login_form = new LoginForm('login', 'index.php', 'post'); $register_form = new RegisterForm('register', 'register.php', 'post'); $login_form->addFields(['username' => ['type' => 'text', 'value' => 'Yourname!', 'rules' => ['require' => true, 'alnum' => true]], 'password' => ['type' => 'password', 'value' => 'yourpassword', 'rules' => ['require' => true]]]); $register_form->addFields(['username' => ['type' => 'text!', 'value' => 'Vladimir', 'rules' => ['require' => true, 'alnum' => true]], 'email' => ['type' => 'email', 'value' => '', 'rules' => ['require' => true, 'email' => true]], 'password' => ['type' => 'password', 'value' => '', 'rules' => ['require' => true, 'match' => 'password_confirm']], 'password_confirm' => ['type' => 'password', 'value' => '123', 'rules' => ['require' => true]]]); $loginValidator = new LoginValidator(); $loginValidator->addForm($login_form); $loginValidator->validate(); var_dump($loginValidator->getErrors()); $registerValidator = new RegisterValidator(); $registerValidator->addForm($register_form); $registerValidator->validate(); var_dump($registerValidator->getErrors());