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: /var/www/selfanalyse/wp-content/plugins/psychometrics/psy_signup_verify.php
<?php
header('Content-Type: application/json');
include_once '../../../wp-config.php';
global $wpdb;
$PSY_USERS = $wpdb->prefix . PSY_USERS;
$PSY_USERS_DETAILS = $wpdb->prefix . PSY_USERS_DETAILS;
//$PSY_USER_RESET_PASSWORD_TABLE  = $wpdb->prefix . PSY_USER_RESET_PASSWORD_TABLE;

/*********** Required file Mail *****************/

/***********************************************/
// ini_set('display_errors',1);
// ini_set('display_startup_errors',1);
// error_reporting(E_ALL);
$DataType = $_REQUEST['dataType'];

$site_name = SITE_NAME;

$array = array();

/***********   SIGN IN  *****************/
if ($DataType == 'sign-in') {
	$username = $_REQUEST['UserName'];
	$Password = $_REQUEST['UserPwd'];

	if ($username == '') {
		$array = array('status' => 0, 'msg' => "Enter your username");
	} elseif ($Password == '') {
		$array = array('status' => 0, 'msg' => "Enter your password");
	} else {

		add_filter('authenticate', 'allow_email_login', 20, 3);
		/**
		 * allow_email_login filter to the authenticate filter hook, to fetch a username based on entered email
		 * @param  obj $user
		 * @param  string $username [description]
		 * @param  string $password [description]
		 * @return boolean
		 */
		function allow_email_login($user, $username, $password)
		{
			if (is_email($username)) {
				$user = get_user_by_email($username);
				if ($user) $username = $user->user_login;
			}
			return wp_authenticate_username_password(null, $username, $password);
		}
		

		$creds = array();
		$creds['user_login'] = $username;
		$creds['user_password'] = $Password;
		$creds['remember'] = true;

		$user = wp_signon($creds, false);
		wp_set_current_user($user->ID);
		$id = $user->ID;
		if ($id != 0) {
			$array = array('status' => 1, 'msg' => "Successfully, logged in");
		} else if (is_wp_error($user)) {
			$error = $user->get_error_message();
			$r = str_replace("Lost your password?", "", $error);
			$array = array('status' => 0, 'msg' => $r);
		}
	}
}
/***********   Send OTP  *****************/
if ($DataType == 'fOtp') {

	$username = $_REQUEST['username'];
	$userQuery = "select ID, user_login, user_email from $PSY_USERS where user_login ='" . $username . "' OR user_email = '" . $username . "'";
	$getUser = $wpdb->get_row($userQuery);

	// genrate random key for email
	function generateRandomString($length = 30)
	{
		return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
	}

	//genrate random number for phone
	$ResetKeyPhone = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
	$encodeOTP = base64_encode($ResetKeyPhone);
	if (sizeof($getUser) != 0) {
		if (filter_var($username, FILTER_VALIDATE_INT)) {
			$username_type = "phone";
		} else if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
			$username_type = "email";
		}

		if ($username_type == "phone") {
			$UserID = $getUser->ID;
			$curDate = date('Y-m-d H:i:s');
			/**get sender id */
			$sender_id = senderID('PSY');
			/****end */
			include 'sendsmsapi.php';
			$mnt_message = "Your Code for reset password is " . $ResetKeyPhone;
			$encodedMessage = urlencode($mnt_message);
			$obj = new Sendsms();
			$var = $obj->sendMessage($sender_id, $username, $encodedMessage);

			$array = array('status' => 'success', 'msg' => '<span style="color:#009C2A";font-weight:bold;>Reset password code is sent in your phone</span>', 'user_type' => $username_type, 'user_id' => $UserID, 'otp' => $encodeOTP, 'verify_type' => 'phone');
			//$insertQuery = $wpdb->query("insert into $PSY_USER_RESET_PASSWORD_TABLE set user_id='$UserID', reset_key='$ResetKeyPhone', status='0', date='$curDate' ");
		}
	} else if (sizeof($getUser) == 0) {
		$array = array('status' => 'failed', 'msg' => '<span style="color:#FF0000";font-weight:bold;>No user found</span>');
	}
}

