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