-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNewUser.php
120 lines (115 loc) · 4.63 KB
/
NewUser.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
session_start();
if (isset($_SESSION["user"])) {
$user = $_SESSION["user"];
header("Location: MyAlbums.php");
exit();
}
include("./common/header.php");
include_once 'EntityClassLib.php';
include_once('Functions.php');
$userIdErr = $nameErr = $phoneNumberErr = $passwordErr = $rePasswordErr = "";
extract($_POST);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
$hashedPassword = hash("sha256", $password);
if (isset($clearBtn)) {
$userId = $name = $phoneNumber = $password = $rePassword = "";
}
if (isset($submitBtn)) {
$userIdErr = ValidateUserId($userId);
$nameErr = ValidateName($name);
$phoneNumberErr = ValidatePhone($phoneNumber);
$passwordErr = ValidatePassword($password);
$rePasswordErr = ValidateRePassword($password, $rePassword);
if (empty($userIdErr) && empty($nameErr) && empty($phoneNumberErr) && empty($passwordErr) && empty($rePasswordErr)) {
try {
addNewUser($userId, $name, $phoneNumber, $hashedPassword);
$user = getUserByIdAndPassword($userId, $hashedPassword);
} catch (Exception $e) {
die("The system is currently not available, try again later");
}
if ($user != null) {
$_SESSION['user'] = $user;
header("Location: MyAlbums.php");
exit();
}
}
}
?>
<div class="container">
<br>
<h1>Sign Up</h1>
<br>
<p>All fields are required</p>
<br>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="row form-group">
<label for="userId" class="col-md-3 col-form-label">User ID: </label>
<div class="col-md-4">
<input type="text" class="form-control" id="userId" name="userId" value="<?php echo isset($userId) ? $userId : ''; ?>">
</div>
<?php
if (!empty($userIdErr)) {
echo "<div class=\"text-danger col-md-5\">
$userIdErr
</div>";
}
?>
</div>
<div class="row form-group">
<label for="name" class="col-md-3 col-form-label">Name: </label>
<div class="col-md-4">
<input type="text" class="form-control" id="name" name="name" value="<?php echo isset($name) ? $name : ''; ?>">
</div>
<?php
if (!empty($nameErr)) {
echo "<div class=\"text-danger col-md-5\">
$nameErr
</div>";
}
?>
</div>
<div class="row form-group">
<label for="phoneNumber" class="col-md-3 col-form-label">Phone Number <small>(nnn-nnn-nnnn)</small>: </label>
<div class="col-md-4">
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="<?php echo isset($phoneNumber) ? $phoneNumber : ''; ?>">
</div>
<?php
if (!empty($phoneNumberErr)) {
echo "<div class=\"text-danger col-md-5\">
$phoneNumberErr
</div>";
}
?>
</div>
<div class="row form-group">
<label for="password" class="col-md-3 col-form-label">Password: </label>
<div class="col-md-4">
<input type="password" class="form-control" id="password" name="password" value="<?php echo isset($password) ? $password : ''; ?>">
</div>
<?php
if (!empty($passwordErr)) {
echo "<div class=\"text-danger col-md-5\">
$passwordErr
</div>";
}
?>
</div>
<div class="row form-group">
<label for="rePassword" class="col-md-3 col-form-label">Password Again: </label>
<div class="col-md-4">
<input type="password" class="form-control" id="rePassword" name="rePassword" value="<?php echo isset($rePassword) ? $rePassword : ''; ?>">
</div>
<?php
if (!empty($rePasswordErr)) {
echo "<div class=\"text-danger col-md-5\">
$rePasswordErr
</div>";
}
?>
</div>
<button type="submit" name="submitBtn" class="btn btn-primary">Submit</button>
<button type="submit" name="clearBtn" class="btn btn-danger">Clear</button>
</form>
</div>
<?php include('./common/footer.php'); ?>