You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
6.7 KiB
235 lines
6.7 KiB
9 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* AVE.cms - Модуль Авторизация
|
||
|
*
|
||
|
* @package AVE.cms
|
||
|
* @subpackage module_Login
|
||
|
* @filesource
|
||
|
*/
|
||
|
|
||
|
if (!defined('BASE_DIR')) exit;
|
||
|
|
||
|
if (defined('ACP'))
|
||
|
{
|
||
|
$modul['ModuleName'] = 'Авторизация';
|
||
|
$modul['ModuleSysName'] = 'login';
|
||
|
$modul['ModuleVersion'] = '2.2.1';
|
||
|
$modul['ModuleDescription'] = 'Данный модуль предназначен для регистрации пользователей на вашем сайте. Для вывода формы авторизации, разместите системный тег <strong>[mod_login]</strong> в нужном месте вашего шаблона. Также вы можете указать шаблон, в котором будет отображена форма для регистрации и авторизации.';
|
||
|
$modul['ModuleAutor'] = 'AVE.CMS Team';
|
||
|
$modul['ModuleCopyright'] = '© 2007-2013 AVE.CMS';
|
||
|
$modul['ModuleStatus'] = 1;
|
||
|
$modul['ModuleIsFunction'] = 1;
|
||
|
$modul['ModuleTemplate'] = 1;
|
||
|
$modul['ModuleAdminEdit'] = 1;
|
||
|
$modul['ModuleFunction'] = 'mod_login';
|
||
|
$modul['ModuleTag'] = '[mod_login]';
|
||
|
$modul['ModuleTagLink'] = '';
|
||
|
$modul['ModuleAveTag'] = '#\\\[mod_login]#';
|
||
|
$modul['ModulePHPTag'] = '<?php mod_login(); ?>';
|
||
|
}
|
||
|
|
||
|
function loginza_check_token($token = '') {
|
||
|
global $AVE_DB;
|
||
|
/*
|
||
|
* Данные нашей Логинзы
|
||
|
*/
|
||
|
$loginza_id = '';
|
||
|
$loginza_api_key = '';
|
||
|
|
||
|
if( !$token )
|
||
|
$token = @$_REQUEST['token'];
|
||
|
if( !$token )
|
||
|
return false;
|
||
|
$sig = md5($token . $loginza_api_key);
|
||
|
|
||
|
$auth_json = CURL_file_get_contents( "http://loginza.ru/api/authinfo?token={$token}");//&id={$loginza_id}&sig={$sig}" );
|
||
|
if( !$auth_json )
|
||
|
return false;
|
||
|
|
||
|
$auth_data = json_decode( $auth_json );
|
||
|
$auth_data->identity='loginza_'.md5(trim($auth_data->identity));
|
||
|
|
||
|
if( isset( $auth_data->error_type ) || isset( $auth_data->error_message ) )
|
||
|
return false;
|
||
|
//var_dump($auth_data);
|
||
|
$user_id=$AVE_DB->Query("SELECT * FROM ".PREFIX."_users where user_name='".$auth_data->identity."' LIMIT 1")->FetchRow();
|
||
|
//die();
|
||
|
if($user_id) {
|
||
|
user_login($auth_data->identity,'');
|
||
|
header('Location:' . rewrite_link($_SESSION['referer']));
|
||
|
unset($_SESSION['referer']);
|
||
|
exit;
|
||
|
}
|
||
|
//Если у юзера есть фотовка - то делаем из нее аватарку
|
||
|
//лежать все будет в avatar_dir
|
||
|
//получить наличие аватарки мона путем md5($user_login)
|
||
|
if($auth_data->photo){
|
||
|
$avatar=CURL_file_get_contents($auth_data->photo);
|
||
|
$avatar_dir=BASE_DIR.'/uploads/avatars';
|
||
|
if(!file_exists($avatar_dir))mkdir($avatar_dir,0777,true);
|
||
|
if($avatar){
|
||
|
$im = imagecreatefromstring($avatar);
|
||
|
if ($im !== false) {
|
||
|
imagejpeg($im,$avatar_dir.'/'.md5($auth_data->identity).'.jpg');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//тут подставляем данные для последующей регистрации
|
||
|
$_POST['user_name']=$auth_data->identity;
|
||
|
$_POST['reg_email']=isset( $auth_data->email ) && $auth_data->email ? $auth_data->email : '';
|
||
|
$fname=isset( $auth_data->name->full_name ) && $auth_data->name->full_name ? $auth_data->name->full_name : '';
|
||
|
$fname=explode(' ',$fname);
|
||
|
$_POST['reg_firstname']=isset( $auth_data->name->first_name ) && $auth_data->name->first_name ? $auth_data->name->first_name : @$fname[0];
|
||
|
$_POST['reg_lastname']=isset( $auth_data->name->last_name ) && $auth_data->name->last_name ? $auth_data->name->last_name : @$fname[1];
|
||
|
$_REQUEST['action']='register';
|
||
|
$_REQUEST['sub']='register';
|
||
|
//Надо кудато положить флажок - что зашли через логинзу
|
||
|
$_SESSION['loginza_auth']=1;
|
||
|
//Тут на всякий случай похраним инфу о юзвере
|
||
|
$_SESSION['loginza_data']=$auth_data;
|
||
|
return $auth_data;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Обработка тега модуля
|
||
|
*
|
||
|
*/
|
||
|
function mod_login()
|
||
|
{
|
||
|
global $AVE_DB, $AVE_Template;
|
||
|
|
||
|
$tpl_dir = BASE_DIR . '/modules/login/templates/';
|
||
|
$lang_file = BASE_DIR . '/modules/login/lang/' . $_SESSION['user_language'] . '.txt';
|
||
|
|
||
|
if (isset($_SESSION['user_id']) && isset($_SESSION['user_pass']))
|
||
|
{
|
||
|
$AVE_Template->config_load($lang_file, 'displaypanel');
|
||
|
|
||
|
$AVE_Template->display($tpl_dir . 'userpanel.tpl');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$AVE_Template->config_load($lang_file, 'displayloginform');
|
||
|
|
||
|
$active = $AVE_DB->Query("
|
||
|
SELECT login_status
|
||
|
FROM " . PREFIX . "_module_login
|
||
|
WHERE Id = 1
|
||
|
")->GetCell();
|
||
|
|
||
|
$AVE_Template->assign('active', $active);
|
||
|
|
||
|
$AVE_Template->display($tpl_dir . 'loginform.tpl');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (!defined('ACP') &&
|
||
|
!empty($_REQUEST['action']) &&
|
||
|
isset($_REQUEST['module']) && $_REQUEST['module'] == 'login')
|
||
|
{
|
||
|
global $login;
|
||
|
|
||
|
loginza_check_token();
|
||
|
|
||
|
//die();
|
||
|
if (isset($_REQUEST['print']) && $_REQUEST['print'] == 1) print_error();
|
||
|
|
||
|
$tpl_dir = BASE_DIR . '/modules/login/templates/';
|
||
|
$lang_file = BASE_DIR . '/modules/login/lang/' . $_SESSION['user_language'] . '.txt';
|
||
|
|
||
|
if (! @require(BASE_DIR . '/modules/login/class.login.php')) module_error();
|
||
|
|
||
|
$login = new Login($tpl_dir, $lang_file);
|
||
|
|
||
|
switch($_REQUEST['action'])
|
||
|
{
|
||
|
case 'wys':
|
||
|
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'on')
|
||
|
{
|
||
|
if (check_permission('documents')) $_SESSION['user_adminmode'] = 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
unset($_SESSION['user_adminmode']);
|
||
|
}
|
||
|
|
||
|
header('Location:' . get_referer_link());
|
||
|
exit;
|
||
|
|
||
|
case 'wys_adm':
|
||
|
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'on')
|
||
|
{
|
||
|
if (check_permission('documents')) $_SESSION['user_adminmode'] = 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
unset($_SESSION['user_adminmode']);
|
||
|
}
|
||
|
|
||
|
header('Location:' . get_home_link());
|
||
|
exit;
|
||
|
|
||
|
case 'login':
|
||
|
$login->loginUserLogin();
|
||
|
break;
|
||
|
|
||
|
case 'logout':
|
||
|
$login->loginUserLogout();
|
||
|
break;
|
||
|
|
||
|
case 'register':
|
||
|
$login->loginNewUserRegister();
|
||
|
break;
|
||
|
|
||
|
case 'passwordreminder':
|
||
|
$login->loginUserPasswordReminder();
|
||
|
break;
|
||
|
|
||
|
case 'passwordchange':
|
||
|
$login->loginUserPasswordChange();
|
||
|
break;
|
||
|
|
||
|
case 'delaccount':
|
||
|
$login->loginUserAccountDelete();
|
||
|
break;
|
||
|
|
||
|
case 'profile':
|
||
|
$login->loginUserProfileEdit();
|
||
|
break;
|
||
|
|
||
|
case 'checkusername':
|
||
|
$login->loginUsernameAjaxCheck();
|
||
|
break;
|
||
|
|
||
|
case 'checkemail':
|
||
|
$login->loginEmailAjaxCheck();
|
||
|
break;
|
||
|
case 'userinfo':
|
||
|
$login->loginUserInfo(intval($_REQUEST['user']));
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (defined('ACP') && !empty($_REQUEST['moduleaction']))
|
||
|
{
|
||
|
global $login;
|
||
|
|
||
|
$tpl_dir = BASE_DIR . '/modules/login/templates/';
|
||
|
$lang_file = BASE_DIR . '/modules/login/lang/' . $_SESSION['admin_language'] . '.txt';
|
||
|
|
||
|
if (! @require(BASE_DIR . '/modules/login/class.login.php')) module_error();
|
||
|
|
||
|
$login = new Login($tpl_dir, $lang_file);
|
||
|
|
||
|
switch($_REQUEST['moduleaction'])
|
||
|
{
|
||
|
case '1':
|
||
|
$login->loginSettingsEdit();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|