-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewAccount.php
More file actions
82 lines (69 loc) · 2.32 KB
/
newAccount.php
File metadata and controls
82 lines (69 loc) · 2.32 KB
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
<?php
require_once('core/includes/require.php');
/* redir checks */
// if(!isset($_SESSION['userId']) || !$em->find('LoginForm\Users\User', $_SESSION['userId'])) {
// header('location: login.php');
// exit(0);
// }
/* variables */
$username = isset($_POST['txtName'])? $_POST['txtName'] : '';
$errName = '';
$errPass = '';
$errRePass = '';
/* Load template */
$page = new LoginForm\Includes\Page('newAccount');
/* Actions */
if(isset($_POST['submit'])) {
$allOk = true;
$pass = $_POST['txtPass'];
$repass = $_POST['txtRePass'];
if($username == '') {
$errName = 'Please fill in a username';
$allOk = false;
} else {
if(strlen($username) > 20) {
$errName = 'Please limit your username to 20 characters';
$allOk = false;
} else {
if($em->getRepository('LoginForm\Users\User')->findByName($username)) {
$errName = 'this username is already taken';
$allOk = false;
}
}
}
if($pass == '') {
$errPass = 'Please fill in a password';
$allOk = false;
} else {
if(strlen($pass) > 12) {
$errPass = 'Please limit your password to 12 characters';
$allOk = false;
} else {
if($repass == '') {
$errRePass = 'Please re-enter the password';
$allOk = false;
} else {
if($pass != $repass) {
$errPass = 'The passwords did not match';
$allOk = false;
}
}
}
}
if($allOk) {
list($password, $salt) = $userPassGen->encrypt($pass);
$em->persist(new LoginForm\Users\User($username, $password, $salt));
$em->flush();
header('location: index.php');
exit(0);
}
}
/* parse template */
$page->setVars(array(
'action' => $_SERVER['PHP_SELF'],
'username' => $username,
'errUsername' => $errName,
'errPass' => $errPass,
'errRePass' => $errRePass
));
echo $page->render();