request->isPost()) { $data = $this->request->getPost(); if ($form->isValid($data)) { $email = $form->getValue('Email'); $passwd = $form->getValue('Password'); // Perform login if ($this->auth->login($email, $passwd)) { $this->response->redirect('/'); } else { $this->flash->message('error', "Invalid credentials"); } } else { $msg = ''; $this->flash->message('error', $msg); } } $this->view->form = $form; } public function oauthAction($provider_name) { $client = $this->getDI()->get('oauth', [ $provider_name ]); $code = $this->request->get('code'); $state = $this->request->get('state'); // Have code. Authenticate and fetch data. if (strlen($code) > 0) { try { // NOTE: Should pass $state here also. $data = $client->authenticate($code); $this->auth->loginOauth($data); $this->response->redirect('/'); } catch(\Exception $e) { $this->flash->message('error', 'Failed to authenticate.'); $this->response->redirect('/login'); } } // No code else { // redirect to provider and acquire code. $this->response->redirect($client->getAuthorizationUrl(), true); } } public function logoutAction() { $this->auth->clearIdentity(); $this->response->redirect('/'); } }