HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/irk2.ru/classes/actions/ActionLogin.class.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
*
---------------------------------------------------------
*/

/**
 * Обрабатывые авторизацию
 *
 */
class ActionLogin extends Action {
	/**
	 * Инициализация
	 *
	 */
	public function Init() {		
		$this->SetDefaultEvent('index');
		Router::SetIsShowStats(false);
	}
	/**
	 * Регистрируем евенты
	 *
	 */
	protected function RegisterEvent() {		
		$this->AddEvent('index','EventLogin');	
		$this->AddEvent('exit','EventExit');	
		$this->AddEvent('reminder','EventReminder');	
	}
	/**
	 * Обрабатываем процесс залогинивания
	 *
	 */
	protected function EventLogin() {	
		/**
		 * Если нажали кнопку "Войти"
		 */
		if (isset($_REQUEST['submit_login'])) {
			/**
			 * Проверяем есть ли такой юзер по логину
			 */
			if ((func_check(getRequest('login'),'mail') and $oUser=$this->User_GetUserByMail(getRequest('login')))  or  $oUser=$this->User_GetUserByLogin(getRequest('login'))) {	
				/**
				 * Сверяем хеши паролей и проверяем активен ли юзер
				 */
				if ($oUser->getPassword()==func_encrypt(getRequest('password')) and $oUser->getActivate()) {
					$bRemember=getRequest('remember',false) ? true : false;
					/**
					 * Авторизуем
					 */
					$this->User_Authorization($oUser,$bRemember);	
					/**
					 * Перенаправляем на страницу с которой произошла авторизация
					 */
					if (isset($_SERVER['HTTP_REFERER'])) {
						$sBackUrl=$_SERVER['HTTP_REFERER'];
						if (strpos($sBackUrl,DIR_WEB_ROOT.'/login')===false) {
							func_header_location($sBackUrl);
						}
					}					 
					func_header_location(DIR_WEB_ROOT.'/');
				}
			}			
			$this->Viewer_Assign('bLoginError',true);
		}
		$this->Viewer_AddHtmlTitle($this->Lang_Get('login'));
	}
	/**
	 * Обрабатываем процесс разлогинивания
	 *
	 */
	protected function EventExit() {
		$this->User_Logout();
		$this->Viewer_Assign('bRefreshToHome',true);
	}
	/**
	 * Обработка напоминания пароля
	 *
	 */
	protected function EventReminder() {
		$this->Viewer_AddHtmlTitle($this->Lang_Get('password_reminder'));
		
		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);
					$oUser->setPassword(md5($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);
						$this->SetTemplateAction('reminder_confirm');
						return ;
					}					
				}
			}
			$this->Message_AddErrorSingle($this->Lang_Get('password_reminder_bad_code'),$this->Lang_Get('error'));
			return Router::Action('error');
		}
		/**
		 * Обрабатываем запрос на смену пароля
		 */
		if (isset($_REQUEST['submit_reminder'])) {
			if ((func_check(getRequest('mail'),'mail') and $oUser=$this->User_GetUserByMail(getRequest('mail')))) {	
				/**
				 * Формируем и отправляем ссылку на смену пароля
				 */
				$oReminder=new UserEntity_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)) {					
					$this->Notify_SendReminderCode($oUser,$oReminder);
					func_header_location(DIR_WEB_ROOT.'/login/reminder/send/');
				}
			} else {
				$this->Message_AddError('Пользователь с таким e-mail не найден','Ошибка');
			}
		}
	}
}
?>