1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Подтверждения при смене емайл адреса в профиле

This commit is contained in:
Mzhelskiy Maxim 2012-07-27 21:29:10 +04:00
parent 7a6039b21c
commit 3fbb862e83
19 changed files with 368 additions and 3 deletions

View file

@ -84,6 +84,9 @@ class ActionProfile extends Action {
$this->AddEventPreg('/^.+$/i','/^friends/i','/^(page([1-9]\d{0,5}))?$/i','EventFriends');
$this->AddEventPreg('/^.+$/i','/^stream/i','/^$/i','EventStream');
$this->AddEventPreg('/^changemail$/i','/^confirm-from/i','/^\w{32}$/i','EventChangemailConfirmFrom');
$this->AddEventPreg('/^changemail$/i','/^confirm-to/i','/^\w{32}$/i','EventChangemailConfirmTo');
}
/**********************************************************************************
@ -1197,6 +1200,59 @@ class ActionProfile extends Action {
return;
}
}
/**
* Обработка подтверждения старого емайла при его смене
*/
public function EventChangemailConfirmFrom() {
if (!($oChangemail=$this->User_GetUserChangemailByCodeFrom($this->GetParamEventMatch(1,0)))) {
return parent::EventNotFound();
}
if ($oChangemail->getConfirmFrom() or strtotime($oChangemail->getDateExpired())<time()) {
return parent::EventNotFound();
}
$oChangemail->setConfirmFrom(1);
$this->User_UpdateUserChangemail($oChangemail);
/**
* Отправляем уведомление
*/
$oUser=$this->User_GetUserById($oChangemail->getUserId());
$this->Notify_Send($oChangemail->getMailTo(),
'notify.user_changemail_to.tpl',
$this->Lang_Get('notify_subject_user_changemail'),
array(
'oUser' => $oUser,
'oChangemail' => $oChangemail,
));
$this->Viewer_Assign('sText',$this->Lang_Get('settings_profile_mail_change_to_notice'));
$this->SetTemplateAction('changemail_confirm');
}
/**
* Обработка подтверждения нового емайла при смене старого
*/
public function EventChangemailConfirmTo() {
if (!($oChangemail=$this->User_GetUserChangemailByCodeTo($this->GetParamEventMatch(1,0)))) {
return parent::EventNotFound();
}
if (!$oChangemail->getConfirmFrom() or $oChangemail->getConfirmTo() or strtotime($oChangemail->getDateExpired())<time()) {
return parent::EventNotFound();
}
$oChangemail->setConfirmTo(1);
$oChangemail->setDateUsed(date("Y-m-d H:i:s"));
$this->User_UpdateUserChangemail($oChangemail);
$oUser=$this->User_GetUserById($oChangemail->getUserId());
$oUser->setMail($oChangemail->getMailTo());
$this->User_Update($oUser);
$this->Viewer_Assign('sText',$this->Lang_Get('settings_profile_mail_change_ok',array('mail'=>htmlspecialchars($oChangemail->getMailTo()))));
$this->SetTemplateAction('changemail_confirm');
}
/**
* Выполняется при завершении работы экшена
*/

View file

