Commit 994b20e5 authored by nkoth's avatar nkoth

[NEW] user_unique_email feature: blocking changing of email to email that has...

[NEW] user_unique_email feature: blocking changing of email to email that has been used by other users already (the part related to new user creation has already been committed earlier)
parent 5d49b131
......@@ -1681,7 +1681,7 @@ class TrackerLib extends TikiLib
$this->log($version, $itemId, $array['fieldId'], '?');
}
} elseif ($array['options_array'][0] == 'email') {
if (!empty($array['value']) && validate_email($array['value'])) {
if (!empty($array['value']) && validate_email($array['value']) && ($prefs['user_unique_email'] != 'y' || !$userlib->other_user_has_email($trackersync_user, $array['value']))) {
$old_value = $userlib->get_user_email($trackersync_user);
$userlib->change_user_email($trackersync_user, $array['value']);
}
......
......@@ -6285,7 +6285,7 @@ class UsersLib extends TikiLib
}
$smarty = TikiLib::lib('smarty');
$smarty->assign('errortype', 'login');
$smarty->assign('msg', tra('We were unable to create your account because this e-mail is already in use.'));
$smarty->assign('msg', tra('We were unable to create your account because this email is already in use.'));
$smarty->display('error.tpl');
die;
}
......@@ -6408,14 +6408,32 @@ class UsersLib extends TikiLib
$this->set_user_preference($user, 'language', $prefs['language']);
}
}
function change_user_email_only($user, $email)
{
global $prefs;
if ($prefs['user_unique_email'] == 'y' && $this->other_user_has_email($user, $email)) {
$smarty = TikiLib::lib('smarty');
$smarty->assign('errortype', 'login');
$smarty->assign('msg', tra('Email cannot be set because this email is already in use by another user.'));
$smarty->display('error.tpl');
die;
}
$query = 'update `users_users` set `email`=? where binary `login`=?';
$result = $this->query($query, array($email, $user));
}
function change_user_email($user, $email, $pass=null)
{
global $prefs;
if ($prefs['user_unique_email'] == 'y' && $this->other_user_has_email($user, $email)) {
$smarty = TikiLib::lib('smarty');
$smarty->assign('errortype', 'login');
$smarty->assign('msg', tra('Email cannot be set because this email is already in use by another user.'));
$smarty->display('error.tpl');
die;
}
// Need to change the email-address for notifications, too
$notificationlib = TikiLib::lib('notification');
$oldMail = $this->get_user_email($user);
......@@ -6543,6 +6561,14 @@ class UsersLib extends TikiLib
return $pass;
}
function other_user_has_email($user, $email)
{
$query = 'select `login` from `users_users` where upper(`email`)=? and `login`!=?';
$pass = $this->getOne($query, array(TikiLib::strtoupper($email), $user));
return $pass;
}
function is_due($user, $method=null)
{
global $prefs;
......@@ -6931,6 +6957,13 @@ class UsersLib extends TikiLib
}
if (isset($u['email'])) {
if ($prefs['user_unique_email'] == 'y' && $this->other_user_has_email($user, $email)) {
$smarty = TikiLib::lib('smarty');
$smarty->assign('errortype', 'login');
$smarty->assign('msg', tra('Email cannot be set because this email is already in use by another user.'));
$smarty->display('error.tpl');
die;
}
$q[] = '`email` = ?';
$bindvars[] = strip_tags($u['email']);
}
......
......@@ -71,7 +71,7 @@ if ($user == $prefs['login_autologin_user']) {
} elseif (!TikiLib::lib('user')->user_exists($uname)) {
$access->display_error('', tra('Permission denied'), "401");
die;
} elseif (!empty($email)) {
} elseif (!empty($email) && ($prefs['user_unique_email'] != 'y' || !TikiLib::lib('user')->other_user_has_email($uname, $email))) {
TikiLib::lib('user')->change_user_email($uname, $email);
}
if (!empty($realName)) {
......@@ -121,4 +121,4 @@ if ($user == $prefs['login_autologin_user']) {
$access->display_error('', tra('Permission denied'), "401");
die;
}
}
\ No newline at end of file
}
......@@ -45,7 +45,9 @@ if (isset($_REQUEST["localinfosubmit"])) {
$smarty->assign('msg', tra('Email is invalid'));
} else {
$tikilib->set_user_preference($user, 'socialnetworks_user_firstlogin', 'n');
$userlib->change_user_email($user, $_REQUEST["email"]);
if ($prefs['user_unique_email'] != 'y' || !$userlib->other_user_has_email($user, $_REQUEST['email'])) {
$userlib->change_user_email($user, $_REQUEST["email"]);
}
$userlib->change_login($user, $_REQUEST["name"]);
$user = $_REQUEST["name"];
$_SESSION[$user_cookie_site] = $user;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment