<?php
session_start();
require 'config/google.php';
require 'config/database.php';
$token=$client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token['access_token']);
$oauth=new Google\Service\Oauth2($client);
$u=$oauth->userinfo->get();
$data=['google_id'=>$u->id,'name'=>$u->name,'email'=>$u->email,'picture'=>$u->picture];
$db->onDuplicate(['name','email','picture']);
$db->insert('users',$data);
$db->where('google_id',$u->id);
$r=$db->getOne('users');
$_SESSION['user']=$r;
header('Location: dashboard.php');
