forked from GibbonEdu/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublicRegistrationProcess.php
executable file
·166 lines (142 loc) · 6.98 KB
/
publicRegistrationProcess.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
<?php
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Gibbon\Comms\NotificationEvent;
include './functions.php';
include './config.php';
//New PDO DB connection
$pdo = new Gibbon\sqlConnection();
$connection2 = $pdo->getConnection();
@session_start();
$URL = $_SESSION[$guid]['absoluteURL'].'/index.php?q=/publicRegistration.php';
$proceed = false;
if (isset($_SESSION[$guid]['username']) == false) {
$enablePublicRegistration = getSettingByScope($connection2, 'User Admin', 'enablePublicRegistration');
if ($enablePublicRegistration == 'Y') {
$proceed = true;
}
}
if ($proceed == false) {
$URL .= '&return=error0';
header("Location: {$URL}");
} else {
//Lock activities table
try {
$data = array();
$sql = 'LOCK TABLES gibbonPerson WRITE, gibbonSetting READ, gibbonNotification WRITE, gibbonModule WRITE';
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}
// Sanitize the whole $_POST array
$validator = new \Gibbon\Data\Validator();
$_POST = $validator->sanitize($_POST);
//Proceed!
$surname = trim($_POST['surname']);
$firstName = trim($_POST['firstName']);
$preferredName = trim($firstName);
$officialName = $firstName.' '.$surname;
$gender = $_POST['gender'];
$dob = $_POST['dob'];
if ($dob == '') {
$dob = null;
} else {
$dob = dateConvert($guid, $dob);
}
$email = trim($_POST['email']);
$username = trim($_POST['username']);
$password = $_POST['passwordNew'];
$salt = getSalt();
$passwordStrong = hash('sha256', $salt.$password);
$status = getSettingByScope($connection2, 'User Admin', 'publicRegistrationDefaultStatus');
$gibbonRoleIDPrimary = getSettingByScope($connection2, 'User Admin', 'publicRegistrationDefaultRole');
$gibbonRoleIDAll = $gibbonRoleIDPrimary;
if ($surname == '' or $firstName == '' or $preferredName == '' or $officialName == '' or $gender == '' or $dob == '' or $email == '' or $username == '' or $password == '' or $gibbonRoleIDPrimary == '' or $gibbonRoleIDPrimary == '' or ($status != 'Pending Approval' and $status != 'Full')) {
$URL .= '&return=error1';
header("Location: {$URL}");
} else {
//Check strength of password
$passwordMatch = doesPasswordMatchPolicy($connection2, $password);
if ($passwordMatch == false) {
$URL .= '&return=error7';
header("Location: {$URL}");
} else {
//Check uniqueness of username
try {
$data = array('username' => $username, 'email' => $email);
$sql = 'SELECT * FROM gibbonPerson WHERE username=:username OR email=:email';
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}
if ($result->rowCount() > 0) {
$URL .= '&return=error3';
header("Location: {$URL}");
} else {
//Check publicRegistrationMinimumAge
$publicRegistrationMinimumAge = getSettingByScope($connection2, 'User Admin', 'publicRegistrationMinimumAge');
$ageFail = false;
if ($publicRegistrationMinimumAge == '') {
$ageFail = true;
} elseif ($publicRegistrationMinimumAge > 0 and $publicRegistrationMinimumAge > getAge($guid, dateConvertToTimestamp($dob), true, true)) {
$ageFail = true;
}
if ($ageFail == true) {
$URL .= '&return=warning1';
header("Location: {$URL}");
} else {
//Write to database
try {
$data = array('surname' => $surname, 'firstName' => $firstName, 'preferredName' => $preferredName, 'officialName' => $officialName, 'gender' => $gender, 'dob' => $dob, 'email' => $email, 'username' => $username, 'passwordStrong' => $passwordStrong, 'passwordStrongSalt' => $salt, 'status' => $status, 'gibbonRoleIDPrimary' => $gibbonRoleIDPrimary, 'gibbonRoleIDAll' => $gibbonRoleIDAll);
$sql = "INSERT INTO gibbonPerson SET surname=:surname, firstName=:firstName, preferredName=:preferredName, officialName=:officialName, gender=:gender, dob=:dob, email=:email, username=:username, password='', passwordStrong=:passwordStrong, passwordStrongSalt=:passwordStrongSalt, status=:status, gibbonRoleIDPrimary=:gibbonRoleIDPrimary, gibbonRoleIDAll=:gibbonRoleIDAll";
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
echo $e->getMessage();
exit();
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}
$gibbonPersonID = $connection2->lastInsertId();
try {
$sqlLock = 'UNLOCK TABLES';
$result = $connection2->query($sqlLock);
} catch (PDOException $e) {
}
if ($status == 'Pending Approval') {
// Raise a new notification event
$event = new NotificationEvent('User Admin', 'New Public Registration');
$event->addRecipient($_SESSION[$guid]['organisationAdmissions']);
$event->setNotificationText(sprintf(__('An new public registration, for %1$s, is pending approval.'), formatName('', $preferredName, $surname, 'Student')));
$event->setActionLink("/index.php?q=/modules/User Admin/user_manage_edit.php&gibbonPersonID=$gibbonPersonID&search=");
$event->sendNotifications($pdo, $gibbon->session);
$URL .= '&return=success1';
header("Location: {$URL}");
} else {
$URL .= '&return=success0';
header("Location: {$URL}");
}
}
}
}
}
}