-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
91 lines (82 loc) · 3.39 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require 'config.php';
if(isset($_SESSION['login_id'])){
header('Location: meditating.php');
exit;
}
require 'google-api/vendor/autoload.php';
// Creating new google client instance
$client = new Google_Client();
// Enter your Client ID
$client->setClientId('683208443895-gfg4rvmt62jkgo7iln556n3mo5dtvtr3.apps.googleusercontent.com');
// Enter your Client Secrect
$client->setClientSecret('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');
// Enter the Redirect URL
$client->setRedirectUri('https://relaxsome.me');
// Adding those scopes which we want to get (email & profile Information)
$client->addScope("email");
$client->addScope("profile");
if(isset($_GET['code'])){
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
if(!isset($token["error"])){
$client->setAccessToken($token['access_token']);
// getting profile information
$google_oauth = new Google_Service_Oauth2($client);
$google_account_info = $google_oauth->userinfo->get();
// Storing data into database
$id = mysqli_real_escape_string($db_connection, $google_account_info->id);
$full_name = mysqli_real_escape_string($db_connection, trim($google_account_info->name));
$email = mysqli_real_escape_string($db_connection, $google_account_info->email);
$profile_pic = mysqli_real_escape_string($db_connection, $google_account_info->picture);
// checking user already exists or not
$get_user = mysqli_query($db_connection, "SELECT `google_id` FROM `users` WHERE `google_id`='$id'");
if(mysqli_num_rows($get_user) > 0){
$_SESSION['login_id'] = $id;
header('Location: meditating.php');
exit;
}
else{
// if user not exists we will insert the user
$insert = mysqli_query($db_connection, "INSERT INTO `users`(`google_id`,`name`,`email`,`profile_image`) VALUES('$id','$full_name','$email','$profile_pic')");
if($insert){
$_SESSION['login_id'] = $id;
header('Location: meditating.php');
exit;
}
else{
echo "Sign up failed!(Something went wrong).";
}
}
}
else{
header('Location: login.php');
exit;
}
}
// Google Login Url = $client->createAuthUrl();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Babylonica' rel='stylesheet'>
<link rel="stylesheet" href="./style.css" />
<title>Relaxsome</title>
</head>
<body>
<div class="screen-one">
<span id="MyClockDisplay" class="clock" onload="showTime()"></span>
<h2>RELAXSOME</h2>
<!-- <button id="social_login_btn">Login with Google</button> -->
<a type="button" class="login-with-google-btn" href="<?php echo $client->createAuthUrl(); ?>">
Sign in with Google
</a>
<span id="alt_stmnt">OR</span>
<a href="meditating.php" class="trial_btn"> <p>Free Trial</p></a>
</div>
<script src="app.js"></script>
</body>
</html>