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

301 lines
9.2 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
*
---------------------------------------------------------
*/
/**
* Обрабатывает регистрацию
*
*/
class ActionRegistration extends Action {
/**
* Инициализация
*
* @return unknown
*/
public function Init() {
/**
* Проверяем аторизован ли юзер
*/
if ($this->User_IsAuthorization()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('registration_is_authorization'),$this->Lang_Get('attention'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
/**
* Если включены инвайты то перенаправляем на страницу регистрации по инвайтам
*/
if (!$this->User_IsAuthorization() and Config::Get('general.reg.invite') and !in_array(Router::GetActionEvent(),array('invite','activate','confirm')) and !$this->CheckInviteRegister()) {
return Router::Action('registration','invite');
}
2008-09-21 09:36:57 +03:00
$this->SetDefaultEvent('index');
2009-04-11 14:50:42 +03:00
$this->Viewer_AddHtmlTitle($this->Lang_Get('registration'));
2008-09-21 09:36:57 +03:00
}
/**
* Регистрируем евенты
*
*/
protected function RegisterEvent() {
$this->AddEvent('index','EventIndex');
2008-09-21 09:36:57 +03:00
$this->AddEvent('confirm','EventConfirm');
$this->AddEvent('activate','EventActivate');
$this->AddEvent('invite','EventInvite');
2008-09-21 09:36:57 +03:00
}
/**********************************************************************************
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
**********************************************************************************
*/
/**
* Показывает страничку регистрации и обрабатывает её
*
* @return unknown
*/
protected function EventIndex() {
/**
* Если нажали кнопку "Зарегистрироваться"
*/
if (isPost('submit_register')) {
2008-09-21 09:36:57 +03:00
//Проверяем входные данные
$bError=false;
/**
* Проверка логина
*/
if (!func_check(getRequest('login'),'login',3,30)) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_login_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* Проверка мыла
*/
if (!func_check(getRequest('mail'),'mail')) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_mail_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* Проверка пароля
*/
if (!func_check(getRequest('password'),'password',5)) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_password_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
} elseif (getRequest('password')!=getRequest('password_confirm')) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_password_error_different'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* Проверка капчи(циферки с картинки)
*/
if (!isset($_SESSION['captcha_keystring']) or $_SESSION['captcha_keystring']!=strtolower(getRequest('captcha'))) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_captcha_error'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* А не занят ли логин?
*/
if ($this->User_GetUserByLogin(getRequest('login'))) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_login_error_used'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* А не занято ли мыло?
*/
if ($this->User_GetUserByMail(getRequest('mail'))) {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_mail_error_used'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
$bError=true;
}
/**
* Если всё то пробуем зарегить
*/
if (!$bError) {
/**
* Создаем юзера
*/
$oUser=Engine::GetEntity('User');
2008-09-21 09:36:57 +03:00
$oUser->setLogin(getRequest('login'));
$oUser->setMail(getRequest('mail'));
$oUser->setPassword(func_encrypt(getRequest('password')));
$oUser->setDateRegister(date("Y-m-d H:i:s"));
$oUser->setIpRegister(func_getIp());
/**
* Если используется активация, то генерим код активации
*/
if (Config::Get('general.reg.activation')) {
2008-09-21 09:36:57 +03:00
$oUser->setActivate(0);
$oUser->setActivateKey(md5(func_generator().time()));
} else {
$oUser->setActivate(1);
$oUser->setActivateKey(null);
}
/**
* Регистрируем
*/
if ($this->User_Add($oUser)) {
/**
* Убиваем каптчу
*/
unset($_SESSION['captcha_keystring']);
2008-09-21 09:36:57 +03:00
/**
* Создаем персональный блог
*/
$this->Blog_CreatePersonalBlog($oUser);
/**
* Если юзер зарегистрировался по приглашению то обновляем инвайт
*/
if (Config::Get('general.reg.invite') and $oInvite=$this->User_GetInviteByCode($this->GetInviteRegister())) {
$oInvite->setUserToId($oUser->getId());
$oInvite->setDateUsed(date("Y-m-d H:i:s"));
$oInvite->setUsed(1);
$this->User_UpdateInvite($oInvite);
}
2008-09-21 09:36:57 +03:00
/**
* Если стоит регистрация с активацией то проводим её
*/
if (Config::Get('general.reg.activation')) {
2008-09-21 09:36:57 +03:00
/**
* Отправляем на мыло письмо о подтверждении регистрации
*/
$this->Notify_SendRegistrationActivate($oUser,getRequest('password'));
Router::Location(Router::GetPath('registration').'confirm/');
2008-09-21 09:36:57 +03:00
} else {
$this->Notify_SendRegistration($oUser,getRequest('password'));
$this->Viewer_Assign('bRefreshToHome',true);
$oUser=$this->User_GetUserById($oUser->getId());
$this->User_Authorization($oUser,false);
$this->SetTemplateAction('ok');
$this->DropInviteRegister();
}
2008-09-21 09:36:57 +03:00
} else {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
}
}
}
/**
* Обрабатывает активацию аккаунта
*
* @return unknown
*/
protected function EventActivate() {
$bError=false;
/**
* Проверяет передан ли код активации
*/
$sActivateKey=$this->GetParam(0);
if (!func_check($sActivateKey,'md5')) {
$bError=true;
}
/**
* Проверяет верный ли код активации
*/
if (!($oUser=$this->User_GetUserByActivateKey($sActivateKey))) {
$bError=true;
}
/**
*
*/
if ($oUser and $oUser->getActivate()) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('registration_activate_error_reactivate'),$this->Lang_Get('error'));
return Router::Action('error');
}
2008-09-21 09:36:57 +03:00
/**
* Если что то не то
*/
if ($bError) {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('registration_activate_error_code'),$this->Lang_Get('error'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
/**
* Активируем
*/
$oUser->setActivate(1);
$oUser->setDateActivate(date("Y-m-d H:i:s"));
/**
* Сохраняем юзера
*/
if ($this->User_Update($oUser)) {
$this->DropInviteRegister();
$this->Viewer_Assign('bRefreshToHome',true);
$this->User_Authorization($oUser,false);
2008-09-21 09:36:57 +03:00
return;
} else {
2009-04-11 14:50:42 +03:00
$this->Message_AddErrorSingle($this->Lang_Get('system_error'));
2008-09-21 09:36:57 +03:00
return Router::Action('error');
}
}
/**
* Обработка кода приглашения при включеном режиме инвайтов
*
*/
protected function EventInvite() {
if (!Config::Get('general.reg.invite')) {
2009-04-11 14:50:42 +03:00
return parent::EventNotFound();
}
if (isPost('submit_invite')) {
/**
* проверяем код приглашения на валидность
*/
if ($this->CheckInviteRegister()) {
$sInviteId=$this->GetInviteRegister();
} else {
$sInviteId=getRequest('invite_code');
}
$oInvate=$this->User_GetInviteByCode($sInviteId);
if ($oInvate) {
if (!$this->CheckInviteRegister()) {
$this->Session_Set('invite_code',$oInvate->getCode());
}
return Router::Action('registration');
} else {
2009-04-11 14:50:42 +03:00
$this->Message_AddError($this->Lang_Get('registration_invite_code_error'),$this->Lang_Get('error'));
}
}
}
/**
* Путается ли юзер зарегистрироваться с помощью кода приглашения
*
* @return unknown
*/
2010-02-06 14:47:19 +02:00
protected function CheckInviteRegister() {
if ($this->Session_Get('invite_code')) {
return true;
}
return false;
}
protected function GetInviteRegister() {
return $this->Session_Get('invite_code');
}
protected function DropInviteRegister() {
if (Config::Get('general.reg.invite')) {
$this->Session_Drop('invite_code');
}
}
2008-09-21 09:36:57 +03:00
/**
* Просто выводит шаблон
*
*/
protected function EventConfirm() {
}
}
?>