HEX
Server: Apache
System: Linux wyse1.wyseservers.com 4.18.0-553.124.4.el8_10.x86_64 #1 SMP Fri May 15 04:14:14 EDT 2026 x86_64
User: kochikidswysewor (1061)
PHP: 8.3.33
Disabled: NONE
Upload Files
File: /home/kochikidswysewor/public_html/wp-content/themes/children-charity-child/user_login.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;  
//Load Composer's autoloader
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
date_default_timezone_set('America/Los_Angeles');
include "../../../wp-load.php";


if ($_REQUEST["action"] === "") {
    echo "<script>alert('Invalid data!');window.location.href='" .
        get_site_url() .
        "'</script>";
}

function user_login_custom($username, $password)
{
    $user = wp_authenticate($username, $password);
    $creds['user_login'] = $username;
    $creds['user_password'] = $password;
    $creds['remember'] =$remember;
    wp_signon( $creds, false ); 
 		if(!is_wp_error($user)) {
	    $status = get_user_meta($user->ID, "user_status", true);
	    $user_role = $user->roles[0];
	    if ($status == "Inactive") {
	        echo "Your account has not been activated!, Please contact admin";
	        return false;
	    } else {
	        return $user_role;
	    }
	  }
	  else {
	  	echo "Username or Password invalid.";
	  	return false;
	  }
   
}

