HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //proc/thread-self/cwd/login-google/google_oauth_config.php
<?php
session_start();
//Google API PHP Library includes

require_once 'vendor/autoload.php';
include_once "../wp-config.php";
$curDate = date('Y-m-d H:i:s');

$PSY_USERS_DETAILS = $wpdb->prefix . PSY_USERS_DETAILS;
$PSY_USERS = $wpdb->prefix . PSY_USERS;
$PSY_GOOGLE_AUTH = $wpdb->prefix . PSY_GOOGLE_AUTH;

// Set config params to acces Google API
$client_id = '930577803-9e6mu5e1bccsd6a3ac1qeeoqcr1vbf54.apps.googleusercontent.com';
$client_secret = 'nAyETa1ANKbQWQ2HQB1oCjEU';
$redirect_uri = 'https://selfanalyse.com/login-google/';
$scope = 'https://www.googleapis.com/auth/userinfo.email ' .
  'https://www.googleapis.com/auth/userinfo.profile';

//Create and Request to access Google API
$client = new Google_Client();
$client->setApplicationName("Google OAuth Login With PHP");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope($scope);

$objRes = new Google_Service_Oauth2($client);

//Add access token to php session after successfully authenticate
if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

//set token
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
  $client->setAccessToken($_SESSION['access_token']);
}

//store with user data
if ($client->getAccessToken()) {
  $userData = $objRes->userinfo->get();

  if (!empty($userData)) {
    $email = $userData['email'];
    $givenName = $userData['givenName'];
    $familyName = $userData['familyName'];
	$picture = $userData['picture'];
    //$checkUser = $wpdb->get_row("SELECT count(*) as check,user_password from wp_aat93akkcv_users where user_login ='$email' OR user_email='$email'");
    if (username_exists($email)) {
      //get user's ID
      $user = get_user_by('login', $email);
      $user_id = $user->ID;
      //login
      wp_set_current_user($user_id, $email);
      wp_set_auth_cookie($user_id);
      do_action('wp_login', $email);
	  
	  $inserG = $wpdb->query("INSERT into $PSY_GOOGLE_AUTH set user_id='$user_id', type='Login', google_response='', action_date='$curDate'"); 
	  
      $message = "Login";
    } else if (email_exists($email)) {
      //get user's ID
      $user = get_user_by('email', $email);
      $user_id = $user->ID;

      //login
      wp_set_current_user($user_id, $email);
      wp_set_auth_cookie($user_id);
      do_action('wp_login', $email);

	  $inserG = $wpdb->query("INSERT into $PSY_GOOGLE_AUTH set user_id='$user_id', type='Login', google_response='', action_date='$curDate'"); 
	  
    } else {
      $password = str_shuffle(bin2hex(openssl_random_pseudo_bytes(4)));
      $user_id = wp_create_user($email, $password, $email);
      
      $inserTDetails = $wpdb->query("INSERT into $PSY_USERS_DETAILS set user_id='$user_id', first_name='$givenName', last_name='$familyName', email_address='$email', source='SP', source_id='0'");
	
	  $inserG = $wpdb->query("INSERT into $PSY_GOOGLE_AUTH set user_id='$user_id', type='Register', google_response='', action_date='$curDate'"); 
	  
      $creds = array();
      $creds['user_login'] = $email;
      $creds['user_password'] = $password;
      $creds['remember'] = true;

      $user = wp_signon($creds, false);
      wp_set_current_user($user->ID);
	  
      if (is_wp_error($user_id)) {
        echo $user_id->get_error_message();
      } else {

        /*********send welcome email********** */
		    include_once '/var/www/html/staging/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
		    sendWelecomeEmailGoogle($email,$givenName,$password);
        $message = "Success";
      }
    }
  }
  $_SESSION['access_token'] = $client->getAccessToken();
} else {
  $googleAuthUrl  =  $client->createAuthUrl();
}