2009-05-10 10:50:39 +03:00
|
|
|
|
<?php
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/*-------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатывые авторизацию
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class ActionLogin extends Action {
|
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function Init() {
|
|
|
|
|
$this->SetDefaultEvent('index');
|
2009-02-07 15:04:44 +02:00
|
|
|
|
Router::SetIsShowStats(false);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Регистрируем евенты
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent() {
|
|
|
|
|
$this->AddEvent('index','EventLogin');
|
|
|
|
|
$this->AddEvent('exit','EventExit');
|
2008-11-29 12:50:49 +02:00
|
|
|
|
$this->AddEvent('reminder','EventReminder');
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем процесс залогинивания
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventLogin() {
|
|
|
|
|
/**
|
|
|
|
|
* Если нажали кнопку "Войти"
|
|
|
|
|
*/
|
2010-03-06 18:11:27 +02:00
|
|
|
|
if (isPost('submit_login') and is_string(getRequest('login')) and is_string(getRequest('password'))) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяем есть ли такой юзер по логину
|
|
|
|
|
*/
|
2008-09-21 14:34:12 +03:00
|
|
|
|
if ((func_check(getRequest('login'),'mail') and $oUser=$this->User_GetUserByMail(getRequest('login'))) or $oUser=$this->User_GetUserByLogin(getRequest('login'))) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Сверяем хеши паролей и проверяем активен ли юзер
|
|
|
|
|
*/
|
|
|
|
|
if ($oUser->getPassword()==func_encrypt(getRequest('password')) and $oUser->getActivate()) {
|
2009-02-04 23:05:21 +02:00
|
|
|
|
$bRemember=getRequest('remember',false) ? true : false;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Авторизуем
|
|
|
|
|
*/
|
2009-02-04 23:05:21 +02:00
|
|
|
|
$this->User_Authorization($oUser,$bRemember);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Перенаправляем на страницу с которой произошла авторизация
|
|
|
|
|
*/
|
2008-09-28 22:39:40 +03:00
|
|
|
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
|
|
$sBackUrl=$_SERVER['HTTP_REFERER'];
|
2009-08-20 10:43:06 +03:00
|
|
|
|
if (strpos($sBackUrl,Router::GetPath('login'))===false) {
|
2009-09-09 20:49:00 +03:00
|
|
|
|
Router::Location($sBackUrl);
|
2008-09-28 22:39:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-09 20:49:00 +03:00
|
|
|
|
Router::Location(Config::Get('path.root.web').'/');
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->Viewer_Assign('bLoginError',true);
|
|
|
|
|
}
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('login'));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем процесс разлогинивания
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventExit() {
|
2009-05-21 17:50:55 +03:00
|
|
|
|
$this->Security_ValidateSendForm();
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$this->User_Logout();
|
|
|
|
|
$this->Viewer_Assign('bRefreshToHome',true);
|
|
|
|
|
}
|
2008-11-29 12:50:49 +02:00
|
|
|
|
/**
|
|
|
|
|
* Обработка напоминания пароля
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventReminder() {
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('password_reminder'));
|
2008-11-29 12:50:49 +02:00
|
|
|
|
|
|
|
|
|
if ($this->GetParam(0)=='send') {
|
|
|
|
|
$this->SetTemplateAction('reminder_send');
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Проверка кода на восстановление пароля и генерация нового пароля
|
|
|
|
|
*/
|
|
|
|
|
if (func_check($this->GetParam(0),'md5')) {
|
|
|
|
|
if ($oReminder=$this->User_GetReminderByCode($this->GetParam(0))) {
|
|
|
|
|
if (!$oReminder->getIsUsed() and strtotime($oReminder->getDateExpire())>time() and $oUser=$this->User_GetUserById($oReminder->getUserId())) {
|
|
|
|
|
$sNewPassword=func_generator(7);
|
2009-07-03 21:15:47 +03:00
|
|
|
|
$oUser->setPassword(func_encrypt($sNewPassword));
|
2008-11-29 12:50:49 +02:00
|
|
|
|
if ($this->User_Update($oUser)) {
|
|
|
|
|
$oReminder->setDateUsed(date("Y-m-d H:i:s"));
|
|
|
|
|
$oReminder->setIsUsed(1);
|
|
|
|
|
$this->User_UpdateReminder($oReminder);
|
|
|
|
|
$this->Notify_SendReminderPassword($oUser,$sNewPassword);
|
|
|
|
|
$this->SetTemplateAction('reminder_confirm');
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('password_reminder_bad_code'),$this->Lang_Get('error'));
|
2008-11-29 12:50:49 +02:00
|
|
|
|
return Router::Action('error');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем запрос на смену пароля
|
|
|
|
|
*/
|
2009-10-17 13:06:36 +03:00
|
|
|
|
if (isPost('submit_reminder')) {
|
2008-11-29 12:50:49 +02:00
|
|
|
|
if ((func_check(getRequest('mail'),'mail') and $oUser=$this->User_GetUserByMail(getRequest('mail')))) {
|
|
|
|
|
/**
|
|
|
|
|
* Формируем и отправляем ссылку на смену пароля
|
|
|
|
|
*/
|
2009-09-08 15:02:51 +03:00
|
|
|
|
$oReminder=Engine::GetEntity('User_Reminder');
|
2008-11-29 12:50:49 +02:00
|
|
|
|
$oReminder->setCode(func_generator(32));
|
|
|
|
|
$oReminder->setDateAdd(date("Y-m-d H:i:s"));
|
|
|
|
|
$oReminder->setDateExpire(date("Y-m-d H:i:s",time()+60*60*24*7));
|
|
|
|
|
$oReminder->setDateUsed(null);
|
|
|
|
|
$oReminder->setIsUsed(0);
|
|
|
|
|
$oReminder->setUserId($oUser->getId());
|
|
|
|
|
if ($this->User_AddReminder($oReminder)) {
|
|
|
|
|
$this->Notify_SendReminderCode($oUser,$oReminder);
|
2009-09-09 20:49:00 +03:00
|
|
|
|
Router::Location(Router::GetPath('login').'reminder/send/');
|
2008-11-29 12:50:49 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-04-06 19:03:05 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('password_reminder_bad_email'),$this->Lang_Get('error'));
|
2008-11-29 12:50:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
?>
|