-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
167 lines (157 loc) · 5.39 KB
/
index.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login - DebtorBook</title>
<?php
include "./externalCss.php";
?>
</head>
<body>
<!-- container -->
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-lg-6 col-sm-12">
<div class="main-img">
<img
src="./assets/images/accounting.jpg"
alt="login"
style="width: 100%;"
/>
</div>
</div>
<div class="col-md-12 col-lg-6 col-sm-12 right-login-block">
<div class="content">
<!-- sign in text-->
<div class="sign-in-text text-right p-2">
<span class="gray-text">New user?</span>
<a href="./signup" class="blue-text text-decoration-none">Sign up</a>
</div>
<!-- sign in form -->
<div class="sign-in-form p-4 text-center">
<!-- alert danger -->
<div class="alert alert-danger m-2 error_msg">
</div>
<span class="blue-text" style="font-size: 2rem;"
>Sign in to Debtor Book</span
>
<!-- sign in form -->
<form action="" method="post" onsubmit="return validateSignUpForm()">
<div class="form-group">
<input
type="email"
name="email"
id="email"
class="mt-4"
placeholder="Email"
required
/>
<input
type="password"
name="password"
id="password"
title="Password"
class="mt-4"
placeholder="Password"
required
/>
<button type="submit" name="signUp" class="mt-4 btn-block">Sign in</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include "./externalJs.php";
?>
<script>
function validateSignUpForm(){
let password = $("#password").val();
let passwordPattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
if(password.match(passwordPattern)){
$(".error_msg").hide();
return true;
}else{
// fasle
$(".error_msg").text("Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters");
$(".error_msg").show();
return false;
}
}
</script>
<?php
if(
isset($_POST["signUp"]) &&
isset($_POST["email"]) &&
isset($_POST["password"])
){
if(
!empty($_POST["email"]) &&
!empty($_POST["password"])
){
// proceed
include "./api/helper/ValidationHelper.php";
$email = $_POST["email"];
$password = $_POST["password"];
$status= 1;
if(!ValidationHelper::validateEmail($email)){
// if email validation failed
?>
<script>
$(".error_msg").text("Invalid Email");
$(".error_msg").show();
</script>
<?php
}elseif(!ValidationHelper::validatePassword($password)){
// if password validation failed
?>
<script>
$(".error_msg").text("Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters");
$(".error_msg").show();
</script>
<?php
}else{
// check user authentication
$password = md5($password);
include "./api/db.php";
$sql = $conn->prepare("SELECT * FROM users WHERE USER_EMAIL= ? AND USER_PASSWORD= ? AND USER_STATUS= ?");
$sql->bind_param("ssi", $email, $password,$status);
$sql->execute();
$result = $sql->get_result();
if($result->num_rows === 0){
// unauthenticate user
?>
<script>
$(".error_msg").text("Sorry, invalid email AND password");
$(".error_msg").css("display","block");
</script>
<?php
}else{
// authenticate user
if($row= $result->fetch_assoc()){
$_SESSION["user_auth_id"] = $row["USER_ID"];
header("Location:./user");
}
?>
<script>
$(".error_msg").hide();
</script>
<?php
}
$sql->close();
$conn->close();
}
?>
<script>history.pushState({}, "", "")</script>
<?php
}
}
?>
</body>
</html>