store invite code in session so openidfinish can find it

This commit is contained in:
Evan Prodromou 2009-04-17 12:52:26 -07:00
parent 34d904b180
commit 231c61a7eb
2 changed files with 127 additions and 77 deletions

View File

@ -191,11 +191,28 @@ class FinishopenidloginAction extends Action
{
# FIXME: save invite code before redirect, and check here
if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
if (common_config('site', 'closed')) {
$this->clientError(_('Registration not allowed.'));
return;
}
$invite = null;
if (common_config('site', 'inviteonly')) {
$code = $_SESSION['invitecode'];
if (empty($code)) {
$this->clientError(_('Registration not allowed.'));
return;
}
$invite = Invitation::staticGet($code);
if (empty($invite)) {
$this->clientError(_('Not a valid invitation code.'));
return;
}
}
$nickname = $this->trimmed('newname');
if (!Validate::string($nickname, array('min_length' => 1,
@ -257,10 +274,16 @@ class FinishopenidloginAction extends Action
# XXX: add language
# XXX: add timezone
$user = User::register(array('nickname' => $nickname,
$args = array('nickname' => $nickname,
'email' => $email,
'fullname' => $fullname,
'location' => $location));
'location' => $location);
if (!empty($invite)) {
$args['code'] = $invite->code;
}
$user = User::register($args);
$result = oid_link_user($user->id, $canonical, $display);

View File

@ -55,6 +55,44 @@ class RegisterAction extends Action
var $registered = false;
/**
* Prepare page to run
*
*
* @param $args
* @return string title
*/
function prepare()
{
$this->code = $this->trimmed('code');
if (empty($this->code)) {
common_ensure_session();
if (!empty($_SESSION['invitecode'])) {
$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);
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;
}
/**
* Title of the page
*
@ -343,17 +381,6 @@ class RegisterAction extends Action
function showFormContent()
{
$code = $this->trimmed('code');
if ($code) {
$invite = Invitation::staticGet($code);
}
if (common_config('site', 'inviteonly') && !($code && $invite)) {
$this->clientError(_('Sorry, only invited people can register.'));
return;
}
$this->elementStart('form', array('method' => 'post',
'id' => 'form_register',
'class' => 'form_settings',
@ -362,8 +389,8 @@ class RegisterAction extends Action
$this->element('legend', null, 'Account settings');
$this->hidden('token', common_session_token());
if ($code) {
$this->hidden('code', $code);
if ($this->code) {
$this->hidden('code', $this->code);
}
$this->elementStart('ul', 'form_data');
@ -382,8 +409,8 @@ class RegisterAction extends Action
_('Same as password above. Required.'));
$this->elementEnd('li');
$this->elementStart('li');
if ($invite && $invite->address_type == 'email') {
$this->input('email', _('Email'), $invite->address,
if ($this->invite && $this->invite->address_type == 'email') {
$this->input('email', _('Email'), $this->invite->address,
_('Used only for updates, announcements, '.
'and password recovery'));
} else {