1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-01 05:55:02 +03:00
ifhub.club/application/classes/actions/ActionLogin.class.php

209 lines
6.5 KiB
PHP
Raw Normal View History

<?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
*
---------------------------------------------------------
*/
/**
* Обрабатывые авторизацию
*
* @package actions
* @since 1.0
2008-09-21 09:36:57 +03:00
*/
class ActionLogin extends Action {
/**
* Инициализация
*
*/
public function Init() {
/**
* Устанавливаем дефолтный евент
*/
2008-09-21 09:36:57 +03:00
$this->SetDefaultEvent('index');
/**
* Отключаем отображение статистики выполнения
*/
Router::SetIsShowStats(false);
2008-09-21 09:36:57 +03:00
}
/**
* Регистрируем евенты
*
*/
protected function RegisterEvent() {
$this->AddEvent('index','EventLogin');
$this->AddEvent('exit','EventExit');
2014-07-14 19:42:50 +03:00
$this->AddEvent('reset','EventReset');
2012-04-05 13:15:33 +03:00
$this->AddEvent('ajax-login','EventAjaxLogin');
2014-07-14 19:42:50 +03:00
$this->AddEvent('ajax-reset','EventAjaxReset');
2008-09-21 09:36:57 +03:00
}
/**
2012-04-05 13:15:33 +03:00
* Ajax авторизация
2008-09-21 09:36:57 +03:00
*/
2012-04-05 13:15:33 +03:00
protected function EventAjaxLogin() {
/**
* Устанвливаем формат Ajax ответа
*/
2012-04-05 13:15:33 +03:00
$this->Viewer_SetResponseAjax('json');
/**
* Логин и пароль являются строками?
*/
2012-04-05 13:15:33 +03:00
if (!is_string(getRequest('login')) or !is_string(getRequest('password'))) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));
return;
2012-02-09 02:23:13 +02:00
}
2008-09-21 09:36:57 +03:00
/**
2012-04-05 13:15:33 +03:00
* Проверяем есть ли такой юзер по логину
2008-09-21 09:36:57 +03:00
*/
2012-04-05 13:15:33 +03:00
if ((func_check(getRequest('login'),'mail') and $oUser=$this->User_GetUserByMail(getRequest('login'))) or $oUser=$this->User_GetUserByLogin(getRequest('login'))) {
2013-10-23 08:18:24 +03:00
/**
* Выбираем сценарий валидации
*/
$oUser->_setValidateScenario('signIn');
/**
* Заполняем поля (данные)
*/
$oUser->setCaptcha(getRequestStr('captcha'));
/**
* Запускаем валидацию
*/
if ($oUser->_Validate()) {
/**
* Сверяем хеши паролей и проверяем активен ли юзер
*/
2013-10-23 08:18:24 +03:00
if ($oUser->getPassword()==func_encrypt(getRequest('password'))) {
if (!$oUser->getActivate()) {
2014-07-14 19:42:50 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('auth.notices.not_activated', array('reactivation_path' => Router::GetPath('registration') . 'reactivation')));
2013-10-23 08:18:24 +03:00
return;
}
$bRemember=getRequest('remember',false) ? true : false;
2014-01-26 15:56:00 +02:00
/**
* Убиваем каптчу
*/
unset($_SESSION['captcha_keystring_user_auth']);
2013-10-23 08:18:24 +03:00
/**
* Авторизуем
*/
$this->User_Authorization($oUser,$bRemember);
/**
* Определяем редирект
*/
$sUrl=Config::Get('module.user.redirect_after_login');
if (getRequestStr('return-path')) {
$sUrl=getRequestStr('return-path');
}
2014-05-16 18:38:42 +03:00
$this->Viewer_AssignAjax('sUrlRedirect',$sUrl ? $sUrl : Router::GetPath('/'));
2013-10-23 08:18:24 +03:00
return;
}
} else {
/**
* Получаем ошибки
*/
$this->Viewer_AssignAjax('aErrors',$oUser->_getValidateErrors());
}
2012-06-13 11:46:40 +03:00
2012-04-05 13:15:33 +03:00
}
2014-07-14 19:42:50 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('auth.login.notices.error_login'));
2012-06-16 02:43:47 +03:00
}
/**
2012-04-05 13:15:33 +03:00
* Обрабатываем процесс залогинивания
* По факту только отображение шаблона, дальше вступает в дело Ajax
2012-04-05 13:15:33 +03:00
*
*/
protected function EventLogin() {
/**
* Если уже авторизирован
*/
if($this->User_GetUserCurrent()) {
2014-05-16 18:38:42 +03:00
Router::Location(Router::GetPath('/'));
2008-09-21 09:36:57 +03:00
}
2014-07-14 19:42:50 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('auth.login.title'));
2008-09-21 09:36:57 +03:00
}
/**
* Обрабатываем процесс разлогинивания
*
*/
protected function EventExit() {
$this->Security_ValidateSendForm();
2008-09-21 09:36:57 +03:00
$this->User_Logout();
2014-05-16 18:38:42 +03:00
Router::Location(Router::GetPath('/'));
2008-09-21 09:36:57 +03:00
}
/**
* Ajax запрос на восстановление пароля
*/
2014-07-14 19:42:50 +03:00
protected function EventAjaxReset() {
/**
* Устанвливаем формат Ajax ответа
*/
$this->Viewer_SetResponseAjax('json');
/**
* Пользователь с таким емайлом существует?
*/
if ((func_check(getRequestStr('mail'),'mail') and $oUser=$this->User_GetUserByMail(getRequestStr('mail')))) {
/**
* Формируем и отправляем ссылку на смену пароля
*/
$oReminder=Engine::GetEntity('User_Reminder');
$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)) {
2014-07-14 19:42:50 +03:00
$this->Message_AddNotice($this->Lang_Get('auth.notices.success_send_password'));
$this->Notify_SendReminderCode($oUser,$oReminder);
return;
}
}
2014-07-14 19:42:50 +03:00
$this->Message_AddError($this->Lang_Get('auth.notices.error_bad_email'),$this->Lang_Get('error'));
}
/**
* Обработка напоминания пароля, подтверждение смены пароля
*
*/
2014-07-14 19:42:50 +03:00
protected function EventReset() {
/**
* Устанавливаем title страницы
*/
2014-07-14 19:42:50 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('auth.reset.title'));
/**
* Проверка кода на восстановление пароля и генерация нового пароля
*/
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));
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);
2014-07-14 19:42:50 +03:00
$this->SetTemplateAction('reset_confirm');
return ;
}
}
}
2014-07-14 19:42:50 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('auth.reset.alerts.error_bad_code'), $this->Lang_Get('error'));
return Router::Action('error');
}
}
}