-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
187 lines (141 loc) · 4.74 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
require_once 'core/init.php';
$user = new User();
if($user->isLoggedIn()) {
Redirect::to('index.php');
}
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validate->check($_POST,array(
'username' => array(
'required' => true,
'min' => 2,
'max' => 20,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
),
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
)
));
if($validate->passed()) {
$user = new User();
$salt = Hash::salt(2);
try {
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'),$salt),
'non_encr_pwd' => Input::get('password'),
'salt' => $salt,
'name' => Input::get('name'),
'joined' => date('Y-m-d H:i:s'),
'group' => 1,
'lang' => Input::get('lang')
));
} catch (Exception $e) {
die($e->getMessage());
}
Session::flash('home','You registered successfully!');
Redirect::to('index.php');
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>register</title>
<link rel="stylesheet" type="text/css" href="css/multipage.css?<?php echo date('l jS \of F Y h:i:s A'); ?>"/>
<style>
.login-box form {
margin-left: 3em;
width: 20em;
display: flex;
flex-direction: column;
}
.login-box form .field {
display: flex;
width: 100%;
justify-content: space-between;
margin-top:0.3em;
}
.login-box .field.register{
margin-top:0.3em;
}
.login-error: {
width: 100%;
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-box">
<h3 class="login-title">C.P. Editor and Collaboration tool</h3>
<h4 class="login-subtitle">Register:</h4>
<form action="" method="POST">
<div class="field">
<label for="username">username</label>
<input type="text" name="username" value="<?php echo escape(Input::get("username")); ?>" id="username"/>
</div>
<div class="field">
<label for="password">password</label>
<input type="password" name="password" id="password"/>
</div>
<div class="field">
<label for="password_again">password again</label>
<input type="password" name="password_again" id="password_again"/>
</div>
<div class="field">
<label for="name">name</label>
<input type="text" name="name" value="<?php echo escape(Input::get("name")); ?>" id="name"/>
</div>
<div class="field">
<label for="lang-codes">Language</label>
<select name="lang" id="lang-codes">
<option value="us">English (AE)</option>
<option value="gb">English (BE)</option>
<option value="de">German</option>
<option value="fr">French</option>
<option value="es">Spanish</option>
<option value="it">Italien</option>
<option value="ru">Russian</option>
<option value="nl">Dutch</option>
</select>
</div>
<div class="field register">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>"/>
<input type="submit" value="Register" class="login_submit"/>
</div>
<?php
if(Input::exists()) {
if(isset($validate)) {
if(!$validate->passed()) {
echo '<div class="login-error">';
foreach($validate->errors() as $error) {
echo $error. '<br/>';
}
echo '</div>';
}
}
}
?>
<div class="field">
<div class="not_registered">Already registered? Please login <a href="./login.php">here</a></div>
</div>
</form>
</div>
</div>
</body>
</html>