CMXX - First testing

This commit is contained in:
“VeLiTi”
2025-03-07 15:07:15 +01:00
parent 5dd2973a26
commit cd0e04981c
81 changed files with 697 additions and 325 deletions

View File

@@ -6,7 +6,7 @@ defined(security_key) or exit;
// Defaults
// ---------------------------------------
$account = [
'account_id' => $_POST['account_id'] ?? '',
'account_id' => $_SESSION['account_id'] ?? '',
'email' => $_POST['email'] ?? '',
'first_name' => $_POST['first_name'] ?? '',
'last_name' => $_POST['last_name'] ?? '',
@@ -58,10 +58,12 @@ if (empty($_SESSION['cart'])) {
// Check if user is logged in
if (isset($_SESSION['account_loggedin'])) {
$stmt = $pdo->prepare('SELECT * FROM accounts WHERE id = ?');
$stmt->execute([ $_SESSION['account_id'] ]);
// Fetch the account from the database and return the result as an Array
$account = $stmt->fetch(PDO::FETCH_ASSOC);
$api_url = '/v2/identity/userkey='.$_SESSION['account_id'];
$account = ioAPIv2($api_url,'',$clientsecret);
if (!empty($account)){$account = json_decode($account,true);}
$account = $account[0];
//RESET ACCOUNT_ID
$account['account_id'] = $account['userkey'];
}
// Update discount code
@@ -119,14 +121,30 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
// If the user is already logged in
if (isset($_SESSION['account_loggedin'])) {
// Account logged-in, update the user's details
$stmt = $pdo->prepare('UPDATE accounts SET first_name = ?, last_name = ?, address_street = ?, address_city = ?, address_state = ?, address_zip = ?, address_country = ?, address_phone = ? WHERE id = ?');
$stmt->execute([ $_POST['first_name'], $_POST['last_name'], $_POST['address_street'], $_POST['address_city'], $_POST['address_state'], $_POST['address_zip'], $_POST['address_country'], $_POST['address_phone'], $_SESSION['account_id'] ]);
$account_id = $_SESSION['account_id'];
$payload = json_encode(
array(
"language" => $_SESSION['country_code'],
"first_name" => $_POST['first_name'],
"last_name" => $_POST['last_name'],
"address_street" => $_POST['address_street'],
"address_city" => $_POST['address_city'],
"address_state" => $_POST['address_state'],
"address_zip" => $_POST['address_zip'],
"address_country" => $_POST['address_country'],
"address_phone" => $_POST['address_phone'],
"userkey" => $_SESSION['account_id']), JSON_UNESCAPED_UNICODE);
$account_update = ioAPIv2('/v2/identity/',$payload,$clientsecret);
$account_update = json_decode($account_update,true);
$account_id = $account['account_id'] = $_SESSION['account_id'];
} else if (isset($_POST['email'], $_POST['password'], $_POST['cpassword']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) && !empty($_POST['password']) && !empty($_POST['cpassword'])) {
// User is not logged in, check if the account already exists with the email they submitted
$stmt = $pdo->prepare('SELECT id FROM accounts WHERE email = ?');
$stmt->execute([ $_POST['email'] ]);
if ($stmt->fetch(PDO::FETCH_ASSOC)) {
// Check if the account exists
$account = ioAPIv2('/v2/identity/email='.$_POST['email'],'',$clientsecret);
$account = json_decode($account,true);
if ($account) {
// Email exists, user should login instead...
$errors[] = $error_account_name;
}
@@ -139,16 +157,33 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
$errors[] = $error_account_password_match;
}
if (!$errors) {
// Hash the password
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
// Email doesnt exist, create new account
$stmt = $pdo->prepare('INSERT INTO accounts (email, password, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_phone) VALUES (?,?,?,?,?,?,?,?,?,?)');
$stmt->execute([ $_POST['email'], $password, $_POST['first_name'], $_POST['last_name'], $_POST['address_street'], $_POST['address_city'], $_POST['address_state'], $_POST['address_zip'], $_POST['address_country'], $_POST['address_phone'] ]);
$account_id = $pdo->lastInsertId();
$stmt = $pdo->prepare('SELECT * FROM accounts WHERE id = ?');
$stmt->execute([ $account_id ]);
// Fetch the account from the database and return the result as an Array
$account = $stmt->fetch(PDO::FETCH_ASSOC);
// Account doesnt exist, create new account
$payload = json_encode(
array(
"email" => $_POST['email'],
"password" => $_POST['password'],
"language" => $_SESSION['country_code'],
"first_name" => $_POST['first_name'],
"last_name" => $_POST['last_name'],
"address_street" => $_POST['address_street'],
"address_city" => $_POST['address_city'],
"address_state" => $_POST['address_state'],
"address_zip" => $_POST['address_zip'],
"address_country" => $_POST['address_country'],
"address_phone" => $_POST['address_phone']), JSON_UNESCAPED_UNICODE);
$account = ioAPIv2('/v2/identity/',$payload,$clientsecret);
$account= json_decode($account,true);
$account_id = $account['account_id'] = $account['accountID'];
if ($account && isset($account['accountID'])) {
//SEND VERIFICATION EMAIL
include dirname(__FILE__).'/custom/email/email_template_register.php';
$register_mail = $message;
send_mail_by_PHPMailer($account['identity'], $subject, $register_mail,'', '');
$register_error = 'Email send to verify your account';
}
}
} else if (account_required) {
$errors[] = $error_account;
@@ -159,7 +194,7 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
//Process checkout => add payment_method to checkout_input array
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$checkout_input['payment_method'] = $_POST['method'];
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Calculate shopping_cart based on session
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -205,7 +240,7 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
session_regenerate_id();
$_SESSION['account_loggedin'] = TRUE;
$_SESSION['account_id'] = $account_id;
$_SESSION['account_role'] = $account ? $account['role'] : 'Member';
$_SESSION['account_role'] = $account ? $account['profile'] : 0;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -218,10 +253,10 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Mollie = 0 ++++++++++++++++++++++++++++++++++++++++++++++++++
// Mollie = 3 ++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (mollie_enabled && $_POST['method'] == 0) {
if (mollie_enabled && $_POST['method'] == 3) {
try {
/*
@@ -290,7 +325,7 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a
// PayPal Payment = 1 +++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (paypal_enabled && $_POST['method'] == 'paypal') {
if (paypal_enabled && $_POST['method'] == 1) {
//Process Payment
require_once __DIR__."/lib/paypal/paypal.php";
@@ -356,7 +391,7 @@ $view .= '<p>'.$account_available.' <a href="'.url('index.php?page=myaccount').'
<div class="payment-methods">';
if (mollie_enabled){
$view .= ' <input id="mollie" type="radio" name="method" value="0" '. ((mollie_default)? 'checked':'') .'>
$view .= ' <input id="mollie" type="radio" name="method" value="3" '. ((mollie_default)? 'checked':'') .'>
<label for="mollie">
<img src="./custom/assets/iDEAL.png" style="width: 50px;" alt="'.$payment_method_1.'">
<img src="./custom/assets/bancontact.png" style="width: 50px;" alt="'.$payment_method_1.'">
@@ -420,7 +455,7 @@ $view .= '
<label for="address_phone">'.$shipping_phone.'</label>
<input type="text" value="'.htmlspecialchars($account['address_phone'], ENT_QUOTES).'" name="address_phone" id="address_phone" placeholder="'.$shipping_phone.'" class="form-field" required>
<input type="text" value="'.htmlspecialchars(($account['address_phone'] ?? ''), ENT_QUOTES).'" name="address_phone" id="address_phone" placeholder="'.$shipping_phone.'" class="form-field" required>
<label for="address_country">'.$shipping_country.'</label>
<select name="address_country" class="ajax-update form-field" required>';
@@ -462,7 +497,7 @@ $view .= ' </span>
foreach($shipping_methods as $method){
$view .= ' <div class="shipping-method">
<input type="radio" class="ajax-update" id="sm'.$method['id'].'" name="shipping_method" value="'.$method['id'].'" required'.($checkout_input['selected_shipment_method']==$method['id'] ? ' checked':'').'>
<input type="radio" class="ajax-update" id="sm'.$method['id'].'" name="shipping_method" value="'.$method['id'].'" required'.(($checkout_input['selected_shipment_method']==$method['id'] || count($shipping_methods) == 1) ? ' checked':'').'>
<label for="sm'.$method['id'].'">'.$method['name'].' ('.currency_code.''.number_format($method['price'], 2).')</label>
</div>';
}