AccountHub/index.php

114 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2018-12-22 16:56:25 -07:00
/*
* This Source Code Form is subject to the terms of the Mozilla Public
2017-12-16 13:27:09 -07:00
* License, v. 2.0. If a copy of the MPL was not distributed with this
2018-12-22 16:56:25 -07:00
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
2017-12-16 13:27:09 -07:00
require_once __DIR__ . "/required.php";
2018-12-22 16:56:25 -07:00
// if we're logged in, we don't need to be here.
if (!empty($_SESSION['loggedin']) && $_SESSION['loggedin'] === true && !isset($_GET['permissionerror'])) {
header('Location: app.php');
die();
}
2018-12-27 00:30:32 -07:00
2018-12-27 00:15:27 -07:00
/**
* Show a simple HTML page with a line of text and a button. Matches the UI of
* the AccountHub login flow.
*
* @global type $SETTINGS
* @global type $SECURE_NONCE
* @global type $Strings
* @param string $title Text to show, passed through i18n
* @param string $button Button text, passed through i18n
* @param string $url URL for the button
*/
function showHTML(string $title, string $button, string $url) {
global $SETTINGS, $SECURE_NONCE, $Strings;
2018-12-22 16:56:25 -07:00
?>
<!DOCTYPE html>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
2018-12-22 16:56:25 -07:00
<title><?php echo $SETTINGS['site_title']; ?></title>
2018-12-22 16:56:25 -07:00
<link rel="icon" href="static/img/logo.svg">
2018-12-22 16:56:25 -07:00
<link href="static/css/bootstrap.min.css" rel="stylesheet">
2018-12-22 16:57:45 -07:00
<style nonce="<?php echo $SECURE_NONCE; ?>">
.display-5 {
2018-12-22 21:26:57 -07:00
font-size: 2.5rem;
2018-12-22 16:57:45 -07:00
font-weight: 300;
line-height: 1.2;
2017-04-24 17:13:08 -06:00
}
2018-12-22 21:26:57 -07:00
.banner-image {
max-height: 100px;
margin: 2em auto;
border: 1px solid grey;
border-radius: 15%;
}
2018-12-22 16:57:45 -07:00
</style>
2018-12-22 16:56:25 -07:00
<div class="container mt-4">
<div class="row justify-content-center">
2018-12-22 21:26:30 -07:00
<div class="col-12 text-center">
<img class="banner-image" src="./static/img/logo.svg" />
</div>
2018-12-22 16:56:25 -07:00
<div class="col-12 text-center">
2018-12-27 00:15:27 -07:00
<h1 class="display-5 mb-4"><?php $Strings->get($title); ?></h1>
</div>
2018-12-22 16:56:25 -07:00
<div class="col-12 col-sm-8 col-lg-6">
<div class="card mt-4">
<div class="card-body">
2018-12-27 00:15:27 -07:00
<a href="<?php echo $url; ?>" class="btn btn-primary btn-block"><?php $Strings->get($button); ?></a>
2018-12-22 16:56:25 -07:00
</div>
</div>
</div>
</div>
2018-12-22 16:56:25 -07:00
</div>
<?php
}
2018-12-27 00:15:27 -07:00
if (!empty($_GET['logout'])) {
showHTML("You have been logged out.", "Log in again", "./index.php");
die();
}
2018-12-22 16:56:25 -07:00
if (empty($_SESSION["login_code"])) {
$redirecttologin = true;
} else {
try {
$uid = LoginKey::getuid($_SESSION["login_code"]);
$user = new User($uid);
Session::start($user);
$_SESSION["login_code"] = null;
header('Location: app.php');
2018-12-27 00:30:32 -07:00
showHTML("Logged in", "Continue", "./app.php");
die();
2018-12-22 16:56:25 -07:00
} catch (Exception $ex) {
$redirecttologin = true;
}
}
if ($redirecttologin) {
try {
2018-12-22 21:26:30 -07:00
$code = LoginKey::generate($SETTINGS["site_title"], "../static/img/logo.svg");
2018-12-22 16:56:25 -07:00
$_SESSION["login_code"] = $code;
2018-12-27 00:30:32 -07:00
$loginurl = "./login/?code=" . htmlentities($code) . "&redirect=" . htmlentities($_SERVER["REQUEST_URI"]);
2018-12-22 16:57:45 -07:00
2018-12-27 00:30:32 -07:00
header("Location: $loginurl");
showHTML("Continue", "Continue", $loginurl);
2018-12-27 00:15:27 -07:00
die();
2018-12-22 16:56:25 -07:00
} catch (Exception $ex) {
sendError($ex->getMessage());
}
2018-12-27 00:30:32 -07:00
}