Skip to content

User Page

The look and the script of a whole page a plugin hosts for regular users, such as an invite page or a device setup page. It loads none of the web client's CSS, so it is built on Stolon's tokens alone, and HostedPage serves it in the page template. See Pages and Templates for the C# side.

Decision

When Use
A page at a root path of the server that regular users open from a link User Page, served by HostedPage
A form, a QR code, or steps on that page The kit's card, fields, and steps, with QR Code, Stepper, and Button inside
A short message on a server page, such as "page not found" Status Page
Anything inside the dashboard A config page

Usage

HostedPage writes the frame, so the plugin writes only the content: one or more cards, and a module script that imports its own bundle by a path relative to the server root.

<section class="stolon-user-page-card" data-stolon-view="form">
    <h1 class="stolon-user-page-title">Create your account</h1>
    <p class="stolon-user-page-lead">Choose a username and a password.</p>
    <form class="stolon-user-page-form" id="form" data-code="{{CODE}}" novalidate>
        <div class="stolon-user-page-field">
            <label for="username">Username</label>
            <input id="username" type="text" autocomplete="username" required />
        </div>
        <div id="message" class="stolon-user-page-message" hidden></div>
        <div class="stolon-user-page-actions">
            <button class="raised stolon-button stolon-primary stolon-large stolon-fill" type="submit">Create account</button>
        </div>
    </form>
</section>
<section class="stolon-user-page-card stolon-user-page-done" data-stolon-view="done" data-stolon-state="success" hidden>
    <span class="stolon-user-page-done-icon"><span class="material-icons" aria-hidden="true">check_circle</span></span>
    <h1 class="stolon-user-page-title">Welcome</h1>
    <div class="stolon-user-page-actions"><a class="raised stolon-button stolon-primary stolon-large stolon-fill" href="web/">Go to sign in</a></div>
</section>
<script type="module">
const base = await import('./web/configurationpage?name=myplugin_stolon.js');
const session = await base.startUserPage();
document.getElementById('form').addEventListener('submit', async function (e) {
    e.preventDefault();
    const answer = await session.request('MyPlugin/Invites/' + this.dataset.code + '/Redeem', { method: 'POST' });
    if (answer.ok) base.showUserPageView('done');
    else base.setUserPageMessage(document.getElementById('message'), 'error', 'That username is taken.');
});
</script>

The frame, which HostedPage writes:

  • stolon-user-page on the body, the page color, the web client's font, and fields a step up for touch.
  • stolon-user-page-header with stolon-user-page-server, the server's name as a link to the web client, and stolon-user-page-mark, the plugin's mark.
  • stolon-user-page-column, the centered column, and stolon-user-page-gate and stolon-user-page-content inside it.

The parts a plugin writes:

  • stolon-user-page-card, the frame every step sits in, with stolon-user-page-title, stolon-user-page-subtitle, and stolon-user-page-lead.
  • stolon-user-page-form and stolon-user-page-field, a label over its input, with stolon-user-page-hint under it.
  • stolon-user-page-actions, a stack of full width buttons. Use stolon-button primary large fill for the main action.
  • stolon-user-page-message, a Callout with the icon of its state, written by setUserPageMessage.
  • stolon-user-page-steps, short numbered steps on an ol.
  • stolon-user-page-split, two cards side by side that stack when the column is narrow.
  • stolon-user-page-done and stolon-user-page-done-icon, the finished state.

Every address in the content is relative to the server root, since the page sets its base there. Write web/ for the web client and MyPlugin/Devices for the plugin's API.

States and Modifiers

  • stolon-wide on the body widens the header and the column, for a split. HostedPage.Wide sets it.
  • data-stolon-state on stolon-user-page-done colors the icon: success green, info blue, warn orange, and error red.
  • data-stolon-access on the body is anyone, user, or administrator. On the last two the content stays hidden until startUserPage sets data-stolon-ready.
  • data-stolon-view names a view for showUserPageView. One view shows and the rest hide.
  • A QR Code on the page is dark on white, since some scanners cannot read light on dark.

Gotchas

  • The check in the browser only decides what the page shows. The plugin's API enforces access with [Authorize] or [Authorize(Policy = HostedPage.AdministratorPolicy)].
  • startUserPage reads the sign-in the web client stored in this browser. A viewer signed in on another device, or in another browser, gets the sign in card.
  • The first call to startUserPage starts the check, and the template calls it after the content's scripts. Pass the options from the content's script, or through HostedPage.Translations.
  • A link to #part resolves against the server root, since the page sets its base there. Scroll from a script instead.
  • The page is always dark, since it loads no Jellyfin theme.