@ -465,8 +465,6 @@ class ActionSettings extends Action {
if ($oUserMail=$this->User_GetUserByMail(getRequest('mail')) and $oUserMail->getId()!=$this->oUserCurrent->getId()) {
$this->Message_AddError($this->Lang_Get('settings_profile_mail_error_used'),$this->Lang_Get('error'));
$bError=true;
} else {
$this->oUserCurrent->setMail(getRequest('mail'));
}
} else {
$this->Message_AddError($this->Lang_Get('settings_profile_mail_error'),$this->Lang_Get('error'));
@ -507,6 +505,15 @@ class ActionSettings extends Action {
if (!$bError) {
if ($this->User_Update($this->oUserCurrent)) {
$this->Message_AddNoticeSingle($this->Lang_Get('settings_account_submit_ok'));
/**
* Подтверждение смены емайла
*/
if (getRequest('mail') and getRequest('mail')!=$this->oUserCurrent->getMail()) {
if ($this->User_MakeUserChangemail($this->oUserCurrent,getRequest('mail'))) {
$this->Message_AddNotice($this->Lang_Get('settings_profile_mail_change_from_notice'));
}
}
$this->Hook_Run('settings_account_save_after', array('oUser'=>$this->oUserCurrent));
} else {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));

View file

@ -1436,5 +1436,74 @@ class ModuleUser extends Module {
}
return $data;
}
/**
* Добавляет запись о смене емайла
*
* @param ModuleUser_EntityChangemail $oChangemail Объект смены емайла
* @return bool|ModuleUser_EntityChangemail
*/
public function AddUserChangemail($oChangemail) {
if ($sId=$this->oMapper->AddUserChangemail($oChangemail)) {
$oChangemail->setId($sId);
return $oChangemail;
}
return false;
}
/**
* Обновляет запись о смене емайла
*
* @param ModuleUser_EntityChangemail $oChangemail Объект смены емайла
* @return int
*/
public function UpdateUserChangemail($oChangemail) {
return $this->oMapper->UpdateUserChangemail($oChangemail);
}
/**
* Возвращает объект смены емайла по коду подтверждения
*
* @param string $sCode Код подтверждения
* @return ModuleUser_EntityChangemail|null
*/
public function GetUserChangemailByCodeFrom($sCode) {
return $this->oMapper->GetUserChangemailByCodeFrom($sCode);
}
/**
* Возвращает объект смены емайла по коду подтверждения
*
* @param string $sCode Код подтверждения
* @return ModuleUser_EntityChangemail|null
*/
public function GetUserChangemailByCodeTo($sCode) {
return $this->oMapper->GetUserChangemailByCodeTo($sCode);
}
/**
* @param ModuleUser_EntityUser $oUser Объект пользователя
* @param string $sMailNew Новый емайл
* @return bool|ModuleUser_EntityChangemail
*/
public function MakeUserChangemail($oUser,$sMailNew) {
$oChangemail=Engine::GetEntity('ModuleUser_EntityChangemail');
$oChangemail->setUserId($oUser->getId());
$oChangemail->setDateAdd(date("Y-m-d H:i:s"));
$oChangemail->setDateExpired(date("Y-m-d H:i:s",time()+3*24*60*60)); // 3 дня для смены емайла
$oChangemail->setMailFrom($oUser->getMail());
$oChangemail->setMailTo($sMailNew);
$oChangemail->setCodeFrom(func_generator(32));
$oChangemail->setCodeTo(func_generator(32));
if ($this->AddUserChangemail($oChangemail)) {
/**
* Отправляем уведомление
*/
$this->Notify_Send($oUser,
'notify.user_changemail_from.tpl',
$this->Lang_Get('notify_subject_user_changemail'),
array(
'oUser' => $oUser,
'oChangemail' => $oChangemail,
));
return $oChangemail;
}
return false;
}
}
?>

View file

@ -0,0 +1,27 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Сущность смены емайла пользователем
*
* @package modules.user
* @since 1.0
*/
class ModuleUser_EntityChangemail extends Entity {
}
?>

View file

