From 827d9a0b8d25cac9ae3c0cee015f387b11a46edd Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 8 Jul 2013 11:04:17 +0000 Subject: [PATCH] Make operator's email unique in the system --- src/messenger/webim/locales/en/properties | 1 + src/messenger/webim/locales/ru/properties | 1 + src/messenger/webim/operator/operator.php | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index c358f7bb..4bd33ea0 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -347,6 +347,7 @@ page_agent.cannot_modify=You are not allowed to change this person's profile. page_agent.clear_avatar=Remove avatar page_agent.create_new=You can create a new operator here. page_agent.error.duplicate_login=Please choose another login because an operator with that login is already registered in the system. +page_agent.error.duplicate_email=Please choose another email because an operator with that email is already registered in the system. page_agent.error.forbidden_create=You are not allowed to create operators. page_agent.error.wrong_login=Login should contain only latin characters, numbers and underscore symbol. page_agent.error.wrong_agent_code=Code should contain only latin characters, numbers and underscore symbol. diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index fe31e457..18611a7f 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -347,6 +347,7 @@ page_agent.cannot_modify= page_agent.clear_avatar=Удалить аватарку page_agent.create_new=Создание нового оператора. page_agent.error.duplicate_login=Выберите другой логин, т.к. оператор с введенным логином уже зарегистрирован в системе. +page_agent.error.duplicate_email=Выберите другой адрес электронной почты, т.к. оператор с введенным адресом уже зарегистрирован в системе. page_agent.error.forbidden_create=Вы не можете создавать операторов. page_agent.error.wrong_login=Логин должен состоять из латинских символов, цифр и знака подчеркивания. page_agent.error.wrong_agent_code=Код должен состоять из латинских символов, цифр и знака подчеркивания. diff --git a/src/messenger/webim/operator/operator.php b/src/messenger/webim/operator/operator.php index f20a78a7..7fe062da 100644 --- a/src/messenger/webim/operator/operator.php +++ b/src/messenger/webim/operator/operator.php @@ -71,6 +71,17 @@ if ((isset($_POST['login']) || !is_capable(CAN_ADMINISTRATE, $operator)) && isse ($opId && $existing_operator && $opId != $existing_operator['operatorid'])) $errors[] = getlocal("page_agent.error.duplicate_login"); + // Check if operator with specified email already exists in the database + $existing_operator = operator_by_email($email); + if ( + // Create operator with email already in database + (!$opId && $existing_operator) || + // Update operator email to existing one + ($opId && $existing_operator && $opId != $existing_operator['operatorid']) + ) { + $errors[] = getlocal("page_agent.error.duplicate_email"); + } + $canmodify = ($opId == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator)) || is_capable(CAN_ADMINISTRATE, $operator); if (!$canmodify) {