/** * @Route ("/auth/twitch") * @Transactional * * @param array $params * @param ViewModel $model * @throws Exception */ public function authTwitch(array $params, ViewModel $model) { try { $authHandler = new TwitchAuthHandler(); return $authHandler->authenticate($params, $model); } catch (\Exception $e) { $model->title = 'Login error'; $model->error = $e; return 'login'; } }
/** * @Route ("/login") * @HttpMethod ({"POST"}) * * @param array $params * @param ViewModel $model * @return string */ public function loginPost(array $params, ViewModel $model) { $userService = UserService::instance(); $authProvider = isset($params['authProvider']) && !empty($params['authProvider']) ? $params['authProvider'] : ''; $rememberme = isset($params['rememberme']) && !empty($params['rememberme']) ? true : false; if (empty($authProvider)) { $model->title = 'Login error'; $model->rememberme = $rememberme; $model->error = new Exception('Please select a authentication provider'); return 'login'; } Session::start(Session::START_NOCOOKIE); if ($rememberme) { Session::set('rememberme', 1); } if (isset($params['follow']) && !empty($params['follow'])) { Session::set('follow', $params['follow']); } switch (strtoupper($authProvider)) { case 'TWITCH': $authHandler = new TwitchAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'GOOGLE': $authHandler = new GoogleAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'TWITTER': $authHandler = new TwitterAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'REDDIT': $authHandler = new RedditAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); default: $model->title = 'Login error'; $model->rememberme = $rememberme; $model->error = new Exception('Authentication type not supported'); return 'login'; } }
/** * @Route ("/profile/connect/{provider}") * @Secure ({"USER"}) * * @param array $params * @return string * @throws Exception * @throws \Destiny\Common\Utils\FilterParamsException */ public function profileConnect(array $params) { FilterParams::required($params, 'provider'); $authProvider = $params['provider']; // check if the auth provider you are trying to login with is not the same as the current $currentAuthProvider = Session::getCredentials()->getAuthProvider(); if (strcasecmp($currentAuthProvider, $authProvider) === 0) { throw new Exception('Provider already authenticated'); } // Set a session var that is picked up in the AuthenticationService // in the GET method, this variable is unset Session::set('accountMerge', '1'); switch (strtoupper($authProvider)) { case 'TWITCH': $authHandler = new TwitchAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'GOOGLE': $authHandler = new GoogleAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'TWITTER': $authHandler = new TwitterAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); case 'REDDIT': $authHandler = new RedditAuthHandler(); return 'redirect: ' . $authHandler->getAuthenticationUrl(); default: throw new Exception('Authentication type not supported'); } }
/** * @Route ("/auth/twitch") * * @param array $params * @param ViewModel $model * @return string * @throws Exception */ public function authTwitch(array $params, ViewModel $model) { try { $authHandler = new TwitchAuthHandler(); return $authHandler->authenticate($params); } catch (\Exception $e) { return $this->handleAuthError($e, $model); } }