Вход Регистрация
Файл: other/vk.php
Строк: 75
<?php
    
require_once '../system/xcms_core.php';
    
$title='Вход через ВКонтакте';
    if(!
$user){
        
$params = array(
            
'client_id'     => $client_id,
            
'redirect_uri'  => $redirect_uri,
            
'response_type' => 'code'
        
);
        if (isset(
$_GET['code'])){ // Если получен код
            
$result false;
            
$params = array(
                
'client_id' => $client_id,
                
'client_secret' => $client_secret,
                
'code' => $_GET['code'],
                
'redirect_uri' => $redirect_uri
            
);
            
$token json_decode(file_get_contents('https://oauth.vk.com/access_token'.'?'.urldecode(http_build_query($params))),true);
            if (isset(
$token['access_token'])) { // Если получен токен
                
$params = array(
                    
'uids'         => $token['user_id'],
                    
'fields'       => 'uid,first_name,last_name,screen_name,sex,bdate,photo_big',
                    
'access_token' => $token['access_token']
                );
                
$userInfo json_decode(file_get_contents('https://api.vk.com/method/users.get'.'?'.urldecode(http_build_query($params))), true);
                if (isset(
$userInfo['response'][0]['uid'])) {
                    
$userInfo $userInfo['response'][0];
                    
$result true;
                }
            }
            if (
$result) {
                
$total=$db->query("select `id` from `user` where `social_vk_id`='$userInfo[uid]'")->rowCount();
                if(
$total){
                    
$q=$db->query("select `login`,`password` from `user` where `social_vk_id`='$userInfo[uid]'")->fetch(PDO::FETCH_ASSOC);
                    if(
$q){
                        
setcookie('login'$q['login'], time()+3600*24*365'/');
                        
setcookie('password'$q['password'], time()+3600*24*365'/');
                        require_once 
'../system/head.php';
                        echo
'<div class="menu">Добро пожаловать, '.$q['login'].' &rarr; <a href="/">Далее</a></div>';
                    }
                }else{
                    
$newpass=$passgen;
                    
$q=$db->query("select `id` from `user` where `login`='$userInfo[uid]'")->rowCount();
                    if(
$q)$userInfo['uid']=$userInfo['uid'].'-'.rand(0,99999);
                    if(
$userInfo['photo_big']!=='http://vk.com/images/camera_200.gif'){
                        
copy($userInfo['photo_big'], '../files/avatar/'.$userInfo['uid'].'.jpg');
                        
$avatar=$userInfo['uid'].'.jpg';
                    }else{
                        
$avatar='default.png';
                    }
                    
$db->query("insert into `user` set `login`='$userInfo[uid]', `social_vk_id`='$userInfo[uid]', `password`='".pass($newpass)."',
                    `time`='
$time', `mail`='0', `names`='$userInfo[first_name]', `inf`='Я Вконтакте - http://vk.com/id$userInfo[uid]', `avatar`='$avatar',`visit`='$time'");
                    require_once 
'../system/head.php';
                    echo
'<div class="menu">Для вас был создан аккаунт:<br />
                    Логин: '
.$userInfo['uid'].'<br />
                    Пароль: '
.$newpass.'<br />
                    <a href="/enter?login='
.$userInfo['uid'].'&password='.$newpass.'">Нажмите сюда, чтобы авторизоваться</a>
                    </div>'
;
                }
            }
        }
    }else{echo
'<div class="body">Ошибка</div>';}
require_once 
'../system/foot.php';
?>
Онлайн: 1
Реклама