-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleLogin.php
54 lines (46 loc) · 1.75 KB
/
googleLogin.php
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
50
51
52
53
54
<?php
include_once("googleConfig.php");
include_once ("src/controllers/userLoginController.php");
$user_data;
$userProfile;
error_reporting(0);
if(isset($_REQUEST['code'])){
$gClient->authenticate();
$_SESSION['token'] = $gClient->getAccessToken();
header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$gClient->setAccessToken($_SESSION['token']);
}
if ($gClient->getAccessToken())
{
$userProfile = $google_oauthV2->userinfo->get();
//DB Insert
$controller = new userController();
$user_data = $controller->getUser($userProfile['id'],$userProfile['first_name'],$userProfile['last_name'],"google",$userProfile['email'],$userProfile['picture']['data']['url']);
$_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
print_r($user_data);
if($user_data == null)
{
$user_data = $controller -> save ($userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],"google",$userProfile['email'],$userProfile['picture']);
}
$_SESSION ['userDetails'] = $user_data;
$output = '<h1>Google Profile Details </h1>';
$output .= '<img src="'.$user_data->getProfilePicLink ().'">';
$output .= '<br/>Google ID : ' . $user_data->getauthID ();
$output .= '<br/>Name : ' . $user_data->getFirstName ().' '.$user_data->getLastName();
$output .= '<br/>Email : ' . $user_data->getEmailId();
$output .= '<br/>You are login with : Google';
$output .= '<br/>Logout from <a href="googleLogout.php?logout">Google</a>';
echo $output;
$_SESSION['token'] = $gClient->getAccessToken();
}
else
{
$authUrl = $gClient->createAuthUrl();
}
if(isset($authUrl))
{
echo '<a href="'.$authUrl.'"><img src="images/glogin.png" alt=""/> Google LogIn</a>';
}
?>