@ -1076,6 +1076,61 @@ class ModuleUser_MapperUser extends Mapper {
return $this->oDb->query($sql,$oNote->getText(),
$oNote->getId());
}
/**
* Добавляет запись о смене емайла
*
* @param ModuleUser_EntityChangemail $oChangemail Объект смены емайла
* @return int|null
*/
public function AddUserChangemail($oChangemail) {
$sql = "INSERT INTO ".Config::Get('db.table.user_changemail')." SET ?a ";
if ($iId=$this->oDb->query($sql,$oChangemail->_getData())) {
return $iId;
}
return false;
}
/**
* Обновляет запись о смене емайла
*
* @param ModuleUser_EntityChangemail $oChangemail Объект смены емайла
* @return int
*/
public function UpdateUserChangemail($oChangemail) {
$sql = "UPDATE ".Config::Get('db.table.user_changemail')."
SET
date_used = ?,
confirm_from = ?d,
confirm_to = ?d
WHERE id = ?d
";
return $this->oDb->query($sql,$oChangemail->getDateUsed(),$oChangemail->getConfirmFrom(),$oChangemail->getConfirmTo(),$oChangemail->getId());
}
/**
* Возвращает объект смены емайла по коду подтверждения
*
* @param string $sCode Код подтверждения
* @return ModuleUser_EntityChangemail|null
*/
public function GetUserChangemailByCodeFrom($sCode) {
$sql = "SELECT * FROM ".Config::Get('db.table.user_changemail')." WHERE code_from = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sCode)) {
return Engine::GetEntity('ModuleUser_EntityChangemail',$aRow);
}
return null;
}
/**
* Возвращает объект смены емайла по коду подтверждения
*
* @param string $sCode Код подтверждения
* @return ModuleUser_EntityChangemail|null
*/
public function GetUserChangemailByCodeTo($sCode) {
$sql = "SELECT * FROM ".Config::Get('db.table.user_changemail')." WHERE code_to = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sCode)) {
return Engine::GetEntity('ModuleUser_EntityChangemail',$aRow);
}
return null;
}
/**
* Возвращает список пользователей по фильтру
*

View file

@ -355,6 +355,7 @@ $config['db']['table']['geo_country'] = '___db.table.prefix___geo_countr
$config['db']['table']['geo_region'] = '___db.table.prefix___geo_region';
$config['db']['table']['geo_city'] = '___db.table.prefix___geo_city';
$config['db']['table']['geo_target'] = '___db.table.prefix___geo_target';
$config['db']['table']['user_changemail'] = '___db.table.prefix___user_changemail';
$config['db']['tables']['engine'] = 'InnoDB'; // InnoDB или MyISAM
/**

View file

@ -1 +1,33 @@
ALTER TABLE `prefix_user` ADD `user_settings_timezone` VARCHAR( 6 ) NULL DEFAULT NULL AFTER `user_settings_notice_new_friend`;
ALTER TABLE `prefix_user` ADD `user_settings_timezone` VARCHAR( 6 ) NULL DEFAULT NULL AFTER `user_settings_notice_new_friend`;
--
-- Структура таблицы `prefix_user_changemail`
--
CREATE TABLE IF NOT EXISTS `prefix_user_changemail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL,
`date_add` datetime NOT NULL,
`date_used` datetime DEFAULT NULL,
`date_expired` datetime NOT NULL,
`mail_from` varchar(50) NOT NULL,
`mail_to` varchar(50) NOT NULL,
`code_from` varchar(32) NOT NULL,
`code_to` varchar(32) NOT NULL,
`confirm_from` tinyint(1) NOT NULL DEFAULT '0',
`confirm_to` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `code_from` (`code_from`),
KEY `code_to` (`code_to`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Ограничения внешнего ключа сохраненных таблиц
--
--
-- Ограничения внешнего ключа таблицы `prefix_user_changemail`
--
ALTER TABLE `prefix_user_changemail`
ADD CONSTRAINT `prefix_user_changemail_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `prefix_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -624,6 +624,9 @@ return array(
'settings_profile_mail_error' => 'Wrong e-mail format',
'settings_profile_mail_error_used' => 'This e-mail is already in use',
'settings_profile_mail_notice' => 'Your real e-mail address fo notifications.',
'settings_profile_mail_change_from_notice' => 'On your old e-mail sent a confirmation email for changing',
'settings_profile_mail_change_to_notice' => 'Thank you! <br/> on your new email address sent another confirmation.',
'settings_profile_mail_change_ok' => 'Your email is changed to <b>%%mail%%</b>',
'settings_profile_sex' => 'Gender',
'settings_profile_sex_man' => 'male',
'settings_profile_sex_woman' => 'female',
@ -972,6 +975,7 @@ return array(
'notify_subject_wall_reply' => 'You\'ve recieved reply to your post on wall',
'notify_subject_wall_new' => 'You\'ve recieved new post on your wall',
'notify_subject_reactvation' => 'Re-activation request',
'notify_subject_user_changemail' => 'Confirmation of change email',
/**
* Админка
*/

View file