Reference

startUserPage

function startUserPage(options?: UserPageOptions): Promise<UserPageSession | null>

Starts a user page that HostedPage serves. It loads the plugin's translations, and on a page for signed in viewers or administrators it checks the viewer with the sign-in the web client stored in this browser. A viewer who may not see the page gets a card that sends them to the web client, and the content stays hidden. The first call starts the check and later calls return the same promise, so the page's own script calls it to get the session.

Option Type What it does
translations string address of the plugin's translations relative to the server root, such as MyPlugin/Translations [optional]
signInText string the sign in button's label (default 'Sign in')
signInMessage string the sentence for a viewer who is not signed in (default 'Sign in to Jellyfin to open this page.')
deniedMessage string the sentence for a viewer who is not an administrator (default 'Only administrators can open this page.')
unreachableMessage string the sentence when the server does not answer (default 'Could not reach the server.')
backText string the button's label when signing in would not help (default 'Back to Jellyfin')

showUserPageView

function showUserPageView(name: string, root?: ParentNode): void

Shows one view of a user page and hides the rest, such as the form and then the finished state. A view is any element with a data-stolon-view name.

setUserPageMessage

function setUserPageMessage(element: HTMLElement, state: UserPageMessageState, text: string): void

Writes a message into an element of a user page, as a Callout with the icon of its state, and announces it. An empty text hides the element.

Type What it is
UserPageAccess Who may open a user page, as HostedPage writes it into data-stolon-access.
UserPageUser The signed in viewer, as Jellyfin's Users/Me answers.
UserPageSession What startUserPage resolves to once the viewer may see the page. request calls the server's API as the viewer.
UserPageMessageState The state of a user page message, as the Callout draws it.
Class What it looks like
stolon-user-page A whole page a plugin hosts for regular users, on the dark page color with the web client's font and field sizes a step up for touch
stolon-user-page-header The header, the server's name as a link to the web client and the plugin's mark, as wide as the column
stolon-user-page-column The centered column under the header that holds the cards
stolon-user-page.stolon-wide The wide column, for content set side by side such as a QR code beside its steps
stolon-user-page-card A card on the surface, the one frame every step of a user page sits in
stolon-user-page-title The card's heading, and the short paragraph under it
stolon-user-page-form A stack of fields, each a label over its input with an optional hint under it
stolon-user-page-actions A stack of full width buttons at the end of a card
stolon-user-page-steps Short numbered steps, such as how to add a tunnel on one platform
stolon-user-page-split Two parts side by side that stack once the column is too narrow for both, such as a QR code and its steps
stolon-user-page-done The finished state, or the page script's sign in ask: a round icon in its state's color over a heading, a sentence, and its buttons
stolon-user-page-message.stolon-icon-text A message in a card, a callout with the icon of its state, which setUserPageMessage writes

Example

The parts of the kit.

An invite page, a form with a Stepper that turns into the finished state.

A WireGuard setup page in the wide column, a QR Code and a download beside steps for each platform.

Example Code

