-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthGoogle.php
More file actions
49 lines (49 loc) · 1.62 KB
/
authGoogle.php
File metadata and controls
49 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace app
{
class authGoogle extends \letId\service\google
{
static function client()
{
return new self;
}
public function user()
{
if (self::connectClient()) {
self::$client->setAuthConfig(avail::$config['storage.root'].'/client_secret.json');
// self::$client->setAccessType("offline");
self::$client->setIncludeGrantedScopes(true);
self::$client->setRedirectUri('http://localhost/google/?oauth2callback');
// self::$client->setScopes('email');
self::$client->setScopes(
array(
"https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
)
);
}
return $this;
}
public function sign($table)
{
$this->accessRemove(isset($_GET['signout']));
if ($this->accessObserve()) {
if (!avail::$authentication->usersCookie()->has()) {
$authData = avail::arrays($this->authData)->key_rename(
array('name'=>'displayname','given_name'=>'firstname','family_name'=>'lastname','email_verified'=>'status')
);
$column = array_intersect_key($authData, array_flip(array('email','displayname','status')));
$db = avail::$database->insert($column)->to($table)->duplicateUpdate(array('logs'=>array('(logs+1)')))->execute()->rowsAffected();
if ($db->rowsId) {
avail::$authentication->usersCookie()->set(array('userid'=>$db->rowsId));
if (isset($_GET['code'])) header("Location: /");
}
}
} else {
avail::content('authGoogleUrl')->set(self::$client->createAuthUrl());
}
}
}
}