/
Signup.php
83 lines (62 loc) · 2.18 KB
/
Signup.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
<?php
//Require Model
require "/Model/ModelFacade.php";
OnRequest();
function OnRequest()
{
$requestMethod = $_SERVER['REQUEST_METHOD'];
if ($requestMethod == "GET") {
SignupGet();
} else {
//loginPost("", "");
SignupPost();
}
}
function SignupGet()
{
if (isset($_GET['delAccount']))
$message = "Your Account has been successfully deleted";
include_once("/Views/Signup.html");
}
function SignupPost()
{
$username = htmlspecialchars($_POST["username"]);
$email = htmlspecialchars($_POST['email']);
$password = htmlspecialchars($_POST['password']);
$passwordConfirm = htmlspecialchars($_POST['passwordconfirm']);
//username validation
if (!ModelFacade::checkUsernameAvaiable($username))
$message = "Username: " . $username . " is not available";
else if (strlen($username) < 6)
$message = "username must be 6 or more characters";
else if (!preg_match("/^[a-zA-Z0-9]*$/", $username))
$message = "username must be alphanumeric";
//email validation
else if (!filter_var($email, FILTER_VALIDATE_EMAIL))
$message = $email . " is not a valid email address";
else if ($_POST["email"] == "" || $_POST["email"] == null)
$message = "email must not be empty";
else if (!ModelFacade::checkEmailAvaiable($email))
$message = "Email: " . $email . " has already been used to create an account.";
//password validation
else if (strlen($password) < 6)
$message = "password must be more then 6 characters";
else if ($password == "" || $password == null)
$message = "password must not be empty";
else if ($password != $passwordConfirm) {
$message = "passwords do not match";
} else {
//signup user
ModelFacade::signup($_POST["username"], $_POST["password"], $_POST['email']);
//log user in
ModelFacade::login($_POST["username"], $_POST["password"]);
//store that this is a new signup so user gets nice notification
$_SESSION['newsignup'] = true;
//redirect to index
header('Location: Index.php');
exit();
}
//
include_once("/Views/Signup.html");
}
?>