-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
136 lines (112 loc) · 5.14 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
<?php
// Include INIT file
require 'header.php';
// If we have inputs
if(Input::exists()) {
// If inputs were not tampered with
if(Token::check(Input::get('token'))) {
// Validate
$validator = new Validator();
$validator->check($_POST, array(
'username' => array(
'name' => 'Username',
'required' => true,
'unique' => 'users',
'min' => 2,
'max' => 20
),
'email' => array(
'name' => 'E-mail',
'required' => true,
'unique' => 'users',
'email' => true
),
'password' => array(
'name' => 'Password',
'required' => true,
'min' => 8
),
'password_check' => array(
'required' => true,
'matches' => 'password'
)
));
// If valid
if($validator->passed()) {
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
{
$secret = '6Ld3ovYUAAAAAN33s_4owHYSVqH-5ewSm-nyFSDb';
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success)
{
// Create a new user
$user = new User();
try {
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password')),
'email' =>Input::get('email'),
'created' => date('Y-m-d H:i:s'),
'lvl' => '1',
'avatar' => Config::get('avatar/default')
));
// Create a session message and redirect to index
Session::flash('home', 'Welcome <b>' . Input::get('username') . '</b>! Your account was created. You can log in.');
Redirect::to('index.php');
} catch (Exception $e) {
echo $e, '<br>';
}
}
else
{
Redirect::to('index.php?bot=yes');
}
}
// If invalid
} else {
$_GET['validationerror'] = 'yes';
}
}
}
?>
<h1>Register</h1>
<form action="" method="post">
<div class="field">
<label for="username">Username</label>
<input type="text" name="username" id="username" value="<?php echo escape(Input::get('username')); ?>" class="w3-input w3-border w3-round">
</div>
<div class="field">
<label for="email">E-mail</label>
<input type="text" name="email" id="email" value="<?php echo escape(Input::get('email')); ?>" class="w3-input w3-border w3-round">
</div>
<div class="field">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="w3-input w3-border w3-round">
</div>
<div class="field">
<label for="password_check">Password check</label>
<input type="password" name="password_check" id="password_check" class="w3-input w3-border w3-round">
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<?php
if(Input::exists('get')) {
if(Input::get('validationerror') == 'yes') {
$str = "";
foreach ($validator->errors() as $error) {
$modified = str_replace("_", " ", $error);
$str .= "<p>". $modified ."</p>";
}
$err = '<div class="w3-display-container w3-panel w3-card-4 w3-round w3-red">
<span onclick="this.parentElement.style.display=\'none\'"class="w3-button w3-small w3-hover-red w3-display-topright">×</span>
'. $str .'</div>';
echo $err;
}
}
?>
<div class="g-recaptcha w3-padding-16" data-sitekey="6Ld3ovYUAAAAABh60BXwp0ANYKiagQjf7TB_FxNj"></div>
<input type="submit" value="Register" class="w3-button w3-small w3-light-green w3-hover-gray w3-round w3-margin-top">
</form>
<p><a href="index.php">Go back</a></p>
<?php
require 'footer.php';