/** * Prepare page to run * * * @param $args * @return string title */ function prepare($args) { parent::prepare($args); $this->code = $this->trimmed('code'); $this->type = $this->trimmed('type'); if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { $this->clientError(_('Sorry, only invited people can register.')); return false; } if (!empty($this->code)) { $this->invite = Invitation::staticGet('code', $this->code); if (empty($this->invite)) { $this->clientError(_('Sorry, invalid invitation code.')); return false; } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } return true; }
function handle($args) { parent::handle($args); if (common_is_real_login()) { // TRANS: Client error message trying to log on with OpenID while already logged on. $this->clientError(_m('Already logged in.')); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $provider = common_config('openid', 'trusted_provider'); if ($provider) { $openid_url = $provider; if (common_config('openid', 'append_username')) { $openid_url .= $this->trimmed('openid_username'); } } else { $openid_url = $this->trimmed('openid_url'); } oid_assert_allowed($openid_url); $rememberme = $this->boolean('rememberme'); common_ensure_session(); $_SESSION['openid_rememberme'] = $rememberme; $result = oid_authenticate($openid_url, 'finishopenidlogin'); if (is_string($result)) { # error message unset($_SESSION['openid_rememberme']); $this->showForm($result, $openid_url); } } else { $openid_url = oid_get_last(); $this->showForm(null, $openid_url); } } }
/** * Prepare page to run * * * @param $args * @return string title */ protected function prepare(array $args = array()) { parent::prepare($args); $this->code = $this->trimmed('code'); if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { // TRANS: Client error displayed when trying to register to an invite-only site without an invitation. $this->clientError(_('Sorry, only invited people can register.')); } if (!empty($this->code)) { $this->invite = Invitation::getKV('code', $this->code); if (!$this->invite instanceof Invitation) { // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation. $this->clientError(_('Sorry, invalid invitation code.')); } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } return true; }
function handle($args) { parent::handle($args); if (common_is_real_login()) { $this->clientError(_('Already logged in.')); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $openid_url = $this->trimmed('openid_url'); # CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. Try again, please.'), $openid_url); return; } $rememberme = $this->boolean('rememberme'); common_ensure_session(); $_SESSION['openid_rememberme'] = $rememberme; $result = oid_authenticate($openid_url, 'finishopenidlogin'); if (is_string($result)) { # error message unset($_SESSION['openid_rememberme']); $this->showForm($result, $openid_url); } } else { $openid_url = oid_get_last(); $this->showForm(null, $openid_url); } } }
/** * Handle input, produce output * * Switches on request method; either shows the form or handles its input. * * @param array $args $_REQUEST data * * @return void */ function handle($args) { parent::handle($args); if (common_is_real_login()) { $this->clientError(_('Already logged in.')); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->checkLogin(); } else { common_ensure_session(); $this->showForm(); } } }
function prepare($args) { parent::prepare($args); common_ensure_session(); $this->user = common_current_user(); if (empty($this->user)) { /* Go log in, and then come back. */ common_set_returnto($_SERVER['REQUEST_URI']); common_redirect(common_local_url('login')); return; } $this->trust_root = $_SESSION['openid_trust_root']; $this->allowUrl = $_SESSION['openid_allow_url']; $this->denyUrl = $_SESSION['openid_deny_url']; if (empty($this->trust_root) || empty($this->allowUrl) || empty($this->denyUrl)) { $this->clientError(_m('This page should only be reached during OpenID processing, not directly.')); return; } return true; }
function handle($args) { parent::handle($args); if (common_is_real_login()) { // TRANS: Client error message trying to log on with OpenID while already logged on. $this->clientError(_m('Already logged in.')); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $provider = common_config('openid', 'trusted_provider'); if ($provider) { $openid_url = $provider; if (common_config('openid', 'append_username')) { $openid_url .= $this->trimmed('openid_username'); } } else { $openid_url = $this->trimmed('openid_url'); } oid_assert_allowed($openid_url); # CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { // TRANS: Message given when there is a problem with the user's session token. $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url); return; } $rememberme = $this->boolean('rememberme'); common_ensure_session(); $_SESSION['openid_rememberme'] = $rememberme; $result = oid_authenticate($openid_url, 'finishopenidlogin'); if (is_string($result)) { # error message unset($_SESSION['openid_rememberme']); $this->showForm($result, $openid_url); } } else { $openid_url = oid_get_last(); $this->showForm(null, $openid_url); } } }
function oid_authenticate($openid_url, $returnto, $immediate = false) { $consumer = oid_consumer(); if (!$consumer) { common_server_error(_m('Cannot instantiate OpenID consumer object.')); return false; } common_ensure_session(); $auth_request = $consumer->begin($openid_url); // Handle failure status return values. if (!$auth_request) { return _m('Not a valid OpenID.'); } else { if (Auth_OpenID::isFailure($auth_request)) { return sprintf(_m('OpenID failure: %s'), $auth_request->message); } } $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country')); if ($sreg_request) { $auth_request->addExtension($sreg_request); } $trust_root = common_root_url(true); $process_url = common_local_url($returnto); if ($auth_request->shouldSendRedirect()) { $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate); if (!$redirect_url) { } else { if (Auth_OpenID::isFailure($redirect_url)) { return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message); } else { common_redirect($redirect_url, 303); } } } else { // Generate form markup and render it. $form_id = 'openid_message'; $form_html = $auth_request->formMarkup($trust_root, $process_url, $immediate, array('id' => $form_id)); # XXX: This is cheap, but things choke if we don't escape ampersands # in the HTML attributes $form_html = preg_replace('/&/', '&', $form_html); // Display an error if the form markup couldn't be generated; // otherwise, render the HTML. if (Auth_OpenID::isFailure($form_html)) { common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message)); } else { $action = new AutosubmitAction(); // see below $action->form_html = $form_html; $action->form_id = $form_id; $action->prepare(array('action' => 'autosubmit')); $action->handle(array('action' => 'autosubmit')); } } }
function setLoginUser($user) { if (common_is_real_login()) { $this->logoutWeb(); } common_ensure_session(); // success! if (!common_set_user($user)) { // TRANS: Server error displayed when during login a server error occurs. $this->serverError(_('Error setting user. You are probably not authorized.')); return; } common_real_login(true); }
/** * Prepare page to run * * * @param $args * @return string title */ function prepare($args) { parent::prepare($args); $this->code = $this->trimmed('code'); // @todo this check should really be in index.php for all sensitive actions $ssl = common_config('site', 'ssl'); if (empty($_SERVER['HTTPS']) && ($ssl == 'always' || $ssl == 'sometimes')) { common_redirect(common_local_url('register')); // exit } if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { $this->clientError(_('Sorry, only invited people can register.')); return false; } if (!empty($this->code)) { $this->invite = Invitation::staticGet('code', $this->code); if (empty($this->invite)) { $this->clientError(_('Sorry, invalid invitation code.')); return false; } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } return true; }
function oid_authenticate($openid_url, $returnto, $immediate = false) { $consumer = oid_consumer(); if (!$consumer) { // TRANS: OpenID plugin server error. common_server_error(_m('Cannot instantiate OpenID consumer object.')); return false; } common_ensure_session(); $auth_request = $consumer->begin($openid_url); // Handle failure status return values. if (!$auth_request) { common_log(LOG_ERR, __METHOD__ . ": mystery fail contacting {$openid_url}"); // TRANS: OpenID plugin message. Given when an OpenID is not valid. return _m('Not a valid OpenID.'); } else { if (Auth_OpenID::isFailure($auth_request)) { common_log(LOG_ERR, __METHOD__ . ": OpenID fail to {$openid_url}: {$auth_request->message}"); // TRANS: OpenID plugin server error. Given when the OpenID authentication request fails. // TRANS: %s is the failure message. return sprintf(_m('OpenID failure: %s'), $auth_request->message); } } $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country')); if ($sreg_request) { $auth_request->addExtension($sreg_request); } $requiredTeam = common_config('openid', 'required_team'); if ($requiredTeam) { // LaunchPad OpenID extension $team_request = new Auth_OpenID_TeamsRequest(array($requiredTeam)); if ($team_request) { $auth_request->addExtension($team_request); } } $trust_root = common_root_url(true); $process_url = common_local_url($returnto); // Net::OpenID::Server as used on LiveJournal appears to incorrectly // reject POST requests for data submissions that OpenID 1.1 specs // as GET, although 2.0 allows them: // https://rt.cpan.org/Public/Bug/Display.html?id=42202 // // Our OpenID libraries would have switched in the redirect automatically // if it were detecting 1.1 compatibility mode, however the server is // advertising itself as 2.0-compatible, so we got switched to the POST. // // Since the GET should always work anyway, we'll just take out the // autosubmitter for now. // //if ($auth_request->shouldSendRedirect()) { $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate); if (!$redirect_url) { } else { if (Auth_OpenID::isFailure($redirect_url)) { // TRANS: OpenID plugin server error. Given when the OpenID authentication request cannot be redirected. // TRANS: %s is the failure message. return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message); } else { common_redirect($redirect_url, 303); } } /* } else { // Generate form markup and render it. $form_id = 'openid_message'; $form_html = $auth_request->formMarkup($trust_root, $process_url, $immediate, array('id' => $form_id)); # XXX: This is cheap, but things choke if we don't escape ampersands # in the HTML attributes $form_html = preg_replace('/&/', '&', $form_html); // Display an error if the form markup couldn't be generated; // otherwise, render the HTML. if (Auth_OpenID::isFailure($form_html)) { // TRANS: OpenID plugin server error if the form markup could not be generated. // TRANS: %s is the failure message. common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message)); } else { $action = new AutosubmitAction(); // see below $action->form_html = $form_html; $action->form_id = $form_id; $action->prepare(array('action' => 'autosubmit')); $action->handle(array('action' => 'autosubmit')); } } */ }
function onArgsInitialize() { // We always want a session because we're tracking anon users common_ensure_session(); }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $nickname = $this->trimmed('nickname'); $email = $this->trimmed('email'); $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); $bio = $this->trimmed('bio'); $location = $this->trimmed('location'); // We don't trim these... whitespace is OK in a password! $password = $this->arg('password'); $confirm = $this->arg('confirm'); if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { // TRANS: Client error displayed when trying to register to an invite-only site without an invitation. $this->clientError(_('Sorry, only invited people can register.'), 401); } if (!empty($this->code)) { $this->invite = Invitation::getKV('code', $this->code); if (empty($this->invite)) { // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation. $this->clientError(_('Sorry, invalid invitation code.'), 401); } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } // Input scrubbing try { $nickname = Nickname::normalize($nickname, true); } catch (NicknameException $e) { // clientError handles Api exceptions with various formats and stuff $this->clientError($e->getMessage(), $e->getCode()); } $email = common_canonical_email($email); if ($email && !Validate::email($email, common_config('email', 'check_domain'))) { // TRANS: Form validation error displayed when trying to register without a valid e-mail address. $this->clientError(_('Not a valid email address.'), 400); } else { if ($this->emailExists($email)) { // TRANS: Form validation error displayed when trying to register with an already registered e-mail address. $this->clientError(_('Email address already exists.'), 400); } else { if (!is_null($homepage) && strlen($homepage) > 0 && !common_valid_http_url($homepage)) { // TRANS: Form validation error displayed when trying to register with an invalid homepage URL. $this->clientError(_('Homepage is not a valid URL.'), 400); } else { if (!is_null($fullname) && mb_strlen($fullname) > 255) { // TRANS: Form validation error displayed when trying to register with a too long full name. $this->clientError(_('Full name is too long (maximum 255 characters).'), 400); } else { if (Profile::bioTooLong($bio)) { // TRANS: Form validation error on registration page when providing too long a bio text. // TRANS: %d is the maximum number of characters for bio; used for plural. $this->clientError(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()), 400); } else { if (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Form validation error displayed when trying to register with a too long location. $this->clientError(_('Location is too long (maximum 255 characters).'), 400); } else { if (strlen($password) < 6) { // TRANS: Form validation error displayed when trying to register with too short a password. $this->clientError(_('Password must be 6 or more characters.'), 400); } else { if ($password != $confirm) { // TRANS: Form validation error displayed when trying to register with non-matching passwords. $this->clientError(_('Passwords do not match.'), 400); } else { // annoy spammers sleep(7); try { $user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $this->code)); Event::handle('EndRegistrationTry', array($this)); $this->initDocument('json'); $this->showJsonObjects($this->twitterUserArray($user->getProfile())); $this->endDocument('json'); } catch (Exception $e) { $this->clientError($e->getMessage(), 400); } } } } } } } } } }
/** * Handle input, produce output * * Switches on request method; either shows the form or handles its input. * * @param array $args $_REQUEST data * * @return void */ function handle($args) { parent::handle($args); if (common_is_real_login()) { $user = common_current_user(); common_redirect(common_local_url('all', array('nickname' => $user->nickname)), 307); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->checkLogin(); } else { common_ensure_session(); $this->showForm(); } } }
function common_session_token() { common_ensure_session(); if (!array_key_exists('token', $_SESSION)) { $_SESSION['token'] = common_good_rand(64); } return $_SESSION['token']; }
function remoteSubscription() { if (!$this->nickname) { $this->showForm(_('No such user.')); return; } $user = User::staticGet('nickname', $this->nickname); $this->profile_url = $this->trimmed('profile_url'); if (!$this->profile_url) { $this->showForm(_('No such user.')); return; } if (!common_valid_http_url($this->profile_url)) { $this->showForm(_('Invalid profile URL (bad format)')); return; } try { $service = new OMB_Service_Consumer($this->profile_url, common_root_url(), omb_oauth_datastore()); } catch (OMB_InvalidYadisException $e) { $this->showForm(_('Not a valid profile URL (no YADIS document or ' . 'invalid XRDS defined).')); return; } if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) == common_local_url('requesttoken') || User::staticGet('uri', $service->getRemoteUserURI())) { $this->showForm(_('That’s a local profile! Login to subscribe.')); return; } try { $service->requestToken(); } catch (OMB_RemoteServiceException $e) { $this->showForm(_('Couldn’t get a request token.')); return; } /* Create an OMB_Profile from $user. */ $profile = $user->getProfile(); if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); $this->serverError(_('User without matching profile.')); return; } $target_url = $service->requestAuthorization(profile_to_omb_profile($user->uri, $profile), common_local_url('finishremotesubscribe')); common_ensure_session(); $_SESSION['oauth_authorization_request'] = serialize($service); /* Redirect to the remote service for authorization. */ common_redirect($target_url, 303); }
/** * Handle input, produce output * * Switches on request method; either shows the form or handles its input. * * @param array $args $_REQUEST data * * @return void */ function handle($args) { parent::handle($args); if (common_is_real_login()) { // TRANS: Client error displayed when trying to log in while already logged in. $this->clientError(_('Already logged in.')); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->checkLogin(); } else { common_ensure_session(); $this->showForm(); } } }
function saveValues($display, $canonical, $sreg) { common_ensure_session(); $_SESSION['openid_display'] = $display; $_SESSION['openid_canonical'] = $canonical; $_SESSION['openid_sreg'] = $sreg; }
function handle($args) { parent::handle($args); $request = $this->oserver->decodeRequest(); if (in_array($request->mode, array('checkid_immediate', 'checkid_setup'))) { $user = common_current_user(); if (!$user) { if ($request->immediate) { //cannot prompt the user to login in immediate mode, so answer false $response = $this->generateDenyResponse($request); } else { // Go log in, and then come back. // // Note: 303 redirect rather than 307 to avoid // prompting user for form resubmission if we // were POSTed here. common_set_returnto($_SERVER['REQUEST_URI']); common_redirect(common_local_url('login'), 303); return; } } else { if (common_profile_url($user->nickname) == $request->identity || $request->idSelect()) { $user_openid_trustroot = User_openid_trustroot::pkeyGet(array('user_id' => $user->id, 'trustroot' => $request->trust_root)); if (empty($user_openid_trustroot)) { if ($request->immediate) { //cannot prompt the user to trust this trust root in immediate mode, so answer false $response = $this->generateDenyResponse($request); } else { common_ensure_session(); $_SESSION['openid_trust_root'] = $request->trust_root; $allowResponse = $this->generateAllowResponse($request, $user); $this->oserver->encodeResponse($allowResponse); //sign the response $denyResponse = $this->generateDenyResponse($request); $this->oserver->encodeResponse($denyResponse); //sign the response $_SESSION['openid_allow_url'] = $allowResponse->encodeToUrl(); $_SESSION['openid_deny_url'] = $denyResponse->encodeToUrl(); // Ask the user to trust this trust root... // // Note: 303 redirect rather than 307 to avoid // prompting user for form resubmission if we // were POSTed here. common_redirect(common_local_url('openidtrust'), 303); return; } } else { //user has previously authorized this trust root $response = $this->generateAllowResponse($request, $user); //$response = $request->answer(true, null, common_profile_url($user->nickname)); } } else { if ($request->immediate) { $response = $this->generateDenyResponse($request); } else { //invalid // TRANS: OpenID plugin client error given trying to add an unauthorised OpenID to a user (403). // TRANS: %s is a request identity. $this->clientError(sprintf(_m('You are not authorized to use the identity %s.'), $request->identity), $code = 403); } } } } else { $response = $this->oserver->handleRequest($request); } if ($response) { $response = $this->oserver->encodeResponse($response); if ($response->code != AUTH_OPENID_HTTP_OK) { header(sprintf("HTTP/1.1 %d ", $response->code), true, $response->code); } if ($response->headers) { foreach ($response->headers as $k => $v) { header("{$k}: {$v}"); } } $this->raw($response->body); } else { // TRANS: OpenID plugin client error given when not getting a response for a given OpenID provider (500). $this->clientError(_m('Just an OpenID provider. Nothing to see here, move along...'), $code = 500); } }
function getStoredParams() { common_ensure_session(); $params = unserialize($_SESSION['userauthorizationparams']); return $params; }
function requestAuthorization($user, $omb, $token, $secret) { $con = omb_oauth_consumer(); $tok = new OAuthToken($token, $secret); $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]); # XXX: Is this the right thing to do? Strip off GET params and make them # POST params? Seems wrong to me. $parsed = parse_url($url); $params = array(); parse_str($parsed['query'], $params); $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params); # We send over a ton of information. This lets the other # server store info about our user, and it lets the current # user decide if they really want to authorize the subscription. $req->set_parameter('omb_version', OMB_VERSION_01); $req->set_parameter('omb_listener', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])); $req->set_parameter('omb_listenee', $user->uri); $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname)); $req->set_parameter('omb_listenee_nickname', $user->nickname); $req->set_parameter('omb_listenee_license', common_config('license', 'url')); $profile = $user->getProfile(); if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); $this->serverError(_('User without matching profile')); return; } if (!is_null($profile->fullname)) { $req->set_parameter('omb_listenee_fullname', $profile->fullname); } if (!is_null($profile->homepage)) { $req->set_parameter('omb_listenee_homepage', $profile->homepage); } if (!is_null($profile->bio)) { $req->set_parameter('omb_listenee_bio', $profile->bio); } if (!is_null($profile->location)) { $req->set_parameter('omb_listenee_location', $profile->location); } $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); if ($avatar) { $req->set_parameter('omb_listenee_avatar', $avatar->url); } # XXX: add a nonce to prevent replay attacks $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe')); # XXX: test to see if endpoint accepts this signature method $req->sign_request(omb_hmac_sha1(), $con, $tok); # store all our info here $omb['listenee'] = $user->nickname; $omb['listener'] = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]); $omb['token'] = $token; $omb['secret'] = $secret; # call doesn't work after bounce back so we cache; maybe serialization issue...? $omb['access_token_url'] = omb_service_uri($omb[OAUTH_ENDPOINT_ACCESS]); $omb['post_notice_url'] = omb_service_uri($omb[OMB_ENDPOINT_POSTNOTICE]); $omb['update_profile_url'] = omb_service_uri($omb[OMB_ENDPOINT_UPDATEPROFILE]); common_ensure_session(); $_SESSION['oauth_authorization_request'] = $omb; # Redirect to authorization service common_redirect($req->to_url()); return; }
function clearTempUser() { common_ensure_session(); unset($_SESSION['tempuser']); }
function getStoredRequest() { common_ensure_session(); $req = $_SESSION['userauthorizationrequest']; return $req; }