-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
75 lines (68 loc) · 2.42 KB
/
login.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
<?php
include "header.php";
require_once('WebsiteUser.php');
session_start();
if(isset($_SESSION['websiteUser'])){
if($_SESSION['websiteUser']->isAuthenticated()){
session_write_close();
header('Location:mailing_list.php');
}
}
$missingFields = false;
if(isset($_POST['submit'])){
if(isset($_POST['username']) && isset($_POST['password'])){
if($_POST['username'] == "" || $_POST['password'] == ""){
$missingFields = true;
} else {
//All fields set, fields have a value
$websiteUser = new WebsiteUser();
$username = $_POST['username'];
$password = $_POST['password'];
$websiteUser->authenticate($username, $password);
if($websiteUser->isAuthenticated()){
$_SESSION['websiteUser'] = $websiteUser;
header('Location:mailing_list.php');
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Week 12 Lecture</title>
</head>
<body>
<!-- MESSAGES -->
<?php
//Missing username/password
if($missingFields){
echo '<h3 style="color:red;">Please enter both a username and a password</h3>';
}
//Authentication failed
if(isset($websiteUser)){
if(!$websiteUser->isAuthenticated()){
echo '<h3 style="color:red;">Login failed. Please try again.</h3>';
}
}
?>
<form name="login" id="login" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table style="margin:20px auto 20px auto">
<tr>
<td>Username:</td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Login"></td>
<td><input type="reset" name="reset" id="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
<?php include "footer.php" ?>