-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
124 lines (104 loc) · 3.98 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
<?php
require_once 'core/init.php';
if(Input::exists()) {
if(Token::check(Input::get('csrf-token'))) {
$validation = new Validation();
$validation->check($_POST, [
'username' => [
'required' => true,
'min' => 2,
'max' => 10,
'unique' => 'users',
],
'name' => [
'required' => true,
'min' => 2,
'max' => 50,
],
'email' => [
'required' => true,
'unique' => 'users',
],
'password' => [
'required' => true,
'min' => 6
],
'password-confirm' => [
'required' => true,
'min' => 6,
'matches' => 'password'
],
]);
if ($validation->passed()) {
// do register user
try{
$user = new User();
$salt = Hash::salt(32);
$user->create([
'username' => Input::get('username'),
'email' => Input::get('email'),
'name' => Input::get('name'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'joined_at' => date('Y-m-d H:i:s'),
'group_id' => 1
]);
Session::flash('success','You registered successfully :) ');
Redirect::to('index.php');
}catch (Exception $exception){
Redirect::to(404);
}
} else {
var_dump($validation->errors());
}
}
else{
throw new Exception('Token Mismatch');
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="assets/imgs/favicon.ico">
<title>Register</title>
<!-- Bootstrap core CSS -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body class="text-center">
<div class="container">
<div class="col-md-4 offset-md-4" >
<form action="" method="POST">
<div class="form-group">
<label for="username">UserName</label>
<input type="text" class="form-control" id="username" name="username" value="<?php echo escape(Input::get('username'))?>" placeholder="Enter UserName">
</div>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo escape(Input::get('name'))?>" placeholder="Enter Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo escape(Input::get('email'))?>" placeholder="Enter email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<div class="form-group">
<label for="password-confirm">Confirm Password</label>
<input type="password" class="form-control" id="password-confirm" name="password-confirm" placeholder="Confirm Password">
</div>
<input type="hidden" name="csrf-token" value="<?php echo Token::generate();?>">
<button type="submit" class="btn btn-primary">Sign up</button>
</form>
</div>
</div>
</body>
</html>