/** * @return Response */ public function register() { // Check for return tag if ($return = $this->request->input('return')) { $this->request->getSession()->set('post-login-redirect', $return); } // Check for cancel tag if ($return = $this->request->input('cancel')) { $this->request->getSession()->set('cancel-login-redirect', $return); } // Check if already registered if ($user = $this->request->getUser()) { return $this->module->postLogin($this->request, $user); } $authenticators = $this->module->getAuthenticators(); $authenticator = $authenticators[0]->getToken(); return Response::redirect(URLBuilder::getURL($this->module->getRoutePath() . '/register/' . $authenticator)); }
public function register() { // Must be logged in if (!($user = $this->request->getUser())) { //echo '<p>' . ('This page is only available for registered users.') . '</p>'; $login = URLBuilder::getURL('account/login', array('return' => $this->module->getURL('register', $_GET))); return Response::redirect($login); } if ($this->request->isPost()) { $template = new Template('CatLab/OAuth2/registerdone.phpt'); $clientid = uniqid('oauth2', true); $password = md5(uniqid('secret')); $redirect_url = $this->request->input('redirecturi'); $layout = $this->request->input('layout'); MapperFactory::getApplicationMapper()->create($clientid, $password, $redirect_url, $layout, $this->request->getUser()->getId()); $template->set('clientid', $clientid); $template->set('clientsecret', $password); $template->set('redirecturi', $redirect_url); return Response::template($template); } $template = new Template('CatLab/OAuth2/register.phpt'); $template->set('action', $this->module->getURL('register')); return Response::template($template); }
public function authorize($parameter = null) { // Check for reset if ($parameter == 'reset' || $this->request->input('reset')) { $this->request->getSession()->set('catlab-user-id', null); unset($_GET['reset']); return \Neuron\Net\Response::redirect(URLBuilder::getURL('oauth2/authorize', $_GET)); } $display = 'mobile'; $server = OAuth2Service::getInstance()->getServer(); $request = OAuth2Service::getInstance()->translateRequest($this->request); $response = new Response(); // Check for cancel parameter if ($this->request->input('cancel')) { $server->handleAuthorizeRequest($request, $response, false, null); $response->send(); return; } // validate the authorize request if (!$server->validateAuthorizeRequest($request, $response)) { $response->send(); die; } $clientid = $server->getAuthorizeController()->getClientId(); $clientdata = $server->getStorage('client')->getClientDetails($clientid); // Check if we should log the user out (after a revoke) $this->checkForLogout($server); $layout = $clientdata['login_layout']; $skipAuthorization = $clientdata['skip_authorization']; if ($layout) { $display = $layout; } if (!($user = $this->request->getUser())) { //echo '<p>' . ('This page is only available for registered users.') . '</p>'; $login = URLBuilder::getURL('account/login', array('return' => URLBuilder::getURL('oauth2/authorize', $_GET), 'cancel' => URLBuilder::getURL('oauth2/authorize', array_merge($_GET, array('cancel' => 1))))); return \Neuron\Net\Response::redirect($login); } $user_id = $user->getId(); if (!$skipAuthorization) { $fields = array(); $fields['client_id'] = $clientid; $fields['u_id'] = $user_id; // Check in the database if already approved $data = Query::select('oauth2_app_authorizations', array('*'), $fields)->execute(); if (count($data) > 0) { $skipAuthorization = true; } } // Should we skip authorization? if ($skipAuthorization) { $response = $server->handleAuthorizeRequest($request, $response, true, $user_id); $this->storeAccessTokenInSession($response); $response->send(); //return \Neuron\FrontController::getInstance()->getResponse (); return; } // display an authorization form if (empty($_POST)) { return $this->showAuthorizationDialog($clientdata); } // print the authorization code if the user has authorized your client $is_authorized = $_POST['authorized'] === 'yes'; $response = $server->handleAuthorizeRequest($request, $response, $is_authorized, $user_id); if ($is_authorized) { $response = $server->handleAuthorizeRequest($request, $response, true, $user_id); $this->storeAccessTokenInSession($response); // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client //$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); //exit("SUCCESS! Authorization Code: $code"); // Also store this in our database $fields = array(); $fields['client_id'] = $clientid; $fields['u_id'] = $user_id; $fields['authorization_date'] = array(time(), Query::PARAM_DATE); // Destroy the session //Session::getInstance ()->destroy (); Query::replace('oauth2_app_authorizations', $fields)->execute(); } $response->send(); return; }
public function cancel() { $cancel = $this->request->getSession()->get('cancel-login-redirect'); if ($cancel) { $this->request->getSession()->set('post-login-redirect', null); $this->request->getSession()->set('cancel-login-redirect', null); return Response::redirect($cancel); } else { return Response::redirect(URLBuilder::getURL('/')); } }
public function login() { $this->initialize(); $helper = new FacebookRedirectLoginHelper(URLBuilder::getAbsoluteURL($this->module->getRoutePath() . '/login/' . $this->getToken(), array('next' => 1))); if (!$this->request->input('next')) { $loginUrl = $helper->getLoginUrl($this->scopes); return Response::redirect($loginUrl); } else { try { $session = $helper->getSessionFromRedirect(); } catch (FacebookRequestException $ex) { // When Facebook returns an error return Response::error($ex->getMessage()); } catch (\Exception $ex) { // When validation fails or other local issues return Response::error($ex->getMessage()); } if ($session) { // Check if this user is already registered. $request = new FacebookRequest($session, 'GET', '/me', array('fields' => 'id,name,gender,verified,locale,timezone,email,birthday,first_name,last_name')); $response = $request->execute(); $graphObject = $response->getGraphObject(); $data = $graphObject->asArray(); // Create an object. $user = new DeligatedUser(); $user->setType('facebook'); $user->setUniqueId($data['id']); $user->setAccessToken((string) $session->getAccessToken()); if (isset($data['name'])) { $user->setName($data['name']); } if (isset($data['gender'])) { switch (strtoupper($data['gender'])) { case DeligatedUser::GENDER_FEMALE: case DeligatedUser::GENDER_MALE: $user->setGender(strtoupper($data['gender'])); break; } } if (isset($data['locale'])) { $user->setLocale($data['locale']); } if (isset($data['email'])) { $user->setEmail($data['email']); } if (isset($data['birthday'])) { if (strlen($data['birthday']) == 10) { $parts = explode('/', $data['birthday']); $user->setBirthday(Carbon::createFromDate($parts[2], $parts[0], $parts[1])); } } if (isset($data['first_name'])) { $user->setFirstname($data['first_name']); } if (isset($data['last_name'])) { $user->setLastname($data['last_name']); } $user->setAvatar('https://graph.facebook.com/' . $user->getUniqueId() . '/picture?type=large'); // Touchy touchy! return $this->setDeligatedUser($user); } } }
private function runTry() { $openid = $this->getOpenIDUrl(); $consumer = $this->getConsumer(); $auth_request = $consumer->begin($openid); // No auth request means we can't begin OpenID. if (!$auth_request) { displayError("Authentication error; not a valid OpenID."); } $sreg_request = \Auth_OpenID_SRegRequest::build(array('nickname'), array('fullname', 'email')); if ($sreg_request) { $auth_request->addExtension($sreg_request); } $policy_uris = null; if (isset($_GET['policies'])) { $policy_uris = $_GET['policies']; } $pape_request = new \Auth_OpenID_PAPE_Request($policy_uris); if ($pape_request) { $auth_request->addExtension($pape_request); } // Redirect the user to the OpenID server for authentication. // Store the token for this authentication so we can verify the // response. // For OpenID 1, send a redirect. For OpenID 2, use a Javascript // form to send a POST request to the server. if ($auth_request->shouldSendRedirect()) { $redirect_url = $auth_request->redirectURL($this->getTrustRoot(), $this->getReturnTo()); // If the redirect URL can't be built, display an error // message. if (\Auth_OpenID::isFailure($redirect_url)) { displayError("Could not redirect to server: " . $redirect_url->message); } else { // Send redirect. //header("Location: ".$redirect_url); return Response::redirect($redirect_url); } } else { // Generate form markup and render it. $form_id = 'openid_message'; $form_html = $auth_request->htmlMarkup($this->getTrustRoot(), $this->getReturnTo(), false, array('id' => $form_id)); // Display an error if the form markup couldn't be generated; // otherwise, render the HTML. if (\Auth_OpenID::isFailure($form_html)) { displayError("Could not redirect to server: " . $form_html->message); } else { print $form_html; } } return null; }
/** * Called after a redirect * @param Request $request * @return Response */ public function postLogout(Request $request) { return Response::redirect(URLBuilder::getURL('/')); }
/** * Called after a redirect * @param Request $request * @return Response */ public function postLogout(Request $request) { if ($redirect = $request->getSession()->get('post-login-redirect')) { $request->getSession()->set('post-login-redirect', null); $request->getSession()->set('cancel-login-redirect', null); return Response::redirect($redirect); } return Response::redirect(URLBuilder::getURL('/')); }
public function register() { $this->initialize(); $deligatedUser = $this->getDeligatedUser(); if (!$deligatedUser) { return Response::redirect(URLBuilder::getURL($this->module->getRoutePath() . '/login/' . $this->getToken())); } if ($deligatedUser->getUser()) { return $this->module->login($this->request, $deligatedUser->getUser()); } // Check for linking request if ($this->request->input('link')) { return $this->linkExitingAccount($deligatedUser); } $page = new Template('CatLab/Accounts/authenticators/deligated/register.phpt'); $page->set('deligated', true); $page->set('connect', URLBuilder::getURL($this->module->getRoutePath() . '/register/' . $this->getToken(), array('link' => 1))); $page->set('layout', $this->module->getLayout()); $page->set('action', URLBuilder::getURL($this->module->getRoutePath() . '/register/' . $this->getToken())); // Check for input. if ($this->request->isPost()) { $email = $this->request->input('email', 'email'); $username = $this->request->input('username', 'username'); $response = $this->processRegister($deligatedUser, $email, $username); if ($response instanceof Response) { return $response; } else { if (is_string($response)) { $page->set('error', $response); } } } // Name if ($name = $deligatedUser->getWelcomeName()) { $page->set('name', $name); } // Email. if ($email = $this->request->input('email')) { $page->set('email', $email); } else { if ($email = $deligatedUser->getEmail()) { $page->set('email', $email); } else { $page->set('email', ''); } } // Username. if ($username = $this->request->input('username')) { $page->set('username', $username); } else { if ($username = $deligatedUser->getProposedUsername()) { $page->set('username', $username); } else { $page->set('username', ''); } } return Response::template($page); }