-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
127 lines (106 loc) · 3.82 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
<!--
page for handling user registration
-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- external files -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/loginCSS2.css">
<link rel="stylesheet" href="css/styles.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<?php
include("headerNavbar.php");
?>
</br>
<!-- Section Heading-->
<h2 class="page-section-heading text-center text-uppercase text-secondary mb-0">Register</h2>
<!-- Icon Divider-->
<div class="divider-custom">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon"><i class="fas fa-star"></i></div>
<div class="divider-custom-line"></div>
</div>
<!-- registration section -->
<form action="lib/checkUser.php" method="post">
<div class="imgcontainer">
</div>
<div class="container">
<label for="uname" class="text-uppercase"><b>Username</b></label>
<input id="uname" type="text" placeholder="Enter Username" name="uname" required>
<label for="email" class="text-uppercase"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="Email" id="Email" required>
<label for="psw" class="text-uppercase"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
<!--button-->
<button id="rbtn" type="button" class="buttonLogin">Create account</button>
<div id="avalibility"></div>
</div>
</form>
</body>
<script>
$(document).ready(function() {
$('#rbtn').click(function() {
var username = $('input[name="uname"]').val();
var email = $('input[name="Email"]').val();
var password = $('input[name="psw"]').val();
$('#avalibility').css("color", "black");
// clean up entered text
if (username.trim() == '') {
$('#avalibility').html("please enter Username.");
return;
}
if (email.trim() == '') {
$('#avalibility').html("please enter Email.");
return;
}
if (password.trim() == '') {
$('#avalibility').html("please enter Password.");
return;
}
if (!validateEmail(email)){
$('#avalibility').html("You have entered an invalid email address! should include e.g.xxx@xxxx.xxx ");
return;
}
if (password.trim().length < 5){
$('#avalibility').html("Password length at least 6 characters.");
return;
}
if (!password.match(/[A-Z]/)) {
$('#avalibility').html("Password should at least one Capital letter.");
return;
}
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
// check availabilty of unique username
$.ajax({
url: 'lib/checkUser.php',
method: "POST",
data: {
uname: username,
Email: email,
psw: password,
},
success: function(data) {
console.log(data);
let msg = data.trim();
if (msg == "success") {
$('#avalibility').css("color", "green");
$('#avalibility').html("New record created successfully. Redirecting...");
setTimeout(() => {
window.location.href = "lib/afterLogin.php";
}, 3000);
} else {
$('#avalibility').html(msg);
}
}
})
});
});
</script>
</html>