public function loginAction() { $flash = ''; if (Identity::isAuthenticated()) { return $this->redirect('/followings'); } else { if (isset($_POST['username']) && isset($_POST['password'])) { try { Identity::authenticate($_POST['username'], $_POST['password']); } catch (\Exception $e) { $flash = $e->getMessage(); } if (Identity::isAuthenticated()) { return $this->redirect('/followings'); } else { $flash .= "Authentication failed. Please try again."; } } } return new ViewModel('user/login.phtml', array('flash' => $flash)); }