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); }
protected function create_admin_user() { $this->print_header('Create Admin User'); $name_is_valid = false; $email_is_valid = false; # Choose name (5 tries) $strikes = 5; while (!$name_is_valid) { $validator = new SignUpValidator(); $name = $this->prompt_user('Please enter your new user name'); if (!$validator->validate_signup_user($name, 'name')) { $m = sprintf('invalid user name: %s', implode(', ', $validator->errors['name'])); $this->println($m); $strikes--; } else { $name_is_valid = true; } if ($strikes < 1) { $m = 'User name cannot be validated. Install failed. Please start over.'; throw new NeechyInstallError($m); } } # Input email $strikes = 5; while (!$email_is_valid) { $validator = new SignUpValidator(); $email = $this->prompt_user('Please enter your email'); if (!$validator->validate_signup_email($email, 'email')) { $m = sprintf('invalid email address: %s', implode(', ', $validator->errors['email'])); $this->println($m); $strikes--; } else { $email_is_valid = true; } if ($strikes < 1) { $m = 'Email cannot be validated. Install failed. Please start over.'; throw new NeechyInstallError($m); } } # Register user and create page $password = NeechySecurity::random_hex(); $this->register_admin_user($name, $email, $password); # Feedback $format = <<<STDOUT An admin has been created with your user name: %s Your random password is: %s Please login now and change your password. STDOUT; $this->println(sprintf($format, $name, $password)); }