123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
-
- require_once 'config.php';
-
-
-
-
- if(isset($_SESSION['token'])) {
- $client->setAccessToken($_SESSION['token']);
- }
- else if(isset($_GET['code'])) {
- $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
-
-
- if(isset($token['error'])) {
- header('Location: ./logout.php');
- die();
- }
-
- $_SESSION['token'] = $token;
- }
- else {
- header('Location: ../home.php');
- exit();
- }
-
-
-
-
- $oAuth = new Google_Service_Oauth2($client);
- $userData = $oAuth->userinfo_v2_me->get();
-
-
-
-
-
- require_once 'dbh.inc.php';
-
-
- $query = 'SELECT * FROM researcher WHERE email = "' . $userData['email'] . '";';
- $result = mysqli_query($connection, $query);
- $dbUserData = mysqli_fetch_assoc($result);
-
-
-
- if($dbUserData === NULL) {
- $_SESSION['error'] = 'unauthorized';
- header('Location: ../unauthorized.php');
- exit();
- }
-
-
-
- $_SESSION['newUser'] = false;
-
-
-
-
- if($dbUserData['picture'] == NULL) {
- $query = 'UPDATE researcher SET name = "' . $userData['name'] . '", picture = "' . $userData['picture'] . '" WHERE email = "' . $userData['email'] . '";';
- mysqli_query($connection, $query);
- $_SESSION['newUser'] = true;
- }
-
-
-
- $result = mysqli_query($connection, $query);
- $dbUserData = mysqli_fetch_assoc($result);
- $_SESSION['dbUserData'] = $dbUserData;
-
-
-
-
- $_SESSION['error_set'] = isset($_SESSION['error']);
-
-
- header('Location: ../home.php');
- exit();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|