This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_reg.php
executable file
·94 lines (79 loc) · 2.22 KB
/
example_reg.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
<?php
require_once 'core/init.php';
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array(
'required' => true,
'min' => 5,
'max' => 15,
'unique' => 'users'
),
'email' => array(
'required' => true,
'email' => true
),
'name' => array(
'required' => true,
'min' => 5
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
)
));
if ($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::generateHash(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'email' => Input::get('email'),
'joined' => date('Y-m-d H:i:s'),
'role' => 2
));
Session::flash('home', 'User registerd');
header('Location: index.php');
} catch (Exception $e) {
die($e->getMessage());
}
} else {
foreach ($validation->errors() as $error) {
echo $error . "</br>";
}
}
}
}
?>
<form action="" method="POST">
<div class="field">
<label for="username">Username</label>
<input type="text" name="username" id="username" autocomplete="off" value="<?php echo escape(Input::get('username')); ?>">
</div>
<div class="field">
<label for="email">Email</label>
<input type="text" name="email" id="email" autocomplete="off" value="<?php echo escape(Input::get('email')); ?>">
</div>
<div class="field">
<label for="name">Name</label>
<input type="text" name="name" id="name" autocomplete="off" value="<?php echo escape(Input::get('name')); ?>">
</div>
<div class="field">
<label for="password">Password</label>
<input type="password" name="password" id="password" autocomplete="off" value="">
</div>
<div class="field">
<label for="password_again">Password Again</label>
<input type="password" name="password_again" id="password_again" autocomplete="off" value="">
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Register">
</form>