convert invite

This commit is contained in:
Evan Prodromou 2009-01-22 22:51:37 +00:00
parent d6879bfe0c
commit 03ce6aee2e
1 changed files with 61 additions and 37 deletions

View File

@ -21,6 +21,7 @@ if (!defined('LACONICA')) { exit(1); }
class InviteAction extends Action class InviteAction extends Action
{ {
var $mode = null;
function isReadOnly() function isReadOnly()
{ {
@ -35,19 +36,18 @@ class InviteAction extends Action
common_config('site', 'name'))); common_config('site', 'name')));
return; return;
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') { } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->send_invitations(); $this->sendInvitations();
} else { } else {
$this->show_form(); $this->showForm();
} }
} }
function send_invitations() function sendInvitations()
{ {
# CSRF protection # CSRF protection
$token = $this->trimmed('token'); $token = $this->trimmed('token');
if (!$token || $token != common_session_token()) { if (!$token || $token != common_session_token()) {
$this->show_form(_('There was a problem with your session token. Try again, please.')); $this->showForm(_('There was a problem with your session token. Try again, please.'));
return; return;
} }
@ -63,78 +63,105 @@ class InviteAction extends Action
foreach ($addresses as $email) { foreach ($addresses as $email) {
$email = trim($email); $email = trim($email);
if (!Validate::email($email, true)) { if (!Validate::email($email, true)) {
$this->show_form(sprintf(_('Invalid email address: %s'), $email)); $this->showForm(sprintf(_('Invalid email address: %s'), $email));
return; return;
} }
} }
$already = array(); $this->already = array();
$subbed = array(); $this->subbed = array();
foreach ($addresses as $email) { foreach ($addresses as $email) {
$email = common_canonical_email($email); $email = common_canonical_email($email);
$other = User::staticGet('email', $email); $other = User::staticGet('email', $email);
if ($other) { if ($other) {
if ($user->isSubscribed($other)) { if ($user->isSubscribed($other)) {
$already[] = $other; $this->already[] = $other;
} else { } else {
subs_subscribe_to($user, $other); subs_subscribe_to($user, $other);
$subbed[] = $other; $this->subbed[] = $other;
} }
} else { } else {
$sent[] = $email; $this->sent[] = $email;
$this->send_invitation($email, $user, $personal); $this->sendInvitation($email, $user, $personal);
} }
} }
common_show_header(_('Invitation(s) sent')); $this->mode = 'sent';
if ($already) {
$this->showPage();
}
function title()
{
if ($this->mode == 'sent') {
return _('Invitation(s) sent');
} else {
return _('Invite new users');
}
}
function showContent()
{
if ($this->mode == 'sent') {
$this->showInvitationSuccess();
} else {
$this->showInviteForm();
}
}
function showInvitationSuccess()
{
if ($this->already) {
$this->element('p', null, _('You are already subscribed to these users:')); $this->element('p', null, _('You are already subscribed to these users:'));
$this->elementStart('ul'); $this->elementStart('ul');
foreach ($already as $other) { foreach ($this->already as $other) {
$this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email)); $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
} }
$this->elementEnd('ul'); $this->elementEnd('ul');
} }
if ($subbed) { if ($this->subbed) {
$this->element('p', null, _('These people are already users and you were automatically subscribed to them:')); $this->element('p', null, _('These people are already users and you were automatically subscribed to them:'));
$this->elementStart('ul'); $this->elementStart('ul');
foreach ($subbed as $other) { foreach ($this->subbed as $other) {
$this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email)); $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email));
} }
$this->elementEnd('ul'); $this->elementEnd('ul');
} }
if ($sent) { if ($this->sent) {
$this->element('p', null, _('Invitation(s) sent to the following people:')); $this->element('p', null, _('Invitation(s) sent to the following people:'));
$this->elementStart('ul'); $this->elementStart('ul');
foreach ($sent as $other) { foreach ($this->sent as $other) {
$this->element('li', null, $other); $this->element('li', null, $other);
} }
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->element('p', null, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!')); $this->element('p', null, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
} }
common_show_footer();
} }
function show_top($error=null) function showPageNotice()
{ {
if ($error) { if ($this->mode != 'sent') {
$this->element('p', 'error', $error); if ($this->error) {
} else { $this->element('p', 'error', $this->error);
$this->elementStart('div', 'instructions'); } else {
$this->element('p', null, $this->elementStart('div', 'instructions');
_('Use this form to invite your friends and colleagues to use this service.')); $this->element('p', null,
$this->elementEnd('div'); _('Use this form to invite your friends and colleagues to use this service.'));
$this->elementEnd('div');
}
} }
} }
function show_form($error=null) function showForm($error=null)
{ {
$this->mode = 'form';
$this->error = $error;
$this->showPage();
}
global $config; function showInviteForm()
{
common_show_header(_('Invite new users'), null, $error, array($this, 'show_top'));
$this->elementStart('form', array('method' => 'post', $this->elementStart('form', array('method' => 'post',
'id' => 'invite', 'id' => 'invite',
'action' => common_local_url('invite'))); 'action' => common_local_url('invite')));
@ -151,13 +178,10 @@ class InviteAction extends Action
$this->submit('send', _('Send')); $this->submit('send', _('Send'));
$this->elementEnd('form'); $this->elementEnd('form');
common_show_footer();
} }
function send_invitation($email, $user, $personal) function sendInvitation($email, $user, $personal)
{ {
$profile = $user->getProfile(); $profile = $user->getProfile();
$bestname = $profile->getBestName(); $bestname = $profile->getBestName();