require_once(INSTALLDIR.'/lib/openid.php');
-class FinishopenidloginAction extends Action {
+class FinishopenidloginAction extends Action
+{
- function handle($args) {
+ function handle($args)
+ {
parent::handle($args);
if (common_logged_in()) {
- common_user_error(_('Already logged in.'));
+ $this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
}
}
- function show_top($error=NULL) {
+ function show_top($error=null)
+ {
if ($error) {
- common_element('div', array('class' => 'error'), $error);
+ $this->element('div', array('class' => 'error'), $error);
} else {
global $config;
- common_element('div', 'instructions',
+ $this->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,
+ 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',
+ $this->elementStart('form', array('method' => 'post',
'id' => 'account_connect',
'action' => common_local_url('finishopenidlogin')));
- common_hidden('token', common_session_token());
- common_element('h2', NULL,
+ $this->hidden('token', common_session_token());
+ $this->element('h2', null,
_('Create new account'));
- common_element('p', NULL,
+ $this->element('p', null,
_('Create a new user with this nickname.'));
- common_input('newname', _('New nickname'),
+ $this->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',
+ $this->elementStart('p');
+ $this->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')),
+ $this->text(_('My text and files are available under '));
+ $this->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,
+ $this->text(_(' except this private data: password, email address, IM address, phone number.'));
+ $this->elementEnd('p');
+ $this->submit('create', _('Create'));
+ $this->element('h2', null,
_('Connect existing account'));
- common_element('p', NULL,
+ $this->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');
+ $this->input('nickname', _('Existing nickname'));
+ $this->password('password', _('Password'));
+ $this->submit('connect', _('Connect'));
+ $this->elementEnd('form');
common_show_footer();
}
- function try_login() {
+ function try_login()
+ {
$consumer = oid_consumer();
$this->go_home($user->nickname);
} else {
$this->save_values($display, $canonical, $sreg);
- $this->show_form(NULL, $this->best_new_nickname($display, $sreg));
+ $this->show_form(null, $this->best_new_nickname($display, $sreg));
}
}
}
- function message($msg) {
+ function message($msg)
+ {
common_show_header(_('OpenID Login'));
- common_element('p', NULL, $msg);
+ $this->element('p', null, $msg);
common_show_footer();
}
- function save_values($display, $canonical, $sreg) {
+ function save_values($display, $canonical, $sreg)
+ {
common_ensure_session();
$_SESSION['openid_display'] = $display;
$_SESSION['openid_canonical'] = $canonical;
$_SESSION['openid_sreg'] = $sreg;
}
- function get_saved_values() {
+ function get_saved_values()
+ {
return array($_SESSION['openid_display'],
$_SESSION['openid_canonical'],
$_SESSION['openid_sreg']);
}
- function create_new_user() {
+ function create_new_user()
+ {
# FIXME: save invite code before redirect, and check here
if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
- common_user_error(_('Registration not allowed.'));
+ $this->clientError(_('Registration not allowed.'));
return;
}
list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) {
- common_server_error(_('Stored OpenID not found.'));
+ $this->serverError(_('Stored OpenID not found.'));
return;
}
$other = oid_get_user($canonical);
if ($other) {
- common_server_error(_('Creating new account for OpenID that already has a user.'));
+ $this->serverError(_('Creating new account for OpenID that already has a user.'));
return;
}
common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)));
}
- function connect_user() {
+ function connect_user()
+ {
$nickname = $this->trimmed('nickname');
$password = $this->trimmed('password');
list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) {
- common_server_error(_('Stored OpenID not found.'));
+ $this->serverError(_('Stored OpenID not found.'));
return;
}
$result = oid_link_user($user->id, $canonical, $display);
if (!$result) {
- common_server_error(_('Error connecting user to OpenID.'));
+ $this->serverError(_('Error connecting user to OpenID.'));
return;
}
$this->go_home($user->nickname);
}
- function go_home($nickname) {
+ function go_home($nickname)
+ {
$url = common_get_returnto();
if ($url) {
# We don't have to return to it again
- common_set_returnto(NULL);
+ common_set_returnto(null);
} else {
$url = common_local_url('all',
array('nickname' =>
common_redirect($url);
}
- function best_new_nickname($display, $sreg) {
+ function best_new_nickname($display, $sreg)
+ {
# Try the passed-in nickname
# XXX: others?
- return NULL;
+ return null;
}
- function is_new_nickname($str) {
+ function is_new_nickname($str)
+ {
if (!Validate::string($str, array('min_length' => 1,
'max_length' => 64,
'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
return true;
}
- function openid_to_nickname($openid) {
+ function openid_to_nickname($openid)
+ {
if (Auth_Yadis_identifierScheme($openid) == 'XRI') {
return $this->xri_to_nickname($openid);
} else {
# 2. One element in path, like http://profile.typekey.com/EvanProdromou/
# or http://getopenid.com/evanprodromou
- function url_to_nickname($openid) {
+ function url_to_nickname($openid)
+ {
static $bad = array('query', 'user', 'password', 'port', 'fragment');
$parts = parse_url($openid);
foreach ($bad as $badpart) {
if (array_key_exists($badpart, $parts)) {
- return NULL;
+ return null;
}
}
}
}
- return NULL;
+ return null;
}
- function xri_to_nickname($xri) {
+ function xri_to_nickname($xri)
+ {
$base = $this->xri_base($xri);
if (!$base) {
- return NULL;
+ return null;
} else {
# =evan.prodromou
# or @gratis*evan.prodromou
}
}
- function xri_base($xri) {
+ function xri_base($xri)
+ {
if (substr($xri, 0, 6) == 'xri://') {
return substr($xri, 6);
} else {
# Given a string, try to make it work as a nickname
- function nicknamize($str) {
+ function nicknamize($str)
+ {
$str = preg_replace('/\W/', '', $str);
return strtolower($str);
}