X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=actions%2Fprofilesettings.php;h=a8ae2c97a484477349b5d114714e6a02d44a1a5d;hb=82c05d389ab0a0bb64a339d0cf3547d3c6ada3ae;hp=ae060dd9086e50f82fd3a2704a130998605be724;hpb=1a15570339fa7ae5e33a98a7fe6a8645e3d3af72;p=quix0rs-gnu-social.git diff --git a/actions/profilesettings.php b/actions/profilesettings.php index ae060dd908..a8ae2c97a4 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -1,52 +1,56 @@ . */ if (!defined('LACONICA')) { exit(1); } +require_once(INSTALLDIR.'/lib/settingsaction.php'); + class ProfilesettingsAction extends SettingsAction { - + function show_form($msg=NULL, $success=false) { + $user = common_current_user(); + $profile = $user->getProfile(); common_show_header(_t('Profile settings')); $this->settings_menu(); $this->message($msg, $success); common_element_start('form', array('method' => 'POST', 'id' => 'profilesettings', - 'action' => + 'action' => common_local_url('profilesettings'))); - common_input('nickname', _t('Nickname')); - common_input('fullname', _t('Full name')); - common_input('email', _t('Email address')); - common_input('homepage', _t('Homepage')); - common_input('bio', _t('Bio')); - common_input('location', _t('Location')); - common_element('input', array('name' => 'submit', - 'type' => 'submit', - 'id' => 'submit'), - _t('Login')); - common_element('input', array('name' => 'cancel', - 'type' => 'button', - 'id' => 'cancel'), - _t('Cancel')); + # too much common patterns here... abstractable? + common_input('nickname', _t('Nickname'), + ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname); + common_input('fullname', _t('Full name'), + ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); + common_input('email', _t('Email address'), + ($this->arg('email')) ? $this->arg('email') : $user->email); + common_input('homepage', _t('Homepage'), + ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage); + common_textarea('bio', _t('Bio'), + ($this->arg('bio')) ? $this->arg('bio') : $profile->bio); + common_input('location', _t('Location'), + ($this->arg('location')) ? $this->arg('location') : $profile->location); + common_submit('submit', _t('Save')); common_element_end('form'); common_show_footer(); } - + function handle_post() { $nickname = $this->arg('nickname'); $fullname = $this->arg('fullname'); @@ -57,31 +61,50 @@ class ProfilesettingsAction extends SettingsAction { $user = common_current_user(); assert(!is_null($user)); # should already be checked - + # FIXME: scrub input # FIXME: transaction! - + + $original = clone($user); + $user->nickname = $this->arg('nickname'); $user->email = $this->arg('email'); - - if (!$user->update()) { + + $val = $user->validate(); + if ($val !== TRUE) { + # XXX: better validation + $this->show_form(_t('Error saving user; invalid.')); + return; + } + + if (!$user->update($original)) { common_server_error(_t('Couldnt update user.')); return; } $profile = $user->getProfile(); + $orig_profile = clone($profile); + $profile->nickname = $user->nickname; $profile->fullname = $this->arg('fullname'); $profile->homepage = $this->arg('homepage'); $profile->bio = $this->arg('bio'); $profile->location = $this->arg('location'); + $profile->profileurl = common_profile_url($nickname); - if (!$profile->update()) { + $val = $profile->validate(); + if ($val !== TRUE) { + # XXX: some feedback here, please! + $this->show_form(_t('Error saving profile; invalid.')); + return; + } + + if (!$profile->update($orig_profile)) { common_server_error(_t('Couldnt save profile.')); return; } - + $this->show_form(_t('Settings saved.'), TRUE); } } \ No newline at end of file