Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
3
Indexable
Never
 if (isset($_GET['code'])) {
    
    $token = token("code", $_GET['code']);
    
    if ($token['access_token']) {
        $geturl   = "https://www.googleapis.com/oauth2/v3/userinfo?alt=json&access_token=$token[access_token]";
        $user     = load($geturl);
        $userinfo = json_decode($user, true);
        
        if ($userinfo['email']) {
            
            if (file_exists("base/data/user/$userinfo[email].json")) {
                
                $update = json_decode(file_get_contents("base/data/user/$userinfo[email].json"), true);
                $update['refresh_token'] = $token['refresh_token'];
                if($update['publisher'] == true)
                {
                   $update['publisher'] = true; 
                }else{
                    $update['publisher'] = false; 
                }
                if ($update['folder'] == null) {
                    $folder = create_folder($token[access_token]);
                    $folid  = $folder['id'];
                    anyonefolder($folid, $token[access_token]);
                    $update['folder'] = $folder['id'];
                    $update['root']   = $folder['parents']['0'];
                }
                file_put_contents("base/data/user/$userinfo[email].json", json_encode($update, true));