/
register.php
150 lines (130 loc) · 4.97 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
<?php
//Bootstrap SPF
require 'includes/master.inc.php';
//This loads up $user - $isadmin - $js
require 'includes/user.inc.php';
$complete = false;
/// Checking //
// Form validation PHP version
$errorClass = array('', '', '', '', '');
$inputValue = array('', '', '', '', '');
// Page specific info
$title='Register <small>a new account</small>';
$meta=''; // Possibly add page unique meta data
// Check if a callback URL is specified?
if ((isset($_POST['callback']))
&& (!empty($_POST['callback'])))
{
$callback = $_POST['callback'];
} else {
$callback = '';
}
// Validate the form fields
// Username verification
if (isset($_POST['register-username']))
{
$inputValue[0] = $_POST['register-username'];
if (($Error->length($_POST['register-username'], 4, 16, 'error', 'Username'))
&& ($Error->username($_POST['register-username'])))
{
$errorClass[0] = 'success';
} else {
$errorClass[0] = 'error';
}
} else if (isset($_POST['action'])) {
$Error->add('error', 'Username cannot be left empty');
$errorClass[0] = 'error';
}
// Password verification
if (isset($_POST['register-password']))
{
$inputValue[1] = $_POST['register-password'];
if ($Error->length($_POST['register-password'], 4, 16, 'error', 'Password'))
{
$errorClass[1] = 'success';
} else {
$errorClass[1] = 'error';
}
} else if (isset($_POST['action'])) {
$Error->add('error', 'Password cannot be left empty');
$errorClass[1] = 'error';
}
// Confirm the password
if (isset($_POST['register-confirm']))
{
$inputValue[2] = $_POST['register-confirm'];
if ($Error->passwords($_POST['register-password'], $_POST['register-confirm'], 'error'))
{
$errorClass[2] = 'success';
} else {
$errorClass[2] = 'error';
}
} else if (isset($_POST['action'])) {
$Error->add('error', 'Password confirmation cannot be left empty');
$errorClass[2] = 'error';
}
// Email verification
if (isset($_POST['register-email']))
{
$inputValue[3] = $_POST['register-email'];
if ($Error->email($_POST['register-email']))
{
$errorClass[3] = 'success';
} else {
$errorClass[3] = 'error';
}
} else if (isset($_POST['action'])) {
$Error->add('error', 'Email cannot be left empty');
$errorClass[3] = 'error';
}
// Captcha verification
if (isset($_POST['register-captcha']))
{
$inputValue[4] = ""; /* we need to always clear the captcha field, because it will regenerate after a reresh*/
if ($Error->captcha($_POST['register-captcha']))
{
$errorClass[4] = 'success';
} else {
$errorClass[4] = 'error';
}
} else if (isset($_POST['action'])) {
$Error->add('error', 'Captcha cannot be left empty');
$errorClass[4] = 'error';
}
// Instantiontiate the erroring before we need to refresh the page
$msg=$Error->alert();
// Check if the form was submitted without any errors.
if ((isset($_POST['register-username']))
&& (isset($_POST['register-password']))
&& (isset($_POST['register-confirm']))
&& (isset($_POST['register-email']))
&& (isset($_POST['register-captcha']))
&& (!$Error->ok()))
{
$complete = true;
// Create the actual user
Auth::createNewUser($_POST['register-username'], $_POST['register-password'], $_POST['register-email']);
$userId = Auth::userId($_POST['register-username']);
$link = full_url_to_script('activate.php') . "?action=activate&code=" . Activation::get($userId) . "&id=" . $userId;
//echo $link;
Emailtemplate::setBaseDir('./assets/email_templates');
$html = Emailtemplate::loadTemplate('activation', array('title'=>'Activation Email',
'prettyName'=>Options::get('prettyName'),
'name'=>$_POST['register-username'],
'siteName'=>Options::get('emailName'),
'activationLink'=>$link,
'footerLink'=>Options::get('siteName'),
'footerEmail'=>Options::get('emailInfo')));
send_html_mail(array($_POST['register-username']=>$_POST['register-email']),
'Activation Email',
$html,
array(Options::get('siteName')=>Options::get('emailAdmin')));
}
Template::setBaseDir('./assets/tmpl');
$html = Template::loadTemplate('layout', array(
'header'=>Template::loadTemplate('header', array('title'=>$title,'user'=>$user,'admin'=>$isadmin,'msg'=>$msg, 'meta'=>$meta, 'selected'=>'register')),
'content'=>Template::loadTemplate('register', array('errorClass'=>$errorClass, 'inputValue'=>$inputValue, 'complete'=>$complete, 'callback'=>$callback)),
'footer'=>Template::loadTemplate('footer',array('time_start'=>$time_start))
));
echo $html;
?>