@ -626,6 +626,9 @@ return array(
'settings_profile_mail_error' => 'Неверный формат e-mail',
'settings_profile_mail_error_used' => 'Этот емайл уже занят',
'settings_profile_mail_notice' => 'Ваш реальный почтовый адрес, на него будут приходить уведомления',
'settings_profile_mail_change_from_notice' => 'На вашу старую почту отправлено подтверждение для смены емайла',
'settings_profile_mail_change_to_notice' => 'Спасибо! <br/> На ваш новый емайл адрес отправлено еще одно подтверждение.',
'settings_profile_mail_change_ok' => 'Ваш емайл изменен на <b>%%mail%%</b>',
'settings_profile_sex' => 'Пол',
'settings_profile_sex_man' => 'мужской',
'settings_profile_sex_woman' => 'женский',
@ -974,6 +977,7 @@ return array(
'notify_subject_wall_reply' => 'Ответ на ваше сообщение на стене',
'notify_subject_wall_new' => 'Новое сообщение на вашей стене',
'notify_subject_reactvation' => 'Повторный запрос активации',
'notify_subject_user_changemail' => 'Подтверждение смены емайла',
/**
* Админка
*/

View file

@ -0,0 +1,11 @@
{assign var="noSidebar" value=true}
{include file='header.tpl' noShowSystemMessage=true}
<div class="content-error">
<p>{$sText}</p>
<br />
</div>
{include file='footer.tpl'}

View file

@ -0,0 +1,11 @@
You have sent a request to change user email <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> on site <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Old email: <b>{$oChangemail->getMailFrom()}</b><br/>
New email: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
To confirm the email change, please click here:
<a href="{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/">{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/</a>
<br/><br/>
Best regards, site administration <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
You have sent a request to change user email <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> on site <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Old email: <b>{$oChangemail->getMailFrom()}</b><br/>
New email: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
To confirm the email change, please click here:
<a href="{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/">{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/</a>
<br/><br/>
Best regards, site administration <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
Вами отправлен запрос на смену емайл адреса пользователя <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> на сайте <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Старый емайл: <b>{$oChangemail->getMailFrom()}</b><br/>
Новый емайл: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
Для подтверждения смены емайла пройдите по ссылке:
<a href="{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/">{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/</a>
<br/><br/>
С уважением, администрация сайта <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
Вами отправлен запрос на смену емайл адреса пользователя <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> на сайте <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Старый емайл: <b>{$oChangemail->getMailFrom()}</b><br/>
Новый емайл: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
Для подтверждения смены емайла пройдите по ссылке:
<a href="{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/">{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/</a>
<br/><br/>
С уважением, администрация сайта <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
{assign var="noSidebar" value=true}
{include file='header.tpl' noShowSystemMessage=true}
<div class="content-error">
<p>{$sText}</p>
<br />
</div>
{include file='footer.tpl'}

View file

@ -0,0 +1,11 @@
You have sent a request to change user email <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> on site <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Old email: <b>{$oChangemail->getMailFrom()}</b><br/>
New email: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
To confirm the email change, please click here:
<a href="{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/">{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/</a>
<br/><br/>
Best regards, site administration <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
You have sent a request to change user email <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> on site <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Old email: <b>{$oChangemail->getMailFrom()}</b><br/>
New email: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
To confirm the email change, please click here:
<a href="{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/">{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/</a>
<br/><br/>
Best regards, site administration <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
Вами отправлен запрос на смену емайл адреса пользователя <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> на сайте <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Старый емайл: <b>{$oChangemail->getMailFrom()}</b><br/>
Новый емайл: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
Для подтверждения смены емайла пройдите по ссылке:
<a href="{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/">{router page='profile'}changemail/confirm-from/{$oChangemail->getCodeFrom()}/</a>
<br/><br/>
С уважением, администрация сайта <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>

View file

@ -0,0 +1,11 @@
Вами отправлен запрос на смену емайл адреса пользователя <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a> на сайте <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>.<br/>
Старый емайл: <b>{$oChangemail->getMailFrom()}</b><br/>
Новый емайл: <b>{$oChangemail->getMailTo()}</b><br/>
<br/>
Для подтверждения смены емайла пройдите по ссылке:
<a href="{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/">{router page='profile'}changemail/confirm-to/{$oChangemail->getCodeTo()}/</a>
<br/><br/>
С уважением, администрация сайта <a href="{cfg name='path.root.web'}">{cfg name='view.name'}</a>