Add a few events (hooks): RegistrationTry, RegistrationForData, ProfileFormData and ProfileSaveForm.
This commit is contained in:
parent
573d4cf0fb
commit
362cac0a96
|
@ -91,9 +91,9 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
$this->element('legend', null, _('Profile information'));
|
||||
$this->hidden('token', common_session_token());
|
||||
|
||||
# too much common patterns here... abstractable?
|
||||
|
||||
// too much common patterns here... abstractable?
|
||||
$this->elementStart('ul', 'form_data');
|
||||
if (Event::handle('StartProfileFormData', array($this))) {
|
||||
$this->elementStart('li');
|
||||
$this->input('nickname', _('Nickname'),
|
||||
($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname,
|
||||
|
@ -118,6 +118,7 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
($this->arg('location')) ? $this->arg('location') : $profile->location,
|
||||
_('Where you are, like "City, State (or Region), Country"'));
|
||||
$this->elementEnd('li');
|
||||
Event::handle('EndProfileFormData', array($this));
|
||||
$this->elementStart('li');
|
||||
$this->input('tags', _('Tags'),
|
||||
($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()),
|
||||
|
@ -127,7 +128,7 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
$language = common_language();
|
||||
$this->dropdown('language', _('Language'),
|
||||
get_nice_language_list(), _('Preferred language'),
|
||||
true, $language);
|
||||
false, $language);
|
||||
$this->elementEnd('li');
|
||||
$timezone = common_timezone();
|
||||
$timezones = array();
|
||||
|
@ -146,12 +147,12 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
($this->arg('autosubscribe')) ?
|
||||
$this->boolean('autosubscribe') : $user->autosubscribe);
|
||||
$this->elementEnd('li');
|
||||
}
|
||||
$this->elementEnd('ul');
|
||||
$this->submit('save', _('Save'));
|
||||
|
||||
$this->elementEnd('fieldset');
|
||||
$this->elementEnd('form');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,8 +166,7 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
|
||||
function handlePost()
|
||||
{
|
||||
# CSRF protection
|
||||
|
||||
// CSRF protection
|
||||
$token = $this->trimmed('token');
|
||||
if (!$token || $token != common_session_token()) {
|
||||
$this->showForm(_('There was a problem with your session token. '.
|
||||
|
@ -174,6 +174,8 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
return;
|
||||
}
|
||||
|
||||
if (Event::handle('StartProfileSaveForm', array($this))) {
|
||||
|
||||
$nickname = $this->trimmed('nickname');
|
||||
$fullname = $this->trimmed('fullname');
|
||||
$homepage = $this->trimmed('homepage');
|
||||
|
@ -184,8 +186,7 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
$timezone = $this->trimmed('timezone');
|
||||
$tagstring = $this->trimmed('tags');
|
||||
|
||||
# Some validation
|
||||
|
||||
// Some validation
|
||||
if (!Validate::string($nickname, array('min_length' => 1,
|
||||
'max_length' => 64,
|
||||
'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
|
||||
|
@ -259,13 +260,12 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
$this->serverError(_('Couldn\'t update user.'));
|
||||
return;
|
||||
} else {
|
||||
# Re-initialize language environment if it changed
|
||||
// Re-initialize language environment if it changed
|
||||
common_init_language();
|
||||
}
|
||||
}
|
||||
|
||||
# XXX: XOR
|
||||
|
||||
// XXX: XOR
|
||||
if ($user->autosubscribe ^ $autosubscribe) {
|
||||
|
||||
$original = clone($user);
|
||||
|
@ -303,8 +303,7 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
return;
|
||||
}
|
||||
|
||||
# Set the user tags
|
||||
|
||||
// Set the user tags
|
||||
$result = $user->setSelfTags($tags);
|
||||
|
||||
if (!$result) {
|
||||
|
@ -313,10 +312,12 @@ class ProfilesettingsAction extends AccountSettingsAction
|
|||
}
|
||||
|
||||
$user->query('COMMIT');
|
||||
|
||||
Event::handle('EndProfileSaveForm', array($this));
|
||||
common_broadcast_profile($profile);
|
||||
|
||||
$this->showForm(_('Settings saved.'), true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function nicknameExists($nickname)
|
||||
|
|
|
@ -108,6 +108,7 @@ class RegisterAction extends Action
|
|||
|
||||
function tryRegister()
|
||||
{
|
||||
if (Event::handle('StartRegistrationTry', array($this))) {
|
||||
$token = $this->trimmed('token');
|
||||
if (!$token || $token != common_session_token()) {
|
||||
$this->showForm(_('There was a problem with your session token. '.
|
||||
|
@ -123,12 +124,10 @@ class RegisterAction extends Action
|
|||
$location = $this->trimmed('location');
|
||||
|
||||
// We don't trim these... whitespace is OK in a password!
|
||||
|
||||
$password = $this->arg('password');
|
||||
$confirm = $this->arg('confirm');
|
||||
|
||||
// invitation code, if any
|
||||
|
||||
$code = $this->trimmed('code');
|
||||
|
||||
if ($code) {
|
||||
|
@ -141,7 +140,6 @@ class RegisterAction extends Action
|
|||
}
|
||||
|
||||
// Input scrubbing
|
||||
|
||||
$nickname = common_canonical_nickname($nickname);
|
||||
$email = common_canonical_email($email);
|
||||
|
||||
|
@ -204,6 +202,9 @@ class RegisterAction extends Action
|
|||
common_debug('Adding rememberme cookie for ' . $nickname);
|
||||
common_rememberme($user);
|
||||
}
|
||||
|
||||
Event::handle('EndRegistrationTry', array($this));
|
||||
|
||||
// Re-init language env in case it changed (not yet, but soon)
|
||||
common_init_language();
|
||||
$this->showSuccess();
|
||||
|
@ -211,6 +212,7 @@ class RegisterAction extends Action
|
|||
$this->showForm(_('Invalid username or password.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given nickname already exist?
|
||||
|
@ -250,8 +252,10 @@ class RegisterAction extends Action
|
|||
|
||||
// overrrided to add entry-title class
|
||||
function showPageTitle() {
|
||||
if (Event::handle('StartShowPageTitle', array($this))) {
|
||||
$this->element('h1', array('class' => 'entry-title'), $this->title());
|
||||
}
|
||||
}
|
||||
|
||||
// overrided to add hentry, and content-inner class
|
||||
function showContentBlock()
|
||||
|
@ -363,6 +367,7 @@ class RegisterAction extends Action
|
|||
}
|
||||
|
||||
$this->elementStart('ul', 'form_data');
|
||||
if (Event::handle('StartRegistrationFormData', array($this))) {
|
||||
$this->elementStart('li');
|
||||
$this->input('nickname', _('Nickname'), $this->trimmed('nickname'),
|
||||
_('1-64 lowercase letters or numbers, '.
|
||||
|
@ -410,6 +415,7 @@ class RegisterAction extends Action
|
|||
_('Where you are, like "City, '.
|
||||
'State (or Region), Country"'));
|
||||
$this->elementEnd('li');
|
||||
Event::handle('EndRegistrationFormData', array($this));
|
||||
$this->elementStart('li', array('id' => 'settings_rememberme'));
|
||||
$this->checkbox('rememberme', _('Remember me'),
|
||||
$this->boolean('rememberme'),
|
||||
|
@ -434,6 +440,7 @@ class RegisterAction extends Action
|
|||
'email address, IM address, and phone number.'));
|
||||
$this->elementEnd('label');
|
||||
$this->elementEnd('li');
|
||||
}
|
||||
$this->elementEnd('ul');
|
||||
$this->submit('submit', _('Register'));
|
||||
$this->elementEnd('fieldset');
|
||||
|
@ -515,3 +522,4 @@ class RegisterAction extends Action
|
|||
$nav->show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user