aboutsummaryrefslogtreecommitdiff
path: root/loginform.inc.php
blob: 8a6cad86ad8bc3b3254ab27d7a4164a5c067214d (plain)
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
<?php
	if(!defined('ROOT')) die('Don\'t call this directly.');

	// handle login
	if(isset($_POST['user']) && isset($_POST['pass'])) {
		if($_POST['user'] === $config['admin_user'] && $_POST['pass'] === $config['admin_pass']) {
			$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
			setcookie('microblog_login', sha1($config['url'].$config['admin_pass']), NOW+$config['cookie_life'], '/', $domain, false);

			header('Location: '.$config['url'].'/new');
			die();
		} else {
			header('HTTP/1.0 401 Unauthorized');
			$message = array(
				'status' => 'error',
				'message' => 'You entered wrong user credentials. Please try again.'
			);
		}
	}

	header('Content-Type: text/html; charset=utf-8');

?><!DOCTYPE html>
<html lang="<?= $config['language'] ?>" class="login">
<head>
	<title>micro.blog</title>
	<link rel="stylesheet" href="<?= $config['url'] ?>/microblog.css" />
</head>
<body>
	<div class="wrap">
		<nav>
			<ul>
				<li><a href="<?= $config['url'] ?>/">Timeline</a></li>
				<li><a href="<?= $config['url'] ?>/new">New Status</a></li>
			</ul>
		</nav>
		<p>Please enter your login information.</p>
		<?php if(isset($message['status']) && isset($message['message'])): ?>
		<p class="message <?= $message['status'] ?>"><?= $message['message'] ?></p>
		<?php endif; ?>
		<form action="" method="post">
			<input type="text" name="user" placeholder="username" /><br />
			<input type="password" name="pass" placeholder="password" /><br />
			<input type="submit" name="" value="Login" />
		</form>
	</div>
</body>
</html>