Repository navigation
Expand file tree
/
Copy pathregistration.php
More file actions
executable file
·113 lines (86 loc) · 3.12 KB
/
Copy pathregistration.php
File metadata and controls
executable file
·113 lines (86 loc) · 3.12 KB
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
<?php
$title = 'Sign Up';
$page = 'register';
$header_title = 'Sign Up';
include "partials/header.php"; ?>
<?php
require './vendor/autoload.php';
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv->load();
$options = array(
'cluster' => 'ap2',
'encrypted' => true
);
$pusher = new Pusher\Pusher(
getenv('APP_KEY'),
getenv('APP_SECRET'),
getenv('APP_ID'),
$options
);
if($_SERVER['REQUEST_METHOD'] == "POST") {
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = trim($_POST['password']);
$error = [
'username'=> '',
'email'=>'',
'password'=>''
];
if(strlen($username) < 4){
$error['username'] = 'Username needs to be longer';
}
if($username ==''){
$error['username'] = 'Username cannot be empty';
}
if(username_exists($username)){
$error['username'] = 'Username already exists, pick another another';
}
if($email ==''){
$error['email'] = 'Email cannot be empty';
}
if(email_exists($email)){
$error['email'] = 'Email already exists, <a href="index.php">Please login</a>';
}
if($password == '') {
$error['password'] = 'Password cannot be empty';
}
foreach ($error as $key => $value) {
if(empty($value)){
unset($error[$key]);
}
} // foreach
if(empty($error)){
register_user($username, $email, $password);
}
}
?>
<div class="row justify-content-md-center">
<div class="col-lg-4 col-md-6 col-sm-8 col-12">
<div class="login-form">
<h4>SIGN UP</h4>
<form raction="" method="post" autocomplete="off">
<div class="form-group">
<label for="username" class="sr-only">username</label>
<input type="text" name="username" id="username" class="form-control" placeholder="Enter Desired Username" autocomplete="on" value="<?php echo isset($username) ? $username : '' ?>">
<p><?php echo isset($error['username']) ? $error['username'] : '' ?></p>
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" name="email" id="email" class="form-control" placeholder="somebody@example.com" autocomplete="on" value="<?php echo isset($email) ? $email : '' ?>" >
<p><?php echo isset($error['email']) ? $error['email'] : '' ?></p>
</div>
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<input type="password" name="password" id="key" class="form-control" placeholder="Password">
<p><?php echo isset($error['password']) ? $error['password'] : '' ?></p>
</div>
<input type="submit" name="resgister" class="form-control btn btn-sm btn-primary" value="Register">
<hr>
<div class="text-center">
<a href="login.php"><i class="fa fa-arrow-left"></i> Back to Login</a>
</div>
</form>
</div>
</div>
</div>
<?php include "partials/footer.php";?>