IndieAuth login support, allows viewing of topics related to profile
[websub-hub] / src / template / admin-login-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4
5
6 /**
7 * Login form.
8 */
9 function indieAuthSection() {
10 return ` <section class="indieauth">
11 <h2>Login</h2>
12 <form action="" method="POST">
13 <fieldset>
14 <legend>IndieAuth</legend>
15 <label for="me">Profile URL:</label>
16 <input id="me" name="me" type="url" size="40" placeholder="https://example.com/my_profile_url" value="" autofocus>
17 <button>Login</button>
18 <br>
19 <div>
20 Logging in with an <a class="external" href="https://indieweb.org/IndieAuth">IndieAuth</a> profile will allow you to view details of any topics on this hub which are related to that profile's domain.
21 </div>
22 </fieldset>
23 </form>
24 </section>`;
25 }
26
27
28 function userSection(ctx, options) {
29 const secure = (ctx.clientProtocol || '').toLowerCase() === 'https';
30 const showUserForm = secure || !options.authenticator.secureAuthOnly;
31 return showUserForm ? ` <section class="user">
32 <form action="" method="POST">
33 <fieldset>
34 <legend>User Account</legend>
35 <label for="identifier">Username:</label>
36 <input id="identifier" name="identifier" value="">
37 <br>
38 <label for="credential">Password:</label>
39 <input id="credential" name="credential" type="password" value="">
40 <br>
41 <button>Login</button>
42 <br>
43 </fieldset>
44 </form>
45 </section>`
46 : '';
47 }
48
49
50 function errorsSection(ctx) {
51 return (ctx.errors && ctx.errors.length) ? ` <section class="errors">
52 <h2>Troubles</h2>
53 <p>Problems were encountered while trying to authenticate you.</p>
54 <ul>` +
55 ctx.errors.map((error) => `<li>${error}</li>`).join('\n') + `
56 </ul>
57 </section>`
58 : '';
59 }
60
61
62 /**
63 * Render login form for both local and profile authentication.
64 * @param {Object} ctx
65 * @param {Object} options
66 * @param {Object} options.manager
67 * @param {String} options.manager.pageTitle
68 * @param {Object} options.dingus
69 * @param {String} options.dingus.selfBaseUrl
70 * @returns {String}
71 */
72 module.exports = (ctx, options) => {
73 const pageTitle = options.manager.pageTitle;
74 const footerEntries = options.manager.footerEntries;
75 const headElements = [];
76 const navLinks = [];
77 const mainContent = [
78 errorsSection(ctx),
79 indieAuthSection(),
80 userSection(ctx, options),
81 ];
82 return th.htmlTemplate(ctx, 2, pageTitle, headElements, navLinks, mainContent, footerEntries);
83 };