/
register.php
203 lines (182 loc) · 5.45 KB
/
register.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
session_start();
//INCLUDES
require_once("config.php");
require_once("db/connect.php");
require_once("classes/functions.php");
//USED CLASSES
require_once("classes/settings.php");
require_once("classes/user.php");
//LOGGED IN? / SESSION
require("inc/user.php");
//PAGE TITLE
$pagetitle = "Register";
//PAGE CODE
$pagecontent = "";
if ($loggedin == TRUE) {
$pagecontent .= '
<div class="notification red">
<p>You are already logged in.</p>
</div>';
} else {
$error['top'] = "";
$error['username'] = "";
$error['email'] = "";
$error['password'] = "";
$error['password2'] = "";
$fill['username'] = "";
$fill['email'] = "";
$isfilled = FALSE; //Is the form filled out? Setting default value.
$filled['username'] = FALSE; // Is it filled out right? Setting default value.
$filled['email'] = FALSE;
$filled['password'] = FALSE;
if (isset($_POST['username']) && $_POST['username'] != "") {
$fill['username'] = $_POST['username'];
if (strlen($_POST['username']) <= 3 || strlen($_POST['username']) >= 25) {
$error['top'] .= "<p>Your username must be between 3 and 25 characters.</p>";
$error['username'] = "Your username must be between 3 and 25 characters.";
} else {
$username = new user($sql, "username", $_POST['username']);
if ($username->load() == TRUE) {
$error['top'] .= "<p>The username is already taken.</p>";
$error['username'] = "The username is already taken.";
} else {
$filled['username'] = TRUE;
}
}
$isfilled = TRUE;
} else {
$error['top'] .= "<p>Your username must be between 3 and 25 characters.</p>";
$error['username'] = "Your username must be between 3 and 25 characters.";
}
if (isset($_POST['email']) && $_POST['email'] != "") {
$fill['email'] = $_POST['email'];
if (strlen($_POST['email']) <= 3 || strlen($_POST['email']) >= 150 || isMail($_POST['email']) == FALSE) {
$error['top'] .= "<p>Please enter a valid email.</p>";
$error['email'] = "Please enter a valid email.";
} else {
$username = new user($sql, "email", $_POST['email']);
if ($username->load() == TRUE) {
$error['top'] .= "<p>The email is already in use.</p>";
$error['email'] = "The email is already in use.";
} else {
$filled['email'] = TRUE;
}
}
$isfilled = TRUE;
} else {
$error['top'] .= "<p>Please enter a valid email.</p>";
$error['email'] = "Please enter a valid email.";
}
if (isset($_POST['password'])) {
if (strlen($_POST['password']) <= 6 || strlen($_POST['username']) >= 150) {
$error['top'] .= "<p>Please enter a password that is at least 6 characters.</p>";
$error['password'] = "Please enter a password that is at least 6 characters.";
} else {
if ($_POST['password'] != $_POST['password2']) {
$error['top'] .= "<p>Both passwords must be identical.</p>";
$error['password2'] = "Both passwords must be identical.";
} else {
$filled['password'] = TRUE;
}
}
$isfilled = TRUE;
} else {
$error['top'] .= "<p>Both passwords must be identical.</p>";
$error['password2'] = "Both passwords must be identical.";
}
if ($isfilled == TRUE && $filled['username'] == TRUE && $filled['email'] == TRUE && $filled['password'] == TRUE) {
$user = new user($sql, "username", $_POST['username']);
$user->email = $_POST['email'];
$user->membersince = currentTime();
$user->logLogin();
if ($user->changePW($_POST['password'])) {
if ($user->save()) {
$user->load();
$_SESSION['userid'] = $user->id;
$pagecontent .= '
<div class="notification green">
<p>Your account has been created.</p>
</div>';
} else {
$pagecontent .= '
<div class="notification red">
<p>Failed to save user.</p>
</div>';
}
} else {
$pagecontent .= '
<div class="notification red">
<p>Failed to save user.</p>
</div>';
}
} else {
if ($isfilled == TRUE) {
$pagecontent .= '
<div class="notification red">
' . $error['top'] . '
</div>';
} else {
$error['username'] = "";
$error['email'] = "";
$error['password'] = "";
$error['password2'] = "";
}
$pagecontent .= '
<form action="register.php" method="post">
<table class="register">
<tr>
<td>Username</td>
<td><input type="text" name="username" placeholder="Username" size="35" value="' . $fill['username'] . '"></td>
<td>' . $error['username'] . '</td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" placeholder="email@example.com" size="35" value="' . $fill['email'] . '"></td>
<td>' . $error['email'] . '</td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" placeholder="Password" size="35"></td>
<td>' . $error['password'] . '</td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" name="password2" placeholder="Password" size="35"></td>
<td>' . $error['password2'] . '</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register" size="35"> or <span class="cancel"><a href="index.php">cancel</a></span></td>
<td></td>
</tr>
</table>
</form>
';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include("inc/head.php"); ?>
</head>
<body>
<div class="wrapper">
<div class="header">
<?php require("inc/header.php"); ?>
</div>
<?php echo $userbar; ?>
<div class="content">
<h3>Register an account</h3>
<?php echo $pagecontent; ?>
</div>
<div class="footer">
<?php include("inc/footer.php"); ?>
</div>
</div>
</body>
</html>
<?php
require_once("db/disconnect.php");
?>