Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. require_once __DIR__ . "/required.php";
  8. // if we're logged in, we don't need to be here.
  9. if (!empty($_SESSION['loggedin']) && $_SESSION['loggedin'] === true && !isset($_GET['permissionerror'])) {
  10. header('Location: app.php');
  11. die();
  12. }
  13. /**
  14. * Show a simple HTML page with a line of text and a button. Matches the UI of
  15. * the AccountHub login flow.
  16. *
  17. * @global type $SETTINGS
  18. * @global type $SECURE_NONCE
  19. * @global type $Strings
  20. * @param string $title Text to show, passed through i18n
  21. * @param string $button Button text, passed through i18n
  22. * @param string $url URL for the button
  23. */
  24. function showHTML(string $title, string $button, string $url) {
  25. global $SETTINGS, $SECURE_NONCE, $Strings;
  26. ?>
  27. <!DOCTYPE html>
  28. <meta charset="UTF-8">
  29. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  30. <meta name="viewport" content="width=device-width, initial-scale=1">
  31. <title><?php echo $SETTINGS['site_title']; ?></title>
  32. <link rel="icon" href="static/img/logo.svg">
  33. <link href="static/css/bootstrap.min.css" rel="stylesheet">
  34. <style nonce="<?php echo $SECURE_NONCE; ?>">
  35. .display-5 {
  36. font-size: 2.5rem;
  37. font-weight: 300;
  38. line-height: 1.2;
  39. }
  40. .banner-image {
  41. max-height: 100px;
  42. margin: 2em auto;
  43. border: 1px solid grey;
  44. border-radius: 15%;
  45. }
  46. </style>
  47. <div class="container mt-4">
  48. <div class="row justify-content-center">
  49. <div class="col-12 text-center">
  50. <img class="banner-image" src="./static/img/logo.svg" />
  51. </div>
  52. <div class="col-12 text-center">
  53. <h1 class="display-5 mb-4"><?php $Strings->get($title); ?></h1>
  54. </div>
  55. <div class="col-12 col-sm-8 col-lg-6">
  56. <div class="card mt-4">
  57. <div class="card-body">
  58. <a href="<?php echo $url; ?>" class="btn btn-primary btn-block"><?php $Strings->get($button); ?></a>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <?php
  65. }
  66. if (!empty($_GET['logout'])) {
  67. showHTML("You have been logged out.", "Log in again", "./index.php");
  68. die();
  69. }
  70. if (empty($_SESSION["login_code"])) {
  71. $redirecttologin = true;
  72. } else {
  73. try {
  74. $uid = LoginKey::getuid($_SESSION["login_code"]);
  75. $user = new User($uid);
  76. Session::start($user);
  77. $_SESSION["login_code"] = null;
  78. header('Location: app.php');
  79. showHTML("Logged in", "Continue", "./app.php");
  80. die();
  81. } catch (Exception $ex) {
  82. $redirecttologin = true;
  83. }
  84. }
  85. if ($redirecttologin) {
  86. try {
  87. $code = LoginKey::generate($SETTINGS["site_title"], "../static/img/logo.svg");
  88. $_SESSION["login_code"] = $code;
  89. $loginurl = "./login/?code=" . htmlentities($code) . "&redirect=" . htmlentities($_SERVER["REQUEST_URI"]);
  90. header("Location: $loginurl");
  91. showHTML("Continue", "Continue", $loginurl);
  92. die();
  93. } catch (Exception $ex) {
  94. sendError($ex->getMessage());
  95. }
  96. }