public function loginAction() { if (!$this->request->isPost()) { return; } $user = new OAuthModels\Login(); if ($this->request->isAjax()) { try { $user->connectWithPassword($this->request->getPost('identify'), $this->request->getPost('password'), OAuthManager::getAccessToken()); OAuthManager::removeAccessToken(); return $this->showResponseAsJson(UserModels\Login::getCurrentUser()); } catch (\Exception $e) { OAuthManager::removeAccessToken(); return $this->showExceptionAsJson($e, $user->getMessages()); } } else { try { $accessToken = OAuthManager::getAccessToken(); $user->connectWithPassword($accessToken); OAuthManager::removeAccessToken(); return $this->redirectHandler($this->getDI()->getConfig()->oauth->loginSuccessRedirectUri); } catch (\Exception $e) { $this->showException($e, $user->getMessages()); return $this->redirectHandler($this->getDI()->getConfig()->oauth->loginFailedRedirectUri); } } }
public function loginAction() { $this->view->setTemplateAfter('login'); $this->view->pick('auth/register'); $session = $this->getDI()->get('session'); $accessToken = $session->get('access-token'); if (!$accessToken) { return $this->response->redirect($this->getDI()->getConfig()->oauth->authFailedRedirectUri); } $this->view->token = $accessToken; if (!$this->request->isPost()) { return; } $user = new Models\Login(); $identify = $this->request->getPost('identify'); if (false === strpos($identify, '@')) { $user->assign(array('username' => $identify, 'password' => $this->request->getPost('password'))); } else { $user->assign(array('email' => $identify, 'password' => $this->request->getPost('password'))); } $session = $this->getDI()->get('session'); try { $user->connectWithPassword($accessToken); $this->flashSession->success('SUCCESS_OAUTH_USER_CONNECTED'); $session->remove('access-token'); return $this->response->redirect($this->getDI()->getConfig()->oauth->loginSuccessRedirectUri); } catch (\Exception $e) { $this->showException($e, $user->getMessages()); return $this->response->redirect($this->getDI()->getConfig()->oauth->loginFailedRedirectUri); } }