/********** Register New User ********** */
if ($DataType == 'reg') {

	$givenName = $_REQUEST['user_name'];
	$email_id = $_REQUEST['email_id'];
	$password = $_REQUEST['password'];
	$mobile = $_REQUEST['mobile'];
	$class_id = $_REQUEST['class_id'];
	$gender = $_REQUEST['gender'];
	$state_id = $_REQUEST['state_id'];
	$dob = date('Y-m-d', strtotime($_REQUEST['dob']));

	$user_id = wp_create_user($mobile, $password, $email_id);
	
	$inserTDetails = $wpdb->query("INSERT into $PSY_USERS_DETAILS set user_id='$user_id', first_name='$givenName', mobile_number='$mobile', email_address='$email_id', gender_id='$gender', state_id='$state_id', date_of_birth='$dob', current_education_level='$class_id', source='SP', source_id='0'");

	$creds = array();
	$creds['user_login'] = $mobile;
	$creds['user_password'] = $password;
	$creds['remember'] = true;

	$user = wp_signon($creds, false);
	wp_set_current_user($user->ID);
	if (is_wp_error($user)) {
		$error = $user->get_error_message();
		$array = array("status" => 0, "message" => $error);
	} else {

		/*********send welcome register message***** */
		include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
		sendWelecomeSMS($mobile,$givenName);

		/*********send welcome email********** */
		sendWelecomeEmail($email_id,$givenName);
		
		$array = array("status" => 1, "message" => "Successfully, registered");
	}
}
/*********** Register mobile OTP ******* */
if ($DataType == 'reg-otp') {
	$mobile = $_REQUEST['mobile'];
	$email = $_REQUEST['email'];

	if (username_exists($mobile)) {
		$array = array("status" => 0, "message" => "This number is already registered");
	} 
	else if (email_exists($email)) {
		$array = array("status" => 0, "message" => "This email id is already registered");		
	}
	else {

		/**get sender id */
		$sender_id = senderID('PSY');
		/****end */

		$reg_otp = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
		unset($_SESSION['REG_OTP']);
		session_start();
		$_SESSION['REG_OTP'] = $reg_otp;
		include '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/sendsmsapi.php';
		//$mnt_message = "Your OTP is ".$reg_otp." for acceptance of registration on Self Analyse. Do not share this OTP with anyone";
		//$mnt_message = "Dear User, OTP to register on Self Analyse is ".$reg_otp.". OTP is valid for 10 minutes.";
		$mnt_message = "Dear Student, OTP to register on Self Analyse is ".$reg_otp.". OTP is valid for 10 minutes. Team Self Analyse";
		$encodedMessage = urlencode($mnt_message);
		$obj = new Sendsms();
		$var = $obj->sendMessage($sender_id, $mobile, $encodedMessage);

		$array = array("status" => 1, "message" => "An otp is send to your mobile number");
	}
}

/********* Verify Regsiter OTP ********** */
if ($DataType == 'verify-reg-otp') {
	session_start();
	$ent_otp = $_REQUEST['ent_otp'];
	if ($ent_otp == $_SESSION['REG_OTP']) {
		$array = array("status" => 1, "message" => "Your number is verified now please submit your details");
	} else {
		$array = array("status" => 0, "message" => "Please enter correct OTP");
	}
}

/********* Check already registered ***** */
if ($DataType == 'check-number') {
	$mobile = $_REQUEST['mobile'];

	if (username_exists($mobile)) {
		$array = array("status" => 0, "message" => "This number is already registered");
	} else {
		$array = array("status" => 1, "message" => "Number Available");
	}
}

/***** check user for forgot password  *** */
if($DataType == 'forgot-user-check')
{
	$username = $_REQUEST['username'];

	if (username_exists($username)) {

		if (filter_var($username, FILTER_VALIDATE_INT)) {
			$stringType = "phone";
		} else if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
			$stringType = "email";
		}

		$user = get_user_by('login', $username);
      	$user_id = $user->ID;
		$frgt_otp = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
		unset($_SESSION['FORGOT_OTP']);
		session_start();
		$_SESSION['FORGOT_OTP'] = $frgt_otp;

		if($stringType == 'phone'){

			/**get sender id */
			$sender_id = senderID('PSY');
			/****end */

			include '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/sendsmsapi.php';
			//$mnt_message = $frgt_otp." is your OTP to verify your Forgotten Password Request for Self Analysis";
			// $mnt_message = "OTP to reset your password for Self Analyse is ".$frgt_otp.". If you haven't requested, kindly contact us on info@selfanalyse.com.";
			$mnt_message = "Dear Student, OTP to register on Self Analyse is ".$frgt_otp.". OTP is valid for 10 minutes. Team Self Analyse";
			$encodedMessage = urlencode($mnt_message);
			$obj = new Sendsms();
			$var = $obj->sendMessage($sender_id, $username, $encodedMessage);
			$array = array("status" => 0, "message" => "An OTP is send to your mobile..", "user_id" => $user_id);
		}
		else if($stringType == 'email'){
			/*********send welcome register message***** */
			include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
			sendOTPForgotEmail($username, $frgt_otp);

			$array = array("status" => 0, "message" => "An OTP is send to your email..", "user_id" => $user_id);
		}
		

	} else {
		$array = array("status" => 1, "message" => "No user found with this user name");
	}
}

/********** check send otp for forgot password ********** */
if($DataType == 'forgot-check-otp')
{
	session_start();
	$check_otp = $_REQUEST['check_otp'];
	if ($check_otp == $_SESSION['FORGOT_OTP']) {
		$array = array("status" => 1, "message" => "OTP is checked", "enter_otp"=>$check_otp);
	} else {
		$array = array("status" => 0, "message" => "Please enter correct OTP");
	}
}

/******* reset password **** */
if($DataType == 'reset-password')
{
	$new_password = $_REQUEST['new_password'];
	$user_id = $_REQUEST['user_id'];

	$user = get_user_by( 'ID', $user_id ); 
	$user_id = $user->ID;
	$user_login = $user->user_login;
	$user_data["ID"] = $user_id;
	$user_data["user_pass"] = $new_password;
	wp_update_user($user_data);

	$creds = array();
	$creds['user_login'] = $user_login;
	$creds['user_password'] = $new_password;
	$creds['remember'] = true;
	$user_session = wp_signon( $creds, false );
	//print_r($user_session);
	wp_set_current_user($user_session->ID);

	if (is_wp_error($user_session)) {
		$error = $user->get_error_message();
		$array = array("status" => 0, "message" => $error);
	} else {
		$array = array("status" => 1, "message" => "Password Reset Successfully");
	}
}
echo json_encode($array);