-
Notifications
You must be signed in to change notification settings - Fork 11
/
register.php
122 lines (93 loc) · 3.98 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
<?php
//Check if the config.php file has already been created.
//If so, include it, otherwise display an error message
if (file_exists('config.php')) {
include_once('config.php');
} else {
$_SESSION['errors']['general'] = $lang['error']['config'];
}
//Get the reCAPTCHA PHP Library in case we need it
//Source https://github.com/google/recaptcha
require('includes/Recaptcha/src/autoload.php');
//If the system is installed, proceed
//'INSTALLED' is defined in the config.php file
//If the system is not installed, navigate to the install page
if (defined('INSTALLED')) {
//includes.php
include_once('./lang/'.$language.'.inc.php');
include_once('includes/includes.php');
include_once('includes/functions.php');
unset($_SESSION['messages']);
unset($_SESSION['errors']);
$_SESSION['messages']['registration'] = '';
$_SESSION['errors']['registration'] = '';
//Check to see if registration is allowed. If not, continue no further
if ($allowAccountRegistration == FALSE){
$_SESSION['errors']['registration'][] = $lang['error']['registration']['not_allowed'];
}
//If this is a post back from the register form, let's see if we can process it or if we need to return some errors
if (!empty($_POST['register']) && $allowAccountRegistration) {
//Grab the post parameters
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
//Check reCAPTCHA to make sure it's not a bot or something
if($useRecaptcha){
$gRecaptchaResponse = $_POST['g-recaptcha-response'];
$remoteIp = getRealIPAddr();
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecretKey);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
}
if ($useRecaptcha == FALSE || $resp->isSuccess()) {
// verified!
// if Domain Name Validation turned off don't forget to check hostname field
// if($resp->getHostName() === $_SERVER['SERVER_NAME']) { }
//Do some error checking
if(empty($username) || empty($password1) || empty($password2)){
if(empty($username)){
$_SESSION['errors']['registration'][] = $lang['error']['registration']['user_empty'];
}
if(empty($password1)){
$_SESSION['errors']['registration'][] = $lang['error']['registration']['password_empty'];
}
if(empty($password2)){
$_SESSION['errors']['registration'][] = $lang['error']['registration']['password_empty'];
}
} else {
//If the user name exists, tell the user and don't register
if(getAccountID($username) > 0){
$_SESSION['errors']['registration'][] = $lang['error']['registration']['user_exists'];
} else if($password1 != $password2){
//Check if the passwords match
$_SESSION['errors']['registration'][] = $lang['error']['registration']['password_match'];
} else {
if(createAccount($username, $password1, $email)){
$_SESSION['messages']['registration'][] = $lang['message']['registration']['account_created'];
$username = '';
$email = '';
} else {
$_SESSION['errors']['registration'][] = $lang['error']['registration']['general_error'];
}
}
}
} else {
$errors = $resp->getErrorCodes();
$_SESSION['errors']['registration'][] = $lang['error']['registration']['reCAPTCHA'];
}
} else {
$username = '';
$email = '';
}
} else {
// If the config file exists, but the system is not installed, throw an error and redirect to the install directory
$_SESSION['errors']['install'] = $lang['error']['install']['not_installed'];
header("Location: install/index.php");
}
//These php files generate the html content to display
include_once('themes/'.$theme.'/views/header.php');
include_once('themes/'.$theme.'/views/navbar.php');
include_once('themes/'.$theme.'/views/register.php');
include_once('themes/'.$theme.'/views/footer.php');
echo $output;
?>