8 isset(
$user) or require
$_SERVER[
'DOCUMENT_ROOT'] .
'/page/404.php';
10 if (isset(
$_POST[
'action'])) {
12 'client_id' => Wrong\Start\Env::$e->GOOGLE_OAUTH_CLIENT_ID,
13 'redirect_uri' =>
'https://' . Wrong\Start\Env::$e->HTTP_HOST .
'/api/action/' . $basename,
14 'response_type' =>
'code',
15 'scope' =>
'https://www.googleapis.com/auth/userinfo.email',
19 $url =
'https://accounts.google.com/o/oauth2/auth?' . urldecode(http_build_query($params));
21 if (!window.open('$url','oauth','left='+Math.ceil((window.screen.width - 800)/2)+', top='+Math.ceil((window.screen.height-600)/2)+', width=800, height=600')) {
27 if (!empty($_GET[
'code'])) {
29 'client_id' => Wrong\Start\Env::$e->GOOGLE_OAUTH_CLIENT_ID,
30 'client_secret' => Wrong\Start\Env::$e->GOOGLE_OAUTH_CLIENT_SECRET,
31 'redirect_uri' =>
'https://' . Wrong\Start\Env::$e->HTTP_HOST .
'/api/action/' . $basename,
32 'grant_type' =>
'authorization_code',
33 'code' => $_GET[
'code']
36 $ch = curl_init(
'https://accounts.google.com/o/oauth2/token');
37 curl_setopt($ch, CURLOPT_POST, 1);
38 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
39 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
40 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
41 curl_setopt($ch, CURLOPT_HEADER,
false);
42 $data = curl_exec($ch);
46 if (!empty(
$data[
'access_token'])) {
48 'access_token' =>
$data[
'access_token'],
49 'id_token' =>
$data[
'id_token'],
50 'token_type' =>
'Bearer',
54 $info = file_get_contents(
'https://www.googleapis.com/oauth2/v1/userinfo?' . urldecode(http_build_query($params)));
55 $info = json_decode($info,
true);
57 if (!empty($info[
'email'])) {
58 if (
$user = Wrong\Auth\User::match($info[
'email'])) {
61 $user->set_confirm(1);
63 if ($id = Wrong\Auth\User::session(Wrong\Models\Users::create($info[
'email'], substr(str_shuffle(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), 0, 10), Wrong\Start\Env::$e->GROUPS_USERS, Wrong\Start\Env::$e->OWNER_GROUP_USERS))) {
65 $user->set_confirm(1);
69 if (
$user->access()->page(
'/system')) {
70 exit(
'<!DOCTYPE html><html lang="en"><head><title>...</title></head><body><script>if(window.opener){window.opener.location.href="/system";window.close();}else{location.href="/system";}</script></body></html>');
72 exit(
'<!DOCTYPE html><html lang="en"><head><title>...</title></head><body><script>if(window.opener){window.opener.location.reload();window.close();}else{location.href="/";}</script></body></html>');
User отвечает за работу с данными пользователя
static session($init_id=0)
static add($code, $timeout=0, $key='')
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit