116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
require 'webdata/init.php';
|
|
|
|
$returnToPage = "./";
|
|
if(isset($_POST['referrerPage'])){
|
|
$returnToPage = $_POST['referrerPage'];
|
|
}
|
|
else if(isset($_SERVER['HTTP_REFERER'])){
|
|
$returnToPage = $_SERVER['HTTP_REFERER'];
|
|
}
|
|
if(stristr($returnToPage, "login.php") || stristr($returnToPage, "register.php")){
|
|
$returnToPage = "./";
|
|
}
|
|
|
|
if(isset($_POST) && !empty($_POST)) {
|
|
$db = database();
|
|
$data = [];
|
|
|
|
foreach ($_POST as $key => $value) {
|
|
if (($data[$key] = filter($value)) === false) {
|
|
print_r($value);
|
|
echo "Failed to sanitize: `" . $key . "`: " . $value . " \t-\t type: " . gettype($value) . "\n";
|
|
}
|
|
}
|
|
|
|
$userEmail = $data['newEmail'];
|
|
$userPass = $data['newPassword'];
|
|
$userName = $data['newName'] ?? '';
|
|
|
|
if(strlen($userPass) < 6){
|
|
$err[] = "Password is too short. Password needs to be at least 6 characters!";
|
|
}
|
|
else if(strlen($userPass) > 30){
|
|
$err[] = "Password is too long. Max length is set to 30 characters. If you believe it should be higher please contact the developers.";
|
|
}
|
|
|
|
if(strlen($userEmail) > 220){
|
|
$err[] = "Your email-address is too long. Can you please register with another email?";
|
|
}
|
|
|
|
if(strlen($userName) > 200){
|
|
$err[] = "Your name seems to be too large to fit this system. Maybe you can short it somehow?";
|
|
}
|
|
|
|
if(empty($err)){
|
|
// HASH PASSWORD
|
|
$newPass = PwdGen($userPass, true);
|
|
|
|
$createUserSQL = "INSERT INTO user SET full_name = '$userName', user_email = '$userEmail', pwd = '$newPass';";
|
|
if($db->query($createUserSQL)){
|
|
$newID = $db->insert_id;
|
|
$updateUserSQL = "UPDATE user SET md5_id = '".md5($newID)."' WHERE user_id = '$newID';";
|
|
$db->query($updateUserSQL);
|
|
|
|
header("Location: login.php?thank");
|
|
}
|
|
else {
|
|
$err[] = "Something went wrong:<br>".$db->error;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
?><!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<?=getHtmlHeaders();?>
|
|
<title>Register - Grocery Assist</title>
|
|
</head>
|
|
<body id='plan'>
|
|
<?php include 'webdata/navbar.php'; ?>
|
|
|
|
<div class='container-md' style="max-width: 720px;">
|
|
|
|
<h1 class="headline text-center">Register</h1>
|
|
<br>
|
|
|
|
<?php if(!empty($err)){
|
|
foreach($err as $e){
|
|
echo "<div class='alert alert-danger' role='alert'>$e</div>";
|
|
}
|
|
echo "<br>";
|
|
}
|
|
?>
|
|
|
|
<form action="register.php" method="POST" class="row">
|
|
<input type="hidden" name="referrerPage" value="<?=$returnToPage;?>">
|
|
<div class="col-md-6">
|
|
<label for="newEmail" class="form-label">Email*</label>
|
|
<input type="email" class="form-control" id="newEmail" name="newEmail" maxlength="220" required value="<?= $data['newEmail'] ?? '';?>">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label for="newPassword" class="form-label">Password*</label>
|
|
<input type="password" class="form-control" id="newPassword" name="newPassword" minlength="6" maxlength="30" required>
|
|
</div>
|
|
<div class="col-12">
|
|
<label for="newName" class="form-label">Full name</label>
|
|
<input type="text" class="form-control" id="newName" name="newName" maxlength="200" value="<?= $data['newName'] ?? '';?>">
|
|
</div>
|
|
<div class="col-12">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="gridCheck" required>
|
|
<label class="form-check-label" for="gridCheck">
|
|
I will read the Terms and Conditions when they are published.
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-12">
|
|
<button type="submit" class="btn btn-primary">Sign up</button>
|
|
</div>
|
|
</form>
|
|
<p>Already have an account? <a href="login.php">Login</a></p>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|