-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
executable file
·148 lines (134 loc) · 4.47 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
137
138
139
140
141
142
143
144
145
146
147
148
<?php
include_once 'functions.php';
if (isset($_SESSION['username'])) {
header("Location: admin/index.php");
}
$register_msg = array(
'username' => '',
'email' => '',
'password' => '',
'global' => ''
);
if (isset($_POST['register_submit'])) {
$username = sanitize($_POST['username']);
$email = sanitize($_POST['email']);
$password = sanitize($_POST['password']);
$proceed = true;
if(empty($username)) {
$register_msg['username'] = "Username can't be blank.";
$proceed = false;
} else if( !is_unique('users', $username, 'username') ) {
$register_msg['username'] = "Username exists. Please try another one.";
$proceed = false;
}
if(empty($email)) {
$register_msg['email'] = "Email can't be empty.";
$proceed = false;
} else if( !is_unique('users', $email, 'email') ) {
$register_msg['email'] = "Email exists. Please try another one.";
$proceed = false;
}
if(empty($password)) {
$register_msg['password'] = "Please add a password";
}
if($proceed) {
$data = array(
'username' => $username,
'email' => $email,
'password' => $password,
'role' => get_registration_role(),
'status' => get_default_status()
);
$result = insert_into_database('users', $data);
if($result) {
redirect('login.php?message=registrationsuccess');
} else {
$register_msg['global'] = "Something went wrong. Please try in a minute.";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>User Registration</title>
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Font Awesome -->
<link rel="stylesheet" href="admin/assets/plugins/fontawesome-free/css/all.min.css">
<!-- icheck bootstrap -->
<link rel="stylesheet" href="admin/assets/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="admin/assets/css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<h3>User Registration</h3>
</div>
<!-- /.login-logo -->
<div class="card">
<div class="card-body login-card-body">
<p class="text-danger"><?php echo $register_msg['global']; ?></p>
<form action="" method="post">
<div class="form-group">
<label for="username">Username</label>
<div class="input-group">
<input type="text" class="form-control" name="username" placeholder="Username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : ''; ?>">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
</div>
<span class="text-danger"><?php echo $register_msg['username']; ?></span>
</div>
<div class="form-group">
<label for="email">Email</label>
<div class="input-group">
<input type="email" class="form-control" name="email" placeholder="Email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<span class="text-danger"><?php echo $register_msg['email']; ?></span>
</div>
<div class="form-group">
<label for="password">Password</label>
<div class="input-group mb-3">
<input type="password" class="form-control" name="password" placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<span class="text-danger"><?php echo $register_msg['password']; ?></span>
</div>
<div class="row">
<!-- /.col -->
<div class="col-12">
<button type="submit" class="btn btn-info btn-block" name="register_submit">Sign Up</button>
</div>
<!-- /.col -->
</div>
</form>
<p class="mt-4 text-center">
<a href="login.php" class="text-center">Have an account? Login</a>
</p>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<!-- jQuery -->
<script src="admin/assets/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="admin/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="admin/assets/js/adminlte.min.js"></script>
</body>
</html>