Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
<?php
/*
=====================================================
Loginza для DataLife Engine
-----------------------------------------------------
http://www.dletweak.ru/
http://www.loginza.ru/
-----------------------------------------------------
Copyright (c) 2008-2010 Dletweak
Copyright (c) 2008-2010 «Логинза»
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: loginza.php
-----------------------------------------------------
Назначение: Авторизация и помещение в группу OpenID
=====================================================
*/
if( ! defined( 'DATALIFEENGINE' ) ) {
die( "Hacking attempt!" );
}
define( 'LOGINZA_GET_INFO', 'http://loginza.ru/api/authinfo?token=');
function json_decode_from_class( $content, $ass = FALSE ) {
require_once ENGINE_DIR.'/classes/JSON.php';
if ($ass) {
$json = new Services_JSON( SERVICES_JSON_LOOSE_TYPE );
} else {
$json = new Services_JSON;
}
return $json->decode($content);
}
$token = $_POST['token'];
if( !$token ) {
msgbox( $lang['all_err_1'], $lang['loginza_err1'] );
} else {
$loginza_info = file_get_contents( LOGINZA_GET_INFO.$token );
$info = function_exists('json_decode') ? json_decode( $loginza_info, TRUE ) : json_decode_from_class( $loginza_info, TRUE );
if (!isset($info['identity'])) {
$stop = $lang['loginza_err2'];
}
if( !$stop ) {
$username = convert_unicode($info['name']['first_name'].' '.$info['name']['last_name']);
$password = md5( trim($info['identity']) ) ;
$photo = trim($info['photo']);
$fullname = convert_unicode($info['name']['first_name'].' '.$info['name']['last_name']);
$icq_i = $info['im']['icq'];
$country = $info['address']['home']['country'];
$city = $info['address']['home']['country'];
$bio = $info['biography'];
$email = 'id-'.substr( md5( trim($info['identity']) ), 0, 8).'@'.clean_url($config['http_home_url']);
$member_id = $db->super_query( "SELECT * FROM " . USERPREFIX . "_users where name='$username' and password='" . md5( $password ) . "'" );
if( $member_id['user_id'] ) {
set_cookie( "dle_user_id", $member_id['user_id'], 365 );
set_cookie( "dle_password", $_POST['login_password'], 365 );
@session_register( 'dle_user_id' );
@session_register( 'dle_password' );
@session_register( 'member_lasttime' );
$_SESSION['dle_user_id'] = $member_id['user_id'];
$_SESSION['dle_password'] = $password;
$_SESSION['member_lasttime'] = $member_id['lastdate'];
$_SESSION['dle_log'] = 0;
$dle_login_hash = md5( strtolower( $_SERVER['HTTP_HOST'] . $member_id['name'] . sha1($password) . $config['key'] . date( "Ymd" ) ) );
if( $config['log_hash'] ) {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
$hash = '';
srand( ( double ) microtime() * 1000000 );
for($i = 0; $i < 9; $i ++) {
$hash .= $salt{rand( 0, 33 )};
}
$hash = md5( $hash );
$db->query( "UPDATE " . USERPREFIX . "_users set hash='" . $hash . "', lastdate='{$_TIME}', logged_ip='" . $_IP . "' WHERE user_id='$member_id[user_id]'" );
set_cookie( "dle_hash", $hash, 365 );
$_COOKIE['dle_hash'] = $hash;
$member_id['hash'] = $hash;
} else $db->query( "UPDATE LOW_PRIORITY " . USERPREFIX . "_users set lastdate='{$_TIME}', logged_ip='" . $_IP . "' WHERE user_id='$member_id[user_id]'" );
$is_logged = TRUE;
} else {
$check_mail = $db->super_query( "SELECT COUNT(*) as how FROM " . USERPREFIX . "_users where email='.$email.'");
if($check_mail['how'] > 0) $stop = $lang['loginza_err3'];
if( !$stop ) {
require_once ENGINE_DIR . '/classes/parse.class.php';
$parse = new ParseFilter( );
$parse->safe_mode = true;
$parse->allow_url = false;
$parse->allow_image = false;
$stopregistration = FALSE;
$config['reg_group_loginza'] = intval( $config['reg_group_loginza'] ) ? intval( $config['reg_group_loginza'] ) : 4;
$regpassword = md5($password);
$email = $db->safesql( $parse->process( $email ) );
if(!$email) $email = $name.'@'.clean_url($config['http_home_url']);
$fullname = $db->safesql( $parse->process( $fullname ) );
$land_country = $db->safesql( $parse->process( $country ) );
$land_city = $db->safesql( $parse->process( $city ) );
if( $land_country !='' AND $land_city !='' ) $land = $land_country.', '.$land_city;
$icq = $db->safesql( $parse->process( $icq_i ) );
$info = $db->safesql( $parse->BB_Parse( $parse->process( $bio ), false ) );
$info = strlen($info) <= 200 ? $info : substr($info, 0, 200);
$add_time = time() + ($config['date_adjust'] * 60);
$_IP = $db->safesql( $_SERVER['REMOTE_ADDR'] );
if( intval( $config['reg_group'] ) < 3 ) $config['reg_group'] = 4;
$name = $username;
$db->query( "INSERT INTO " . USERPREFIX . "_users (name, fullname, password, email, reg_date, lastdate, user_group, info, signature, favorites, xfields, logged_ip) VALUES ('$name', '$fullname', '$regpassword', '$email', '$add_time', '$add_time', '" . $config['reg_group_loginza'] . "', '', '', '', '', '" . $_IP . "')" );
$id = $db->insert_id()+1;
if( $photo ) {
$fparts = pathinfo($photo);
$tmp_name = $fparts['basename'];
$type = $fparts['extension'];
include_once ENGINE_DIR . '/classes/thumb.class.php';
$res = @copy($photo, ROOT_DIR . "/uploads/fotos/".$tmp_name);
if( $res ) {
$thumb = new thumbnail( ROOT_DIR . "/uploads/fotos/".$tmp_name );
$thumb->size_auto( $user_group[$config['reg_group_loginza']]['max_foto'] );
$thumb->jpeg_quality( $config['jpeg_quality'] );
$thumb->save( ROOT_DIR . "/uploads/fotos/foto_" . $id . "." . $type );
@unlink( ROOT_DIR . "/uploads/fotos/".$tmp_name );
$foto_name = "foto_" . $id . "." . $type;
$db->query( "UPDATE " . USERPREFIX . "_users set foto='$foto_name' where name='$name'" );
}
}
$member_id = $db->super_query( "SELECT * FROM " . USERPREFIX . "_users where name='$name' and password='" . md5( $password ) . "'" );
if( $member_id['user_id'] ) {
set_cookie( "dle_user_id", $member_id['user_id'], 365 );
set_cookie( "dle_password", $_POST['login_password'], 365 );
@session_register( 'dle_user_id' );
@session_register( 'dle_password' );
@session_register( 'member_lasttime' );
$_SESSION['dle_user_id'] = $member_id['user_id'];
$_SESSION['dle_password'] = $password;
$_SESSION['member_lasttime'] = $member_id['lastdate'];
$_SESSION['dle_log'] = 0;
$dle_login_hash = md5( strtolower( $_SERVER['HTTP_HOST'] . $member_id['name'] . sha1($password) . $config['key'] . date( "Ymd" ) ) );
if( $config['log_hash'] ) {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
$hash = '';
srand( ( double ) microtime() * 1000000 );
for($i = 0; $i < 9; $i ++) {
$hash .= $salt{rand( 0, 33 )};
}
$hash = md5( $hash );
$db->query( "UPDATE " . USERPREFIX . "_users set hash='" . $hash . "', lastdate='{$_TIME}', logged_ip='" . $_IP . "' WHERE user_id='$member_id[user_id]'" );
set_cookie( "dle_hash", $hash, 365 );
$_COOKIE['dle_hash'] = $hash;
$member_id['hash'] = $hash;
} else $db->query( "UPDATE LOW_PRIORITY " . USERPREFIX . "_users set lastdate='{$_TIME}', logged_ip='" . $_IP . "' WHERE user_id='$member_id[user_id]'" );
$is_logged = TRUE;
}
}
else {
msgbox( $lang['all_err_1'], $stop );
}
}
} else {
msgbox( $lang['all_err_1'], $stop );
}
if( !$stop ) header("Location: ".$config['http_home_url']);
}
?>