-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (162 loc) · 7.27 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
168
169
170
171
172
173
174
175
176
177
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
spl_autoload_register(function ($class_name) {
include 'classes/'.$class_name . '.php';
});
if (isset($_POST['signUp'])) {
$email = $_POST['signUpEmail'];
$password = $_POST['signUpPassword'];
$passwordConfirm = $_POST['passwordConfirm'];
$connection = new Connection();
$authentication = new Authentication($connection->pdo);
$authentication->signUp($email, $password, $passwordConfirm);
}
if (isset($_POST['logIn'])) {
$email = $_POST['logInEmail'];
$password = $_POST['logInPassword'];
$connection = new Connection();
$authentication = new Authentication($connection->pdo);
$loginStatus = $authentication->logIn($email, $password);
if ($loginStatus) {
header("location:dashboard.php");
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Secret Diary</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="#">Diary</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="d-flex flex-column ms-auto">
<form class="d-flex align-items-start" method="post" action="index.php">
<div class="d-flex flex-column me-2">
<input class="form-control" type="email" name="logInEmail" placeholder="Email Address" value="<?php echo htmlspecialchars($_POST['logInEmail'] ?? ""); ?>">
<?php
if (isset($_POST['logIn']) && isset(Validation::$errors['email'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['email'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
<div class="d-flex flex-column me-2">
<input class="form-control" type="password" name="logInPassword" placeholder="Password">
<?php
if (isset($_POST['logIn']) && isset(Validation::$errors['password'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['password'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
<button type="submit" class="btn btn-primary" name="logIn">Login</button>
</form>
<?php
if (isset($_POST['logIn']) && isset(Validation::$errors['general'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['general'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
</div>
</div>
</nav>
<div class="container main-content d-flex flex-column justify-content-center align-items-center">
<form class="bg-light p-4" method="post" action="index.php">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="signUpEmail" placeholder="Email Address"
value="<?php echo htmlspecialchars($_POST['signUpEmail'] ?? ""); ?>">
<?php
if (isset($_POST['signUp']) && isset(Validation::$errors['email'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['email'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="signUpPassword" placeholder="Password">
<?php
if (isset($_POST['signUp']) && isset(Validation::$errors['password'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['password'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
<div class="mb-3">
<label for="password2" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password2" name="passwordConfirm"
placeholder="Retype password">
<?php
if (isset($_POST['signUp']) && isset(Validation::$errors['password confirmation'])):
?>
<div class="error-message">
<?php
foreach (Validation::$errors['password confirmation'] as $error):
echo $error . "<br>";
endforeach;
?>
</div>
<?php
endif;
?>
</div>
<button type="submit" class="btn btn-primary w-100" name="signUp">Sign up</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</body>
</html>