/
registration.php
103 lines (79 loc) · 2.76 KB
/
registration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
ob_start();
session_start();
use src\ProjectBrood\business\UsersBusiness;
use Doctrine\Common\ClassLoader;
use src\ProjectBrood\exceptions\RegistratieMisluktException;
use src\ProjectBrood\exceptions\GebruikerBestaatException;
use src\ProjectBrood\exceptions\OngelijkeWachtwoordException;
use src\ProjectBrood\exceptions\AllFieldsAreRequiredException;
if (isset($_POST['register_btn']))
{
require_once'Doctrine/Common/ClassLoader.php';
$classLoader = new ClassLoader("src");
$classLoader->register();
$userVoornaam = trim(strip_tags($_POST['register_name']));
$userFamilienaam = trim(strip_tags($_POST['register_surname']));
$userEmail = filter_var($_POST['register_email'], FILTER_VALIDATE_EMAIL);
$userPassword = trim(htmlspecialchars($_POST['register_password']));
$userPasswordRt = trim(htmlspecialchars($_POST['register_password_rt']));
$userEmailHash = md5(date('Y-m-d H:i:s'));
try{
/**
* Check if all fields are filled.
* todo: Need to add a better validation in the future, like allowing only strings etc
*/
if(empty($userVoornaam) || empty($userFamilienaam) || empty($userEmail) || empty($userPassword) || empty($userPasswordRt)) throw new AllFieldsAreRequiredException();
/**
* Create user object
*/
$obj = new UsersBusiness();
/**
* Check by email if user exists
*/
$userControle = $obj->zoekGebruikerMetEmail($userEmail);
if(!empty($userControle)) throw new GebruikerBestaatException();
/**
* Check both passwords are identical to each other
*/
if($userPassword !== $userPasswordRt) throw new OngelijkeWachtwoordException();
/**
* Hash password
*/
$userPassword = $obj->hashPassword($userPassword);
/**
* Create new user
*/
$userRegistration = $obj->creerGebruiker($userVoornaam, $userFamilienaam, $userEmail, $userPassword, $userEmailHash);
if(!isset($userRegistration)) throw new RegistratieMisluktException();
/**
* Send verification email
*/
$obj->sendVerificationEmail($userVoornaam, $userEmail, $userEmailHash);
echo md5(date('Y-m-d H:i:s'));
}
catch(RegistratieMisluktException $e)
{
/**
* todo Foutmelding in een variabele steken
*/
echo "Registratie mislukt";
}
catch(GebruikerBestaatException $e)
{
echo "Gebruiker bestaat al";
}
catch(OngelijkeWachtwoordException $e)
{
echo "Wachtwoorden moeten identiek zijn";
}
catch(AllFieldsAreRequiredException $e)
{
echo "Alle velden moeten ingevuld zijn";
}
}
else
{
header('Location: index.php');
}
ob_flush();