-class FinishopenidloginAction extends Action {
-
- function handle($args) {
- parent::handle($args);
- if (common_logged_in()) {
- common_user_error(_('Already logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
- if ($this->arg('create')) {
- if (!$this->boolean('license')) {
- $this->show_form(_('You can\'t register if you don\'t agree to the license.'),
- $this->trimmed('newname'));
- return;
- }
- $this->create_new_user();
- } else if ($this->arg('connect')) {
- $this->connect_user();
- } else {
- common_debug(print_r($this->args, true), __FILE__);
- $this->show_form(_('Something weird happened.'),
- $this->trimmed('newname'));
- }
- } else {
- $this->try_login();
- }
- }
-
- function show_top($error=NULL) {
- if ($error) {
- common_element('div', array('class' => 'error'), $error);
- } else {
- global $config;
- common_element('div', 'instructions',
- sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), $config['site']['name']));
- }
- }
-
- function show_form($error=NULL, $username=NULL) {
- common_show_header(_('OpenID Account Setup'), NULL, $error,
- array($this, 'show_top'));
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'account_connect',
- 'action' => common_local_url('finishopenidlogin')));
- common_hidden('token', common_session_token());
- common_element('h2', NULL,
- _('Create new account'));
- common_element('p', NULL,
- _('Create a new user with this nickname.'));
- common_input('newname', _('New nickname'),
- ($username) ? $username : '',
- _('1-64 lowercase letters or numbers, no punctuation or spaces'));
- common_element_start('p');
- common_element('input', array('type' => 'checkbox',
- 'id' => 'license',
- 'name' => 'license',
- 'value' => 'true'));
- common_text(_('My text and files are available under '));
- common_element('a', array(href => common_config('license', 'url')),
- common_config('license', 'title'));
- common_text(_(' except this private data: password, email address, IM address, phone number.'));
- common_element_end('p');
- common_submit('create', _('Create'));
- common_element('h2', NULL,
- _('Connect existing account'));
- common_element('p', NULL,
- _('If you already have an account, login with your username and password to connect it to your OpenID.'));
- common_input('nickname', _('Existing nickname'));
- common_password('password', _('Password'));
- common_submit('connect', _('Connect'));
- common_element_end('form');
- common_show_footer();
- }
-
- function try_login() {
-
- $consumer = oid_consumer();
-
- $response = $consumer->complete(common_local_url('finishopenidlogin'));
-
- if ($response->status == Auth_OpenID_CANCEL) {
- $this->message(_('OpenID authentication cancelled.'));
- return;
- } else if ($response->status == Auth_OpenID_FAILURE) {
- // Authentication failed; display the error message.
- $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
- } else if ($response->status == Auth_OpenID_SUCCESS) {
- // This means the authentication succeeded; extract the
- // identity URL and Simple Registration data (if it was
- // returned).
- $display = $response->getDisplayIdentifier();
- $canonical = ($response->endpoint->canonicalID) ?
- $response->endpoint->canonicalID : $response->getDisplayIdentifier();
-
- $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
-
- if ($sreg_resp) {
- $sreg = $sreg_resp->contents();
- }
-
- $user = oid_get_user($canonical);
-
- if ($user) {
- oid_set_last($display);
- # XXX: commented out at @edd's request until better
- # control over how data flows from OpenID provider.
- # oid_update_user($user, $sreg);
- common_set_user($user);
- common_real_login(true);
- if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
- common_rememberme($user);
- }
+class FinishopenidloginAction extends Action
+{
+
+ function handle($args)
+ {
+ parent::handle($args);
+ if (common_logged_in()) {
+ common_user_error(_('Already logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+ if ($this->arg('create')) {
+ if (!$this->boolean('license')) {
+ $this->show_form(_('You can\'t register if you don\'t agree to the license.'),
+ $this->trimmed('newname'));
+ return;
+ }
+ $this->create_new_user();
+ } else if ($this->arg('connect')) {
+ $this->connect_user();
+ } else {
+ common_debug(print_r($this->args, true), __FILE__);
+ $this->show_form(_('Something weird happened.'),
+ $this->trimmed('newname'));
+ }
+ } else {
+ $this->try_login();
+ }
+ }
+
+ function show_top($error=null)
+ {
+ if ($error) {
+ common_element('div', array('class' => 'error'), $error);
+ } else {
+ global $config;
+ common_element('div', 'instructions',
+ sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), $config['site']['name']));
+ }
+ }
+
+ function show_form($error=null, $username=null)
+ {
+ common_show_header(_('OpenID Account Setup'), null, $error,
+ array($this, 'show_top'));
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'account_connect',
+ 'action' => common_local_url('finishopenidlogin')));
+ common_hidden('token', common_session_token());
+ common_element('h2', null,
+ _('Create new account'));
+ common_element('p', null,
+ _('Create a new user with this nickname.'));
+ common_input('newname', _('New nickname'),
+ ($username) ? $username : '',
+ _('1-64 lowercase letters or numbers, no punctuation or spaces'));
+ common_element_start('p');
+ common_element('input', array('type' => 'checkbox',
+ 'id' => 'license',
+ 'name' => 'license',
+ 'value' => 'true'));
+ common_text(_('My text and files are available under '));
+ common_element('a', array(href => common_config('license', 'url')),
+ common_config('license', 'title'));
+ common_text(_(' except this private data: password, email address, IM address, phone number.'));
+ common_element_end('p');
+ common_submit('create', _('Create'));
+ common_element('h2', null,
+ _('Connect existing account'));
+ common_element('p', null,
+ _('If you already have an account, login with your username and password to connect it to your OpenID.'));
+ common_input('nickname', _('Existing nickname'));
+ common_password('password', _('Password'));
+ common_submit('connect', _('Connect'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function try_login()
+ {
+
+ $consumer = oid_consumer();
+
+ $response = $consumer->complete(common_local_url('finishopenidlogin'));
+
+ if ($response->status == Auth_OpenID_CANCEL) {
+ $this->message(_('OpenID authentication cancelled.'));
+ return;
+ } else if ($response->status == Auth_OpenID_FAILURE) {
+ // Authentication failed; display the error message.
+ $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
+ } else if ($response->status == Auth_OpenID_SUCCESS) {
+ // This means the authentication succeeded; extract the
+ // identity URL and Simple Registration data (if it was
+ // returned).
+ $display = $response->getDisplayIdentifier();
+ $canonical = ($response->endpoint->canonicalID) ?
+ $response->endpoint->canonicalID : $response->getDisplayIdentifier();
+
+ $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
+
+ if ($sreg_resp) {
+ $sreg = $sreg_resp->contents();
+ }
+
+ $user = oid_get_user($canonical);
+
+ if ($user) {
+ oid_set_last($display);
+ # XXX: commented out at @edd's request until better
+ # control over how data flows from OpenID provider.
+ # oid_update_user($user, $sreg);
+ common_set_user($user);
+ common_real_login(true);
+ if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
+ common_rememberme($user);
+ }