ok
Direktori : /home2/selectio/public_html/tnpsctestbatch.com/ |
Current File : /home2/selectio/public_html/tnpsctestbatch.com/welcome.php |
<?php require_once "config/gc_config.php"; require_once "config/config.php"; session_start(); define('USER_STATUS_ACTIVE', 1); // Assuming $client is defined somewhere before this point if (isset($_GET['code'])) { try { $token = $client->fetchAccessTokenWithAuthCode($_GET['code']); $client->setAccessToken($token['access_token']); $google_oauth = new Google_Service_Oauth2($client); $google_account_info = $google_oauth->userinfo->get(); $userinfo = [ 'email' => $google_account_info['email'], 'first_name' => $google_account_info['givenName'], 'last_name' => $google_account_info['familyName'], 'full_name' => $google_account_info['name'], 'picture' => $google_account_info['picture'], 'verifiedEmail' => $google_account_info['email'], 'token' => $google_account_info['id'], ]; $statement = $pdo->prepare("SELECT * FROM tbl_students WHERE email=:email AND status=:status"); $statement->execute(['email' => $userinfo['email'], 'status' => USER_STATUS_ACTIVE]); $result = $statement->fetch(PDO::FETCH_ASSOC); if ($result) { $_SESSION['user_exam'] = $result; $_SESSION['user_exam']['name'] = $userinfo['full_name']; $_SESSION['user_token'] = $userinfo['token']; if(isset($_SESSION['current_page'])){ echo "<script> window.location.href='".$_SESSION['current_page']."' </script>"; }else{ if(isset($_SESSION['tnpsccheck_out'])){ echo "<script> window.location.href='".$_SESSION['tnpsccheck_out']."' </script>"; }else{ header('Location: https://tnpsctestbatch.com'); } } } else { $statement = $pdo->prepare("INSERT INTO `tbl_students`(`name`, `email`,`token`) VALUES (?,?,?)"); $result = $statement->execute([$userinfo['full_name'], $userinfo['email'], $userinfo['token']]); $id = $pdo->lastInsertId(); if ($result) { $statementa = $pdo->prepare("SELECT * FROM `tbl_students` WHERE id=?"); $statementa->execute([$id]); $resulta = $statementa->fetch(PDO::FETCH_ASSOC); $_SESSION['user_exam'] = $resulta; $token = $userinfo['token']; $_SESSION['redirect111']==0; $_SESSION['user_token'] = $token; // header('Location:collectdetails.php?id='.$id); if(isset($_SESSION['current_page'])){ echo "<script> window.location.href='".$_SESSION['current_page']."' </script>"; }else{ if(isset($_SESSION['tnpsccheck_out'])){ echo "<script> window.location.href='".$_SESSION['tnpsccheck_out']."' </script>"; }else{ header('Location: https://tnpsctestbatch.com/confirm_register.php?user_id='.$id); } } // header('Location:'.$_SESSION['HTTP_REFERER']); exit(); } else { error_log('User not created'); // Handle the error appropriately, e.g., redirect to an error page } } } catch (Exception $e) { error_log('Exception: ' . $e->getMessage()); // Handle the exception as appropriate, e.g., redirect to an error page } } else { if (!isset($_SESSION['user_token'])) { header("location: login.php"); exit(); } } ?>