<!-- title: User Page -->
<iframe id="page" title="User page parts" style="display: block; width: 100%; height: 900px; border: 0; border-radius: 8px;"></iframe>
<template id="content">
<section class="stolon-user-page-card">
<h1 class="stolon-user-page-title">Card title</h1>
<p class="stolon-user-page-lead">A short paragraph under the title says what the page is for.</p>
<form class="stolon-user-page-form" novalidate>
<div class="stolon-user-page-field">
<label for="name">Device name</label>
<input id="name" type="text" value="Living room TV" />
<span class="stolon-user-page-hint">Shown in your device list.</span>
</div>
<div id="success" class="stolon-user-page-message" hidden></div>
<div id="warn" class="stolon-user-page-message" hidden></div>
<div id="error" class="stolon-user-page-message" hidden></div>
<div class="stolon-user-page-actions">
<button class="raised stolon-button stolon-primary stolon-large stolon-fill" type="button">Primary action</button>
<button class="raised stolon-button stolon-secondary stolon-large stolon-fill" type="button">Secondary action</button>
</div>
</form>
</section>
<section class="stolon-user-page-card">
<h2 class="stolon-user-page-subtitle">Steps</h2>
<ol class="stolon-user-page-steps">
<li>Each step is one short sentence.</li>
<li>The numbers come from the list.</li>
</ol>
</section>
<section class="stolon-user-page-card stolon-user-page-done" data-stolon-state="success">
<span class="stolon-user-page-done-icon"><span class="material-icons" aria-hidden="true">check_circle</span></span>
<h1 class="stolon-user-page-title">Finished</h1>
<p class="stolon-user-page-lead">The finished state closes a flow.</p>
<div class="stolon-user-page-actions">
<a class="raised stolon-button stolon-primary stolon-large stolon-fill" href="web/">Go to sign in</a>
</div>
</section>
<script type="module">
const base = await import('./base/stolon.js');
await base.startUserPage();
base.setUserPageMessage(document.getElementById('success'), 'success', 'Saved.');
base.setUserPageMessage(document.getElementById('warn'), 'warn', 'This code expires in 10 minutes.');
base.setUserPageMessage(document.getElementById('error'), 'error', 'Could not save.');
</script>
</template>
<script type="module">
await window.__baseReady;
window.__gallery.userPage({ frame: document.getElementById('page'), content: document.getElementById('content'), title: 'Devices', server: 'Den', mark: 'Devices', markIcon: 'devices' });
</script>

<!-- title: User Page Invite -->
<iframe id="page" title="Invite page" style="display: block; width: 100%; height: 560px; border: 0; border-radius: 8px;"></iframe>
<template id="content">
<div id="steps"></div>
<section class="stolon-user-page-card" data-stolon-view="form">
<h1 class="stolon-user-page-title">Create your account</h1>
<p class="stolon-user-page-lead">Ana invited you to watch on Den. Choose a username and a password.</p>
<form class="stolon-user-page-form" id="form" data-code="{{CODE}}" novalidate>
<div class="stolon-user-page-field">
<label for="username">Username</label>
<input id="username" type="text" autocomplete="username" autocapitalize="none" spellcheck="false" required />
</div>
<div class="stolon-user-page-field">
<label for="password">Password</label>
<input id="password" type="password" autocomplete="new-password" required />
<span class="stolon-user-page-hint">At least 8 characters.</span>
</div>
<div class="stolon-user-page-field">
<label for="confirm">Confirm password</label>
<input id="confirm" type="password" autocomplete="new-password" required />
</div>
<div id="message" class="stolon-user-page-message" hidden></div>
<div class="stolon-user-page-actions">
<button class="raised stolon-button stolon-primary stolon-large stolon-fill" type="submit">Create account</button>
</div>
</form>
</section>
<section class="stolon-user-page-card stolon-user-page-done" data-stolon-view="done" data-stolon-state="success" hidden>
<span class="stolon-user-page-done-icon"><span class="material-icons" aria-hidden="true">check_circle</span></span>
<h1 class="stolon-user-page-title" id="welcome">Welcome</h1>
<p class="stolon-user-page-lead">Your account is ready. Sign in with your new username and password.</p>
<div class="stolon-user-page-actions">
<a class="raised stolon-button stolon-primary stolon-large stolon-fill" href="web/">Go to sign in</a>
</div>
</section>
<script type="module">
// A plugin imports its own bundle, './web/configurationpage?name=myplugin_stolon.js'.
const base = await import('./base/stolon.js');
await base.startUserPage();
const steps = base.createStepper({ steps: [{ id: 'form', label: 'Account' }, { id: 'done', label: 'Sign in' }] });
document.getElementById('steps').appendChild(steps.element);
const message = document.getElementById('message');

function finish(name) {
    document.getElementById('welcome').textContent = 'Welcome, ' + name;
    steps.setValue('done');
    base.showUserPageView('done');
}

document.getElementById('form').addEventListener('submit', function (e) {
    e.preventDefault();
    const name = document.getElementById('username').value.trim();
    const password = document.getElementById('password').value;
    if (!name) { base.setUserPageMessage(message, 'error', 'Enter a username.'); return; }
    if (password.length < 8) { base.setUserPageMessage(message, 'error', 'Use at least 8 characters.'); return; }
    if (password !== document.getElementById('confirm').value) { base.setUserPageMessage(message, 'error', 'The passwords do not match.'); return; }
    base.setUserPageMessage(message, 'info', '');
    // A plugin posts to its API here, such as fetch('MyPlugin/Invites/' + code + '/Redeem'), relative to the server root.
    finish(name);
});

