From 25481da931ae564320d2d2cc0f4735c8b058a161 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 14 Jan 2012 10:50:47 +0000 Subject: feature:2517 ability to change username. admins can change usernames, users are notified by mail git-svn-id: http://piwigo.org/svn/trunk@12882 68402e56-0260-453c-a942-63ccdbb3a9ee --- profile.php | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'profile.php') diff --git a/profile.php b/profile.php index acdf9822b..9e1820cef 100644 --- a/profile.php +++ b/profile.php @@ -104,6 +104,7 @@ function save_profile_from_post($userdata, &$errors) if ($special_user) { unset( + $_POST['username'], $_POST['mail_address'], $_POST['password'], $_POST['use_new_pwd'], @@ -114,6 +115,11 @@ function save_profile_from_post($userdata, &$errors) $_POST['theme'] = get_default_theme(); $_POST['language'] = get_default_language(); } + + if (!defined('IN_ADMIN')) + { + unset($_POST['username']); + } if ($conf['allow_user_customization'] or defined('IN_ADMIN')) { @@ -196,12 +202,44 @@ function save_profile_from_post($userdata, &$errors) { array_push($fields, $conf['user_fields']['password']); // password is encrpyted with function $conf['pass_convert'] - $data{$conf['user_fields']['password']} = - $conf['pass_convert']($_POST['use_new_pwd']); + $data{$conf['user_fields']['password']} = $conf['pass_convert']($_POST['use_new_pwd']); + } + + // username is updated only if allowed + if (!empty($_POST['username'])) + { + array_push($fields, $conf['user_fields']['username']); + $data{$conf['user_fields']['username']} = $_POST['username']; + + // send email to the user + if ($_POST['username'] != $userdata['username']) + { + include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); + switch_lang_to($userdata['language']); + + $keyargs_content = array( + get_l10n_args('Hello', ''), + get_l10n_args('Your username has been successfully changed to : %s', $_POST['username']), + ); + + pwg_mail( + $_POST['mail_address'], + array( + 'subject' => '['.$conf['gallery_title'].'] '.l10n('Username modification'), + 'content' => l10n_args($keyargs_content), + 'content_format' => 'text/plain', + ) + ); + + switch_lang_back(); + } } + mass_updates(USERS_TABLE, - array('primary' => array($conf['user_fields']['id']), - 'update' => $fields), + array( + 'primary' => array($conf['user_fields']['id']), + 'update' => $fields + ), array($data)); } -- cgit v1.2.3