-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
98 lines (86 loc) · 3.04 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
<?php
require_once 'core/init.php';
setHeader();
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 ($validation->passed()) {
//register users
$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 Been Registered Successfully !');//flash alert to users
Redirect::to('index.php');
} catch (Exception $e) {
die($e->getMessage());
}
//Session::flash('success','You Been Registered Successfully !');
}else{?>
<div class="alert alert-warning" style="width:35%; margin-left: 30%;margin-top: 2%; text-align: center;color: red;">
<?php
foreach ($validation ->errors() as $error) {
echo $error , '<br>';
}?>
</div>
<?php
}
}
}
?>
<div class="panel panel-primary" style="width:35%; margin-left: 30%;margin-top: 2%; text-align: center;">
<div class="panel-heading">
<h6 align="center">SIGN UP HERE</h6>
</div>
<div class="panel-body"><br><br>
<form action="" method="POST">
<div class="form-group">
<label for="username" class="sr-only">Username</label>
<input type="text" name="username" id="username" class="form-control" value="<?php echo escape(Input::get('username'));?>" autocomplete="on" placeholder="Enter Username">
</div><br>
<div class="form-group">
<label for="password" class="sr-only">Choose Password</label>
<input type="password" name="password" class="form-control" id="password" placeholder="Enter Password">
</div><br>
<div class="form-group">
<label for="password" class="sr-only">Re-Enter Password</label>
<input type="password" name="password_again" class="form-control" id="password_again" placeholder="Confirm Password">
</div><br>
<div class="form-group">
<label for="name" class="sr-only">Name</label>
<input type="text" name="name" id="name" class="form-control" value="<?php echo escape(Input::get('name'));?>" autocomplete="on" placeholder="Enter Fullname">
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>"><br>
<input type="submit" name="submit" value="Register" class="btn btn-primary">
</form><br><br>
<small>Already Have Account Please ?<a href="login.php" style="text-decoration: none;font-weight: bold;"> LOGIN HERE</a></small>
</div>
</div>