-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
executable file
·94 lines (82 loc) · 2.7 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
require_once('access.php');
require_once('dal.php');
require_once('utils.php');
require_once('email.php');
$error = null;
$user = null;
$dal = new DAL($opts['hn'], $opts['db'], $opts['un'], $opts['pw']);
try {
$dal->beginTransaction();
$user = $dal->selectUser();
if (isset($_POST['login'])) {
if (!$dal->login($_POST['email'], $_POST['password'], isset($_POST['remember']))) throw new UserException("Login failed.");
header('Location: .');
exit;
} else if ($user !== null) {
header('Location: .');
exit;
}
$dal->commit();
} catch (UserException $e) {
$dal->rollback();
$error = $e->getMessage();
} catch (Exception $e) {
$dal->rollback();
throw $e;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="OpenLCB ID Registry"/>
<link rel="icon" href="../../favicon.ico"/>
<title>Login as OpenLCB User</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
<!-- Custom styles for this template -->
<link href="theme.css" rel="stylesheet">
</head>
<body>
<?php
include('navbar.php');
?>
<div class="container-fluid form-login">
<h2 class="form-login-heading">Login</h2>
<?php
if ($error !== null) {
?>
<div class="alert alert-danger">
<a href="" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></a>
<?php echo htmlspecialchars($error); ?>
</div>
<?php
} else {
?>
<div class="alert alert-info" role="alert">
Hello.
</div>
<?php
}
?>
<form method="POST">
<div class="form-group">
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control input-sm" name="email" placeholder="Email address" required autofocus/>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control input-sm" name="password" placeholder="Password" required/>
<div class="checkbox">
<label>
<input type="checkbox" name="remember"/> Remember me
</label>
</div>
</div>
<button type="submit" name="login" class="btn btn-sm btn-primary btn-block"><span class="glyphicon glyphicon-log-in"></span> Login</button>
</form>
</div>
</body>
</html>