changed a lot
This commit is contained in:
@@ -3,10 +3,9 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<select name="salutation" id="salutation">
|
<select name="salutation" id="salutation">
|
||||||
<option disabled selected value="0" style="display:none">Anrede</option>
|
|
||||||
<option value="Frau">Frau</option>
|
<option value="Frau">Frau</option>
|
||||||
<option value="Herr">Herr</option>
|
<option value="Herr">Herr</option>
|
||||||
<option value="Person">Person</option>
|
<option selected value="Person">Person</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class DataHandler
|
|||||||
$stmtCities->bind_param("sss", null, $postalcode, $coty);
|
$stmtCities->bind_param("sss", null, $postalcode, $coty);
|
||||||
|
|
||||||
if ($stmtUser->execute() && $stmtCities->execute() && $stmtAddress->execute()) {
|
if ($stmtUser->execute() && $stmtCities->execute() && $stmtAddress->execute()) {
|
||||||
return true;
|
return $data;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const password = document.getElementById('password');
|
const password = document.getElementById('password');
|
||||||
const password2 = document.getElementById('password2');
|
const password2 = document.getElementById('password2');
|
||||||
|
|
||||||
password2.addEventListener('change', checkPassword);
|
password2.addEventListener('change', checkPassword);
|
||||||
|
|
||||||
const form = document.getElementById('marmeladenLadenRegisterForm');
|
const form = document.getElementById('marmeladenLadenRegisterForm');
|
||||||
form.addEventListener('submit', register);
|
form.addEventListener('submit', register);
|
||||||
|
|
||||||
@@ -15,16 +15,21 @@ async function register(event) {
|
|||||||
//create object with form data
|
//create object with form data
|
||||||
const data = {};
|
const data = {};
|
||||||
formData.forEach((value, key) => data[key] = value);
|
formData.forEach((value, key) => data[key] = value);
|
||||||
|
//log data on console
|
||||||
|
datastring = JSON.stringify(data);
|
||||||
|
console.log(data);
|
||||||
|
console.log(datastring);
|
||||||
//send data to php with Ajax
|
//send data to php with Ajax
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '../logic/serviceLogic.php',
|
url: '../logic/registerLogic.php',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {method: 'register', data: data},
|
data: datastring,
|
||||||
datatype: 'json',
|
cache: false,
|
||||||
|
datatype: 'text',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response === 'success') {
|
console.log(response);
|
||||||
window.location.replace('index.html');
|
if (response == 'success') {
|
||||||
|
window.location.href = '../index.html';
|
||||||
} else {
|
} else {
|
||||||
alert(response);
|
alert(response);
|
||||||
}
|
}
|
||||||
@@ -33,8 +38,6 @@ async function register(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function checkPassword() {
|
async function checkPassword() {
|
||||||
if (password.value != password2.value) {
|
if (password.value != password2.value) {
|
||||||
password2.setCustomValidity('Passwords do not match');
|
password2.setCustomValidity('Passwords do not match');
|
||||||
|
|||||||
46
logic/registerLogic.php
Normal file
46
logic/registerLogic.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
include($_SERVER['DOCUMENT_ROOT'] . '/logic/testinput.php');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'));
|
||||||
|
|
||||||
|
$username = testinput($data->email);
|
||||||
|
$password = password_hash(testinput($data->password), PASSWORD_DEFAULT);
|
||||||
|
$email = testinput($data->email);
|
||||||
|
$phone = testinput($data->phone);
|
||||||
|
$salutation = testinput($data->salutation);
|
||||||
|
$firstname = testinput($data->firstname);
|
||||||
|
$lastname = testinput($data->lastname);
|
||||||
|
$street = testinput($data->street);
|
||||||
|
$postalcode = testinput($data->postalcode);
|
||||||
|
$city = testinput($data->city);
|
||||||
|
$role = "customer";
|
||||||
|
|
||||||
|
registerUser($username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $city, $role);
|
||||||
|
|
||||||
|
function registerUser($username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $city, $role)
|
||||||
|
{
|
||||||
|
|
||||||
|
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
|
||||||
|
|
||||||
|
$sql2 = "INSERT IGNORE INTO `cities` (`postalcode`, `name`) VALUES (?,?)";
|
||||||
|
$sql = "INSERT INTO `user` (`username`, `password`, `email`, `phone`, `salutation`, `firstname`, `lastname`, `address`, `plz`, `role`) VALUES (?,?,?,?,?,?,?,?,?,?)";
|
||||||
|
|
||||||
|
|
||||||
|
$stmtUser = $db->prepare($sql);
|
||||||
|
$stmtCities = $db->prepare($sql2);
|
||||||
|
|
||||||
|
$stmtUser->bind_param("ssssssssss", $username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $role);
|
||||||
|
$stmtCities->bind_param("is", $postalcode, $city);
|
||||||
|
|
||||||
|
if ($stmtCities->execute() && $stmtUser->execute()) {
|
||||||
|
$response = "success";
|
||||||
|
} else {
|
||||||
|
$response = "failure";
|
||||||
|
}
|
||||||
|
$stmtUser->close();
|
||||||
|
$stmtCities->close();
|
||||||
|
$db->close();
|
||||||
|
|
||||||
|
echo $response;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user