|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title><?= $this->t('{material:mfa:title}') ?></title> |
| 5 | + |
| 6 | + <?php include __DIR__ . '/../common-head-elements.php' ?> |
| 7 | +</head> |
| 8 | +<body class="gradient-bg"> |
| 9 | +<div class="mdl-layout mdl-layout--fixed-header fill-viewport"> |
| 10 | + <header class="mdl-layout__header"> |
| 11 | + <div class="mdl-layout__header-row"> |
| 12 | + <span class="mdl-layout-title"> |
| 13 | + <?= $this->t('{material:mfa:header}') ?> |
| 14 | + </span> |
| 15 | + </div> |
| 16 | + </header> |
| 17 | + <main class="mdl-layout__content" layout-children="column"> |
| 18 | + <form layout-children="column" method="post"> |
| 19 | + <?php $newCodes = $this->data['newBackupCodes']; ?> |
| 20 | + <?php if (! empty($newCodes)): ?> |
| 21 | + <h1 class="mdl-typography--display-1"> |
| 22 | + <?= $this->t('{material:mfa:new_codes_header}') ?> |
| 23 | + </h1> |
| 24 | + |
| 25 | + <p class="mdl-typography--body-1"> |
| 26 | + <em><?= $this->t('{material:mfa:old_codes_gone}') ?></em> |
| 27 | + </p> |
| 28 | + |
| 29 | + <p class="mdl-typography--body-1"> |
| 30 | + <?= $this->t('{material:mfa:new_codes_info}') ?> |
| 31 | + <span class="mdl-typography--body-2"><?= $this->t('{material:mfa:new_codes_only_once}') ?></span> |
| 32 | + </p> |
| 33 | + |
| 34 | + <div class="mdl-card mdl-shadow--8dp"> |
| 35 | + <div class="mdl-card__supporting-text" layout-children="column" id="code-card"> |
| 36 | + <?php |
| 37 | + $idpName = htmlentities($this->configuration->getValue('idp_display_name', $this->configuration->getValue('idp_name', '—'))); |
| 38 | + ?> |
| 39 | + <p class="fill-parent" layout-children="row"> |
| 40 | + <span flex><?= $this->t('{material:mfa:account}', ['{idpName}' => $idpName]) ?></span> |
| 41 | + <em class="mdl-typography--caption"><?= date('M j, Y') ?></em> |
| 42 | + </p> |
| 43 | + |
| 44 | + <?php |
| 45 | + function calculateMaxHeightStyle($newCodes) |
| 46 | + { |
| 47 | + $numCodes = count($newCodes); |
| 48 | + $numCols = $numCodes <= 5 ? 1 : 2; |
| 49 | + $numCodesPerRow = ceil($numCodes / $numCols); |
| 50 | + $numCodesPerRow *= 1.3; // the .3 here accounts for px differences in <code> and base em sizes. |
| 51 | + |
| 52 | + return "max-height: {$numCodesPerRow}em;"; |
| 53 | + } |
| 54 | + ?> |
| 55 | + <div class="code-container" style="<?= calculateMaxHeightStyle($newCodes) ?>"> |
| 56 | + <?php foreach ($newCodes as $newCode): ?> |
| 57 | + <code>☐ <?= htmlentities($newCode) ?></code> |
| 58 | + <?php endforeach; ?> |
| 59 | + </div> |
| 60 | + |
| 61 | + <span class="mdl-typography--caption"><?= $this->t('{material:mfa:new_codes_only_once}') ?></span> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div class="mdl-card__actions" layout-children="row"> |
| 65 | + <script> |
| 66 | + function printElement(selector) { |
| 67 | + var elementToPrint = document.querySelector(selector); |
| 68 | + |
| 69 | + elementToPrint.classList.add('printable-codes'); |
| 70 | + |
| 71 | + window.print(); |
| 72 | + } |
| 73 | + </script> |
| 74 | + <button class="mdl-button mdl-button--primary" type="button" onclick="printElement('#code-card')"> |
| 75 | + <?= $this->t('{material:mfa:button_print}') ?> |
| 76 | + </button> |
| 77 | + |
| 78 | + <a href="data:text/plain,<?= $idpName . urlencode("\r\n" . join("\r\n", $newCodes)) ?>" |
| 79 | + download="<?= $idpName ?>-printable-codes.txt" class="mdl-button mdl-button--primary"> |
| 80 | + <?= $this->t('{material:mfa:button_download}') ?> |
| 81 | + </a> |
| 82 | + |
| 83 | + <script> |
| 84 | + function copyCodesToClipboard(button) { |
| 85 | + document.querySelector('textarea').select(); |
| 86 | + |
| 87 | + document.execCommand('copy'); |
| 88 | + |
| 89 | + button.innerHTML = button.innerHTML.replace('<?= $this->t("{material:mfa:button_copy}") ?>', '<?= $this->t("{material:mfa:button_copied}") ?>'); |
| 90 | + } |
| 91 | + </script> |
| 92 | + <button class="mdl-button mdl-button--primary" type="button" onclick="copyCodesToClipboard(this)"> |
| 93 | + <?= $this->t('{material:mfa:button_copy}') ?> |
| 94 | + <textarea class="out-of-sight"><?= $idpName."\n".join("\n", $newCodes) ?></textarea> |
| 95 | + </button> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + <?php else: ?> |
| 99 | + <div class="mdl-card mdl-shadow--8dp"> |
| 100 | + <div class="mdl-card__media white-bg margin" layout-children="column"> |
| 101 | + <i class="mdl-color-text--red error material-icons mdl-typography--display-4">error</i> |
| 102 | + </div> |
| 103 | + |
| 104 | + <div class="mdl-card__title center"> |
| 105 | + <h1 class="mdl-card__title-text"> |
| 106 | + <?= $this->t('{material:error:header}') ?> |
| 107 | + </h1> |
| 108 | + </div> |
| 109 | + |
| 110 | + <div class="mdl-card__supporting-text" > |
| 111 | + <p> |
| 112 | + <?= $this->t('{material:mfa:new_codes_failed}') ?> |
| 113 | + <a href="<?= $this->data['mfaSetupUrl'] ?>" target="_blank"><?= $this->data['mfaSetupUrl'] ?></a> |
| 114 | + </p> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + |
| 118 | + <script> |
| 119 | + ga('send','event','error','backupcode','generation-failed'); |
| 120 | + </script> |
| 121 | + <?php endif; ?> |
| 122 | + |
| 123 | + <div layout-children="row" class="fill-parent"> |
| 124 | + <span flex></span> |
| 125 | + |
| 126 | + <button name="continue" class="mdl-button mdl-button--raised mdl-button--primary"> |
| 127 | + <?= $this->t('{material:mfa:button_continue}') ?> |
| 128 | + </button> |
| 129 | + </div> |
| 130 | + </form> |
| 131 | + </main> |
| 132 | +</div> |
| 133 | +</body> |
| 134 | +</html> |
0 commit comments