function isValidEmail($email)
{
    return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

function password_reset_by_email($email)
{
    //php mailer variables
    $admin_email = get_option("admin_email"); //admin email fetch
    $user = get_user_by("email", $email); //getting user information by email
    $user_id = $user->ID; //getting user ID
    if ($user_id) {
        $random_password = wp_generate_password(
            $length = 12,
            $include_standard_special_chars = false
        );
    } else {
        return false;
    }

    if ($user) {
        $body_ = "New password:" . $random_password;
        $body =
            '<table width="700px" cellpadding="0" cellspacing="0" style="width:700px;
	border-left:1px solid #171717; 
	border-top:1px solid #171717;
	font-family:Arial, Helvetica, sans-serif;
	font-size:13px;
	color:#000;
	margin:0 auto;">
  <tbody><tr style="background:#fff;">
    <td colspan="2" style="padding:0px !important;border-right:1px solid #171717;
	border-bottom:0px solid #171717;
	">
	
	<a href="'. get_site_url().'" title="Kochi Kids" style="font-family:Arial, Helvetica, sans-serif;
	font-size:13px;
	color:#000;
	text-decoration:underline;">
	<img src="'.get_stylesheet_directory_uri().'/img/mail-template.jpg" alt="Kochi Kids"></a>
</td>
  </tr>
 <tr>
    <td colspan="2" style="border-right:1px solid #171717;
	border-bottom:1px solid #171717;
	padding:5px;">    
     
     Hi, 
     <br>
      <br>
      Your password has been successfully been reset and following is your new password.<br>
    ' .
            $body_ .
            '  <br> <br>
   </td>
  </tr>  <tr>
		<td colspan="2" class="footer-template" style="background:#d13777;
	text-align:center;border-right:1px solid #171717;
	border-bottom:1px solid #171717;
	padding:5px;"><a href="'. get_site_url().'" target="_blank" title="Kochi Kids" style="color:#fff ; 
	text-align:center;
	text-decoration:none !important;">Kochi Kids</a></td>
	  </tr>
	</tbody></table>';

    $subject = "Kochi Kids - Password Reset";
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    // $headers.= "From:".$this->admin_mailto."\r\n";
    $headers .= "From: Kochi Kids <" . $admin_email . "> \r\n";
    //$send = wp_mail($email, $subject, $body, $headers);

    $to = $email;
    //$body ="test mail";
    $from_mail = $admin_email;
    $mail1 = new PHPMailer(true);
        try {
            //Server settings
            //$mail1->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
            $mail1->isSMTP();                                            //Send using SMTP
            $mail1->Host       = 'mail.kochikids.org';                     //Set the SMTP server to send through
            $mail1->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail1->Username   = 'info@kochikids.org';                     //SMTP username
            $mail1->Password   = '{iXTZ%J%#RP8';                              //SMTP password
            $mail1->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
            $mail1->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
            //Recipients
            $mail1->setFrom('info@kochikids.org');
            $mail1->addAddress($to);     //Add a recipient
            if($from_mail){
                $mail1->addReplyTo($from_mail);
            }
            $mail1->isHTML(true);
            $mail1->Subject = $subject;
            $mail1->MsgHTML($body);
            //$mail1->Body    = $body;
            $send = $mail1->send();
        }catch (Exception $e) {
             echo "Message could not be sent. Mailer Error: {$mail1->ErrorInfo}"; exit;
        }
        if ($send) {
            wp_update_user(["ID" => $user_id, "user_pass" => $random_password]);
            return true;
        }
    }
}

if ($_REQUEST["action"] == "add") {
    $user_email = $_POST["user_email"];
    $user_name = $_POST["user_name"];
    $user_pass = $_POST["user_pass"];
    $user_phone = $_POST["user_phone"];
    $user_role = $_POST["user_role"];
    $user_address = $_POST["user_address"];
    $status = ($user_role == 'agent') ? "Inactive" : "Active";

    $array = [];
    $array = $_POST;
    unset($array["user_name"]);
    unset($array["user_pass"]);
    unset($array["user_email"]);
    if ($user_name != "" && $user_email != "" && $user_pass != "") {
        $exists = email_exists($user_email);
        $username = sanitize_user( $_POST['user_name'] );
        if ( username_exists( $username ) || $exists) {
        	echo "Username or Email Already in use";
        } 
         else {
            if (isValidEmail($user_email)) {
                $admin_email = get_option("admin_email"); //admin email fetch
           
                    $body_ = "Kochi Kids - New Account";
                    $body =
                        '<table width="700px" cellpadding="0" cellspacing="0" style="width:700px;
                border-left:1px solid #171717; 
                border-top:1px solid #171717;
                font-family:Arial, Helvetica, sans-serif;
                font-size:13px;
                color:#000;
                margin:0 auto;">
              <tbody><tr style="background:#fff;">
                <td colspan="2" style="padding:0px !important;border-right:1px solid #171717;
                border-bottom:0px solid #171717;
                ">
                
                <a href="'. get_site_url().'" title="Kochi Kids" style="font-family:Arial, Helvetica, sans-serif;
                font-size:13px;
                color:#000;
                text-decoration:underline;">
                <img src="'.get_stylesheet_directory_uri().'/img/mail-template.jpg" alt="Kochi Kids"></a>
            </td>
              </tr>
             <tr>
                <td colspan="2" style="border-right:1px solid #171717;
                border-bottom:1px solid #171717;
                padding:5px;">    
                 
                 Hi, 
                 <br>
                  <br>
                  Thank You, You have been successfully registered.You can login to your account once admin is approved<br>                         
                <br> <br>
               </td>
              </tr>  <tr>
                    <td colspan="2" class="footer-template" style="background:#d13777;
                text-align:center;border-right:1px solid #171717;
                border-bottom:1px solid #171717;
                padding:5px;"><a href="'. get_site_url().'" target="_blank" title="Kochi Kids" style="color:#fff ; 
                text-align:center;
                text-decoration:none !important;">Kochi Kids</a></td>
                  </tr>
                </tbody></table>';

                    $subject = "Kochi Kids - New Account";
                    $headers = "MIME-Version: 1.0\r\n";
                    $headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
                    $headers .= "From: Kochi Kids <" . $admin_email . "> \r\n";

                    $to = $user_email;
                    $subject = 'Kochi Kids - New Account';
                    $from_mail = $admin_email;
                    $mail1 = new PHPMailer(true);
                        try {
                            //Server settings
                            //$mail1->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
                            $mail1->isSMTP();                                            //Send using SMTP
                            $mail1->Host       = 'mail.kochikids.org';                     //Set the SMTP server to send through
                            $mail1->SMTPAuth   = true;                                   //Enable SMTP authentication
                            $mail1->Username   = 'info@kochikids.org';                     //SMTP username
                            $mail1->Password   = '{iXTZ%J%#RP8';                              //SMTP password
                            $mail1->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
                            $mail1->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
                            //Recipients
                            $mail1->setFrom('info@kochikids.org');
                            $mail1->addAddress($to);     //Add a recipient
                            if($from_mail){
                                $mail1->addReplyTo($from_mail);
                            }
                            $mail1->isHTML(true);
                            $mail1->Subject = $subject;
                            $mail1->MsgHTML($body);
                            //$mail1->Body    = $body;
                            $send = $mail1->send();
                        }catch (Exception $e) {
                             echo "Message could not be sent. Mailer Error: {$mail1->ErrorInfo}"; exit;
                        }

                    //$send = wp_mail($user_email, $subject, $body, $headers);
                    if ($send) {
                        $userdata = [
                            "user_login" => $user_name,
                            "first_name" => $user_name,
                            "user_email" => $user_email,
                            "user_pass" => $user_pass,
                            "role" => $user_role,
                        ];

                    $user_id = wp_insert_user(wp_slash($userdata));
                    update_field("phone_number", $user_phone, "user_" . $user_id);
                    update_field("address", $user_address, "user_" . $user_id);
                    update_field("user_status", $status, "user_" . $user_id);

                    if ($user_id) {
                        foreach ($array as $key => $value) {
                            update_user_meta($user_id, $key, $value);
                        }
                        echo "1";
                    } else {
                        echo 0;
                    }
                                return true;
                }
                    



            }
        }
    }
} elseif ($_REQUEST["action"] == "reset") {
    $user_email = $_POST["reset_user_email"];

    if ($user_email != "") {
        if (isValidEmail($user_email)) {
            if (password_reset_by_email($user_email) == true) {
                echo "1";
            } else {
                echo "Email address not found!";
            }
        }
    } else {
        echo "Enter email address";
    }
} elseif ($_REQUEST["action"] == "login") {
    $user_name = $_POST["user_name"];
    $user_pass = $_POST["user_pass"];
    if ($user_name != "" && $user_pass != "") {
        $result = user_login_custom($user_name, $user_pass);
        echo $result;exit;
        // return $result;
    }
} elseif ($_REQUEST["action"] == "logout") {
    wp_logout();
    header("location:" . get_bloginfo('wpurl'));
}