-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
90 lines (77 loc) · 2.64 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
<?php
/**
* PHP OOP Login Register Project
* You can copy paste it
* @package ooplr
**/
// Loading Main Function/init
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' => 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(32);
try{
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'joined' => date('Y-m-d H:i:s'),
'group' => 1
));
Session::flash('home', 'You have been registered and now can login.');
Redirect::to(404);
} 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" value="<?php echo escape(Input::get('username')); ?>" autocomplete="off"/>
</div>
<div class="field">
<label for="password">Choose a Password</label>
<input type="password" name="password" id="password"/>
</div>
<div class="field">
<label for="password_again">Enter your 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>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>" />
<input type="submit" value="Register"/>
</form>