added logic / Form stuff
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<input type="text" class="form-control" name="zip" id="zip" placeholder="PLZ" required>
|
<input type="text" class="form-control" name="postalcode" id="postalcode" placeholder="PLZ" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="city" id="city" placeholder="Stadt" required>
|
<input type="text" class="form-control" name="city" id="city" placeholder="Stadt" required>
|
||||||
@@ -31,7 +31,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<input type="text" class="form-control" name="country" id="country" placeholder="Land" required>
|
<select name="country" id="country">
|
||||||
|
<option disabled selected value="" style="display:none">Land</option>
|
||||||
|
<option value="Frau">Österreich</option>
|
||||||
|
<option value="Herr">Deutschland</option>
|
||||||
|
<option value="Person">Schweiz</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -60,3 +65,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="../js/registration.js"></script>
|
||||||
@@ -4,20 +4,21 @@ include($_SERVER['DOCUMENT_ROOT'] . '/logic/testinput.php');
|
|||||||
|
|
||||||
class DataHandler
|
class DataHandler
|
||||||
{
|
{
|
||||||
public function registerUser($username, $password, $email, $phone, $salutation, $firstname, $lastname, $role, $street, $streetnumber, $postalcode, $country)
|
public function registerUser($data)
|
||||||
{
|
{
|
||||||
$username = testinput($username);
|
$username = testinput($data->username);
|
||||||
$password = testinput($password);
|
$password = testinput($data->password);
|
||||||
$email = testinput($email);
|
$email = testinput($data->email);
|
||||||
$phone = testinput($phone);
|
$phone = testinput($data->phone);
|
||||||
$salutation = testinput($salutation);
|
$salutation = testinput($data->salutation);
|
||||||
$firstname = testinput($firstname);
|
$firstname = testinput($data->firstname);
|
||||||
$lastname = testinput($lastname);
|
$lastname = testinput($data->lastname);
|
||||||
$role = testinput($role);
|
$street = testinput($data->street);
|
||||||
$street = testinput($street);
|
$streetnumber = testinput($data->streetnumber);
|
||||||
$streetnumber = testinput($streetnumber);
|
$postalcode = testinput($data->postalcode);
|
||||||
$postalcode = testinput($postalcode);
|
$country = testinput($data->country);
|
||||||
$country = testinput($country);
|
|
||||||
|
$password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
|
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
|
||||||
|
|
||||||
|
|||||||
19
js/app.js
Normal file
19
js/app.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('#mmlMainContent').load('../components/homepage.html');
|
||||||
|
$('#top_nav_bar').load('../components/top_nav.html');
|
||||||
|
$('#main_nav_bar').load('../components/main_nav.html', function () {
|
||||||
|
var _a, _b, _c;
|
||||||
|
(_a = document.getElementById('registerLink')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', function () {
|
||||||
|
$('#mmlMainContent').load('../components/register.html');
|
||||||
|
});
|
||||||
|
(_b = document.getElementById('homeLink')) === null || _b === void 0 ? void 0 : _b.addEventListener('click', function () {
|
||||||
|
$('#mmlMainContent').load('../components/homepage.html');
|
||||||
|
});
|
||||||
|
(_c = document.getElementById('loginLink')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', function () {
|
||||||
|
$('#mmlMainContent').load('../components/login.html');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#marmeladenladen_footer').load('../components/footer.html');
|
||||||
|
$('#marmeladenladen_search').load('../components/modal.html');
|
||||||
|
});
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#mmlMainContent').load('../components/homepage.html');
|
$('#mmlMainContent').load('../components/homepage.html');
|
||||||
$('#top_nav_bar').load('../components/top_nav.html');
|
$('#top_nav_bar').load('../components/top_nav.html');
|
||||||
@@ -14,7 +12,6 @@ $(document).ready(function() {
|
|||||||
$('#mmlMainContent').load('../components/login.html');
|
$('#mmlMainContent').load('../components/login.html');
|
||||||
},);
|
},);
|
||||||
});
|
});
|
||||||
$('#mmlMainContent').load('../components/ftProducts.html');
|
|
||||||
$('#marmeladenladen_footer').load('../components/footer.html');
|
$('#marmeladenladen_footer').load('../components/footer.html');
|
||||||
$('#marmeladenladen_search').load('../components/modal.html');
|
$('#marmeladenladen_search').load('../components/modal.html');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,41 +1,42 @@
|
|||||||
const email = document.getElementById('email');
|
|
||||||
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);
|
||||||
|
|
||||||
|
async function register(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
function register() {
|
//check password with checkPassword function
|
||||||
|
if (checkPassword()) {
|
||||||
|
//get form data
|
||||||
|
const formData = new FormData(form);
|
||||||
|
//create object with form data
|
||||||
|
const data = {};
|
||||||
|
formData.forEach((value, key) => data[key] = value);
|
||||||
|
|
||||||
|
//send data to php with Ajax
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'php/registration.php',
|
url: '../logic/serviceLogic.php',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {method: 'register', data: data},
|
||||||
email: email.value,
|
datatype: 'json',
|
||||||
password: password.value,
|
success: function (response) {
|
||||||
password2: password2.value
|
if (response === 'success') {
|
||||||
},
|
window.location.replace('index.html');
|
||||||
success: function (data) {
|
} else {
|
||||||
if (data == 'success') {
|
alert(response);
|
||||||
window.location.href = 'index.html';
|
}
|
||||||
} else {
|
|
||||||
alert(data);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var formData = new FormData(form);
|
|
||||||
const jSONdata = JSON.stringify(Object.fromEntries(formData));
|
|
||||||
|
|
||||||
//print elements of jSONdata
|
|
||||||
console.log(jSONdata);
|
|
||||||
|
|
||||||
|
|
||||||
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');
|
||||||
return false;
|
return false;
|
||||||
@@ -44,13 +45,3 @@ function checkPassword() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkemail() {
|
|
||||||
if (email.value != '') {
|
|
||||||
email.setCustomValidity('');
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
email.setCustomValidity('Email is required');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
46
logic/serviceLogic.php
Normal file
46
logic/serviceLogic.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
include( $_SERVER['DOCUMENT_ROOT'] . '/logic/userLogic.php' );
|
||||||
|
|
||||||
|
$param = "";
|
||||||
|
$method = "";
|
||||||
|
|
||||||
|
isset($_GET["method"]) ? $method = $_GET["method"] : false;
|
||||||
|
isset($_GET["param"]) ? $param = $_GET["param"] : false;
|
||||||
|
|
||||||
|
$logic = new UserLogic();
|
||||||
|
$result = $logic->handleUserRequests($method, $param);
|
||||||
|
if ($result == null) {
|
||||||
|
response("GET", 400, null);
|
||||||
|
} else {
|
||||||
|
response("GET", 200, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function response($method, $status, $data)
|
||||||
|
{
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
switch ($method) {
|
||||||
|
case 'GET':
|
||||||
|
http_response_code($status);
|
||||||
|
echo json_encode($data);
|
||||||
|
break;
|
||||||
|
case 'POST':
|
||||||
|
http_response_code($status);
|
||||||
|
echo json_encode($data);
|
||||||
|
break;
|
||||||
|
case 'PUT':
|
||||||
|
http_response_code($status);
|
||||||
|
echo json_encode($data);
|
||||||
|
break;
|
||||||
|
case 'DELETE':
|
||||||
|
http_response_code($status);
|
||||||
|
echo json_encode($data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(array("message" => "Invalid method"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user