if (new URLSearchParams(window.parent.location.search).get('state') === 'done') finish('Sam');
if (new URLSearchParams(window.parent.location.search).get('state') === 'error') base.setUserPageMessage(message, 'error', 'That username is taken.');
</script>
</template>
<script type="module">
await window.__baseReady;
window.__gallery.userPage({ frame: document.getElementById('page'), content: document.getElementById('content'), title: 'Invite', values: { CODE: 'k2x9' }, server: 'Den', mark: 'Invite', markIcon: 'person_add' });
</script>

<!-- title: User Page WireGuard -->
<iframe id="page" title="WireGuard setup page" style="display: block; width: 100%; height: 720px; border: 0; border-radius: 8px;"></iframe>
<template id="content">
<section class="stolon-user-page-card">
<h1 class="stolon-user-page-title">Set up {{DEVICE}}</h1>
<p class="stolon-user-page-lead">This tunnel lets the device reach Den from anywhere. Keep this page to yourself, since the code holds the device's key.</p>
</section>
<div class="stolon-user-page-split">
<section class="stolon-user-page-card">
<h2 class="stolon-user-page-subtitle">Scan or download</h2>
<div id="qr"></div>
<div class="stolon-user-page-actions">
<button class="raised stolon-button stolon-primary stolon-large stolon-fill" type="button" id="download"><span class="material-icons" aria-hidden="true">download</span><span>Download config</span></button>
</div>
</section>
<section class="stolon-user-page-card" id="setup">
<h2 class="stolon-user-page-subtitle">Add the tunnel</h2>
<div class="stolon-pill-group" role="group" aria-label="Platform" id="platforms">
<button type="button" class="stolon-pill" data-value="phone">Phone</button>
<button type="button" class="stolon-pill" data-value="desktop">Computer</button>
<button type="button" class="stolon-pill" data-value="linux">Linux</button>
</div>
<ol class="stolon-user-page-steps" data-stolon-view="phone">
<li>Install WireGuard from the App Store or Google Play.</li>
<li>Tap the plus button, then Scan from QR code.</li>
<li>Scan the code on this page and name the tunnel.</li>
<li>Turn the tunnel on, then open Jellyfin.</li>
</ol>
<ol class="stolon-user-page-steps" data-stolon-view="desktop" hidden>
<li>Install WireGuard from wireguard.com.</li>
<li>Download the config from this page.</li>
<li>Choose Import tunnel from file and pick the config.</li>
<li>Select Activate, then open Jellyfin.</li>
</ol>
<ol class="stolon-user-page-steps" data-stolon-view="linux" hidden>
<li>Install the wireguard-tools package.</li>
<li>Download the config and move it to /etc/wireguard/den.conf.</li>
<li>Run wg-quick up den, then open Jellyfin.</li>
</ol>
</section>
</div>
<script type="module">
// A plugin imports its own bundle, './web/configurationpage?name=myplugin_stolon.js', and reads the config from its API.
const base = await import('./base/stolon.js');
await base.startUserPage();
const config = [
    '[Interface]',
    'PrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=',
    'Address = 10.8.0.2/32',
    'DNS = 10.8.0.1',
    '',
    '[Peer]',
    'PublicKey = xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=',
    'AllowedIPs = 10.8.0.0/24',
    'Endpoint = den.example.com:51820',
    'PersistentKeepalive = 25'
].join('\n');
const qr = base.createQrCode({ value: config, label: 'WireGuard config', showValue: false, showActions: false });
document.getElementById('qr').appendChild(qr.element);
document.getElementById('download').addEventListener('click', function () {
    const link = document.createElement('a');
    link.href = URL.createObjectURL(new Blob([config], { type: 'text/plain' }));
    link.download = 'den.conf';
    link.click();
    URL.revokeObjectURL(link.href);
});
const setup = document.getElementById('setup');
const platforms = base.createPillGroup(document.getElementById('platforms'), {
    onChange: function (value) { if (value) base.showUserPageView(value, setup); else platforms.set('phone'); }
});
platforms.set('phone');
</script>
</template>
<script type="module">
await window.__baseReady;
window.__gallery.userPage({ frame: document.getElementById('page'), content: document.getElementById('content'), values: { DEVICE: "Ana's phone" }, title: 'WireGuard', server: 'Den', mark: 'WireGuard', markIcon: 'vpn_key', wide: true });
</script>