CMXX - Myaccount
This commit is contained in:
@@ -3,18 +3,22 @@
|
||||
defined(security_key) or exit;
|
||||
// User clicked the "Login" button, proceed with the login process... check POST data and validate email
|
||||
if (isset($_POST['login'], $_POST['email'], $_POST['password']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
// Check if the account exists
|
||||
$stmt = $pdo->prepare('SELECT * FROM accounts WHERE email = ?');
|
||||
$stmt->execute([ $_POST['email'] ]);
|
||||
$account = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
// If account exists verify password
|
||||
if ($account && password_verify($_POST['password'], $account['password'])) {
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// LOGIN CONSUMER
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$payload = json_encode(array("login" => "consumer", "email" => $_POST['email'], "password" => $_POST['password']), JSON_UNESCAPED_UNICODE);
|
||||
$account = ioAPIv2('/v2/identity/',$payload,$clientsecret);
|
||||
$account= json_decode($account,true);
|
||||
|
||||
if ($account && isset($account['accountID'])) {
|
||||
// User has logged in, create session data
|
||||
session_regenerate_id();
|
||||
$_SESSION['account_loggedin'] = TRUE;
|
||||
$_SESSION['account_id'] = $account['id'];
|
||||
$_SESSION['account_role'] = $account['role'];
|
||||
$_SESSION['account_id'] = $account['accountID'];
|
||||
$_SESSION['account_role'] = $account['profile'];
|
||||
$products_in_cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];
|
||||
|
||||
if ($products_in_cart) {
|
||||
// user has products in cart, redirect them to the checkout page
|
||||
header('Location: ' . url('index.php?page=checkout'));
|
||||
@@ -32,9 +36,10 @@ $register_error = '';
|
||||
// User clicked the "Register" button, proceed with the registration process... check POST data and validate email
|
||||
if (isset($_POST['register'], $_POST['email'], $_POST['password'], $_POST['cpassword']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
// Check if the account exists
|
||||
$stmt = $pdo->prepare('SELECT * FROM accounts WHERE email = ?');
|
||||
$stmt->execute([ $_POST['email'] ]);
|
||||
$account = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$account = ioAPIv2('/v2/identity/email='.$_POST['email'],'',$clientsecret);
|
||||
$account = json_decode($account,true);
|
||||
|
||||
if ($account) {
|
||||
// Account exists!
|
||||
$register_error = $error_myaccount_exists;
|
||||
@@ -46,25 +51,19 @@ if (isset($_POST['register'], $_POST['email'], $_POST['password'], $_POST['cpass
|
||||
$register_error = $error_account_password_rules;
|
||||
} else {
|
||||
// Account 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 (?,?,"","","","","","","","")');
|
||||
// Hash the password
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$stmt->execute([ $_POST['email'], $password ]);
|
||||
$account_id = $pdo->lastInsertId();
|
||||
// Automatically login the user
|
||||
session_regenerate_id();
|
||||
$_SESSION['account_loggedin'] = TRUE;
|
||||
$_SESSION['account_id'] = $account_id;
|
||||
$_SESSION['account_role'] = 'Member';
|
||||
$products_in_cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];
|
||||
if ($products_in_cart) {
|
||||
// User has products in cart, redirect them to the checkout page
|
||||
header('Location: ' . url('index.php?page=checkout'));
|
||||
} else {
|
||||
// Redirect the user back to the same page, they can then see their order history
|
||||
header('Location: ' . url('index.php?page=myaccount'));
|
||||
$payload = json_encode(array("login" => "consumer", "email" => $_POST['email'], "password" => $_POST['password'], "language" => $_SESSION['country_code']), JSON_UNESCAPED_UNICODE);
|
||||
$account = ioAPIv2('/v2/identity/',$payload,$clientsecret);
|
||||
$account= json_decode($account,true);
|
||||
|
||||
if ($account && isset($account['accountID'])) {
|
||||
//SEND VERIFICATION EMAIL
|
||||
ob_start();
|
||||
include dirname(__FILE__).'/custom/email/email_template_register.php';
|
||||
$register_mail= ob_get_clean();
|
||||
|
||||
send_mail_by_PHPMailer($_POST['email'], $subject, $register_mail,'', '');
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Determine the current tab page
|
||||
|
||||
Reference in New Issue
Block a user