forked from tad0616/photos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createuser.php
65 lines (43 loc) · 2.33 KB
/
createuser.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
<?php
require 'includes/functions.php';
include_once 'config.php';
//Pull username, generate new ID and hash password
$newid = uniqid(rand(), false);
$newuser = $_POST['newuser'];
$newpw = password_hash($_POST['password1'], PASSWORD_DEFAULT);
$pw1 = $_POST['password1'];
$pw2 = $_POST['password2'];
//Enables moderator verification (overrides user self-verification emails)
if (isset($admin_email)) {
$newemail = $admin_email;
} else {
$newemail = $_POST['email'];
}
//Validation rules
if ($pw1 != $pw2) {
echo '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Password fields must match</div><div id="returnVal" style="display:none;">false</div>';
} elseif (strlen($pw1) < 4) {
echo '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Password must be at least 4 characters</div><div id="returnVal" style="display:none;">false</div>';
} elseif (!filter_var($newemail, FILTER_VALIDATE_EMAIL) == true) {
echo '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Must provide a valid email address</div><div id="returnVal" style="display:none;">false</div>';
} else {
//Validation passed
if (isset($_POST['newuser']) && !empty(str_replace(' ', '', $_POST['newuser'])) && isset($_POST['password1']) && !empty(str_replace(' ', '', $_POST['password1']))) {
//Tries inserting into database and add response to variable
$a = new NewUserForm;
$response = $a->createUser($newuser, $newid, $newemail, $newpw);
//Success
if ($response == 'true') {
echo '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'. $signupthanks .'</div><div id="returnVal" style="display:none;">true</div>';
//Send verification email
$m = new MailSender;
$m->sendMail($newemail, $newuser, $newid, 'Verify');
} else {
//Failure
mySqlErrors($response);
}
} else {
//Validation error from empty form variables
echo 'An error occurred on the form... try again';
}
};