source: Klonkt/src/views/pages/account.ejs@ 1d76e0e

main
Last change on this file since 1d76e0e was 2d66d66, checked in by Robin <roboburr@…>, 7 weeks ago

Feature: revoke connected OAuth apps from the account page

You issue C2S bearer tokens (Shaer, etc.) but had no way to see or revoke them.
The account page now has a 'Connected apps' section listing every authorization
(app name via the client join, site, scope, last used) with a Revoke button.
Already-issued tokens appear because they were always stored (hashed) with the
user/client/site; the bearer is never kept, so revocation is keyed on the safe
token_hash and scoped to the owner (you cannot revoke someone else's).

  • OAuthService.listAuthorizations(userId) / revokeAuthorization(userId, hash).
  • account.js: authorizations passed to the page; POST /account/oauth/revoke.
  • account.ejs: the section + styles; i18n NL/EN/DE. Visible to viewers too (revoking your own app access is a safety action).

83 tests green. Live-verified: two apps listed on /account, revoke one -> it is
gone and the other stays, token count drops in the DB.

Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 15.9 KB
Line 
1<div class="container ax-page">
2
3 <header class="ax-header">
4 <a href="/" class="ax-back" aria-label="<%= t('acct.back_home') %>">←</a>
5 <div>
6 <h1><%= t('acct.title') %></h1>
7 <p class="ax-tagline"><%= t('acct.subtitle') %></p>
8 </div>
9 </header>
10
11 <% if (success) { %><div class="ax-flash ax-flash-ok"><%= success %></div><% } %>
12 <% if (error) { %><div class="ax-flash ax-flash-err"><%= error %></div><% } %>
13
14 <% if (isViewer) { %>
15 <div class="ax-viewer-note" role="note">
16 <span class="ax-viewer-ico" aria-hidden="true">👁️</span>
17 <div>
18 <strong><%= t('acct.viewer_mode') %></strong>
19 <span><%= t('acct.viewer_note') %></span>
20 </div>
21 </div>
22 <% } %>
23
24 <%# ── PROFILE ────────────────────────────────────────────── %>
25 <section class="ax-card">
26 <div class="ax-card-title"><%= t('acct.profile') %></div>
27
28 <div class="ax-profile-id">
29 <span class="ax-profile-avatar ax-profile-avatar-static">
30 <% var _av = (typeof siteAvatar !== 'undefined' ? siteAvatar : null); %>
31 <% if (_av) { %>
32 <img src="<%= avatar(_av, 128) %>" alt="">
33 <% } else { %>
34 <span><%= account.username.charAt(0).toUpperCase() %></span>
35 <% } %>
36 </span>
37 <div class="ax-profile-meta">
38 <div class="ax-profile-name"><%= account.username %></div>
39 <div class="ax-profile-role"><%= account.role %> · <%= account.email %></div>
40 <% if (account.created_at) { %>
41 <div class="ax-profile-joined"><%= t('acct.member_since') %> <%= formatDate(account.created_at) %></div>
42 <% } %>
43 <% if (canMutate) { %>
44 <div class="ax-profile-joined"><%- t('acct.photo_site_hint') %></div>
45 <% } %>
46 </div>
47 </div>
48
49 <% if (canMutate) { %>
50 <form action="/account/profile" method="post" class="ax-form ax-form-bio">
51 <label class="ax-field">
52 <span><%= t('acct.username') %></span>
53 <input type="text" name="username" value="<%= account.username %>" minlength="2" maxlength="30" pattern="[A-Za-z0-9_\-]{2,30}" autocomplete="username">
54 </label>
55 <label class="ax-field">
56 <span><%= t('acct.email') %></span>
57 <input type="email" name="email" value="<%= account.email || '' %>" maxlength="254" autocomplete="email" placeholder="<%= t('acct.email_ph') %>">
58 </label>
59 <label class="ax-field">
60 <span><%= t('acct.bio') %></span>
61 <textarea name="bio" rows="3" maxlength="500" placeholder="<%= t('acct.bio_ph') %>"><%= account.bio || '' %></textarea>
62 </label>
63 <div class="ax-form-actions">
64 <button type="submit" class="ax-btn ax-btn-primary"><%= t('acct.save') %></button>
65 </div>
66 </form>
67 <% } else { %>
68 <div class="ax-form ax-form-bio">
69 <label class="ax-field">
70 <span><%= t('acct.bio') %></span>
71 <textarea rows="3" disabled placeholder="<%= t('acct.bio_empty') %>"><%= account.bio || '' %></textarea>
72 </label>
73 </div>
74 <% } %>
75 </section>
76
77 <%# ── PERSONAL LANGUAGE ──────────────────────────────────── %>
78 <% if (canMutate) { %>
79 <section class="ax-card">
80 <div class="ax-card-title"><%= t('acct.lang_label') %></div>
81 <form action="/account/lang" method="post" class="ax-form">
82 <label class="ax-field">
83 <span><%= t('acct.lang_label') %> <small><%= t('acct.lang_hint') %></small></span>
84 <select name="lang">
85 <% langs.forEach(function(l){ var sel = (account && account.lang) ? (account.lang === l.code) : l.active; %>
86 <option value="<%= l.code %>"<%= sel ? ' selected' : '' %>><%= l.name %></option>
87 <% }); %>
88 </select>
89 </label>
90 <div class="ax-form-actions">
91 <button type="submit" class="ax-btn ax-btn-primary"><%= t('acct.save') %></button>
92 </div>
93 </form>
94 </section>
95 <% } %>
96
97 <%# ── SITE (owner may update their site name) ─────────── %>
98 <% if (typeof editableSite !== 'undefined' && editableSite && canMutate) { %>
99 <section class="ax-card">
100 <div class="ax-card-title"><%= t('acct.site') %></div>
101 <form action="/account/site" method="post" class="ax-form">
102 <label class="ax-field">
103 <span><%= t('acct.site_name') %> <small><%= t('acct.site_name_hint') %></small></span>
104 <input type="text" name="site_title" value="<%= editableSite.title || '' %>" maxlength="200" required>
105 </label>
106 <label class="ax-field">
107 <span><%= t('acct.tagline') %> <small><%= t('acct.tagline_hint') %></small></span>
108 <input type="text" name="site_tagline" value="<%= editableSite.tagline || '' %>" maxlength="200">
109 </label>
110 <div class="ax-form-actions">
111 <button type="submit" class="ax-btn ax-btn-primary"><%= t('acct.site_save') %></button>
112 </div>
113 </form>
114 </section>
115 <% } %>
116
117 <%# ── PASSWORD ──────────────────────────────────────────── %>
118 <%# In viewer mode there is no password section (nothing to change). %>
119 <%# ── CONNECTED APPS (OAuth C2S) ─────────────────────────── %>
120 <section class="ax-card">
121 <div class="ax-card-title"><%= t('acct.oauth_apps') %></div>
122 <p class="ax-tagline" style="margin:0 0 .6rem"><%= t('acct.oauth_hint') %></p>
123 <% if (!authorizations || !authorizations.length) { %>
124 <p class="ax-oauth-empty"><%= t('acct.oauth_none') %></p>
125 <% } else { %>
126 <ul class="ax-oauth-list">
127 <% authorizations.forEach(function(a){ %>
128 <li class="ax-oauth-item">
129 <div class="ax-oauth-info">
130 <strong><%= a.client_name || t('acct.oauth_unknown_app') %></strong>
131 <span class="ax-oauth-meta">@<%= a.site_slug %> · <%= a.scope || 'c2s' %> · <%= t('acct.oauth_last_used') %> <%= a.last_used_at ? formatDate(a.last_used_at) : t('acct.oauth_never') %></span>
132 </div>
133 <form action="/account/oauth/revoke" method="post">
134 <input type="hidden" name="token_hash" value="<%= a.token_hash %>">
135 <button type="submit" class="ax-btn ax-btn-danger"><%= t('acct.oauth_revoke') %></button>
136 </form>
137 </li>
138 <% }); %>
139 </ul>
140 <% } %>
141 </section>
142
143 <% if (canMutate) { %>
144 <% if (hasPassword) { %>
145 <section class="ax-card">
146 <div class="ax-card-title"><%= t('acct.password_change') %></div>
147 <form action="/account/password" method="post" class="ax-form">
148 <label class="ax-field">
149 <span><%= t('acct.password_current') %></span>
150 <input type="password" name="current" required autocomplete="current-password">
151 </label>
152 <div class="ax-row ax-row-2">
153 <label class="ax-field">
154 <span><%= t('acct.password_new') %> <small><%= t('acct.password_min') %></small></span>
155 <input type="password" name="new_password" required minlength="8" autocomplete="new-password">
156 </label>
157 <label class="ax-field">
158 <span><%= t('acct.password_confirm') %></span>
159 <input type="password" name="confirm" required minlength="8" autocomplete="new-password">
160 </label>
161 </div>
162 <div class="ax-form-actions">
163 <button type="submit" class="ax-btn ax-btn-primary"><%= t('acct.password_change') %></button>
164 </div>
165 </form>
166 </section>
167
168 <% } else { %>
169 <section class="ax-card">
170 <div class="ax-card-title"><%= t('acct.login') %></div>
171 <p class="ax-tagline" style="margin:0"><%= t('acct.login_google_only', { email: account.email }) %></p>
172 </section>
173 <% } %>
174 <% } %>
175
176</div>
177
178<style>
179.ax-page { max-width: 720px; margin: 1.5rem auto 4rem; padding: 0 1rem; }
180.ax-header { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 1.5rem; }
181.ax-header h1 { font-family: var(--font-display, serif); font-size: 1.75rem; margin: 0 0 0.25rem; }
182.ax-tagline { color: var(--ink-muted, var(--ink-soft)); margin: 0; font-size: 0.9rem; }
183.ax-back {
184 display: inline-flex; align-items: center; justify-content: center;
185 width: 40px; height: 40px;
186 border: 1px solid var(--rule); border-radius: 8px;
187 background: var(--paper); color: var(--ink); text-decoration: none;
188 font-size: 1.1rem; flex-shrink: 0; transition: border-color 120ms;
189}
190.ax-back:hover { border-color: var(--accent); }
191
192.ax-flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
193.ax-flash-ok { background: rgba(40,160,90,.15); color: #2a9d5e; border: 1px solid rgba(40,160,90,.3); }
194.ax-flash-err { background: rgba(200,60,60,.15); color: #c33; border: 1px solid rgba(200,60,60,.3); }
195
196/* ─── Kijker-modus notice ──────────────────────────────────────── */
197.ax-viewer-note {
198 display: flex; align-items: flex-start; gap: 0.75rem;
199 padding: 0.85rem 1rem; margin-bottom: 1rem;
200 border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--rule));
201 border-left: 3px solid var(--accent);
202 border-radius: 10px;
203 background: color-mix(in srgb, var(--accent) 8%, var(--paper));
204}
205.ax-viewer-ico { font-size: 1.1rem; line-height: 1.4; }
206.ax-viewer-note strong { display: block; font-size: 0.92rem; }
207.ax-viewer-note span { color: var(--ink-muted, var(--ink-soft)); font-size: 0.85rem; }
208.ax-profile-avatar-static { flex-shrink: 0; }
209.ax-form-bio textarea:disabled { opacity: 0.7; cursor: default; }
210
211/* ─── Cards ────────────────────────────────────────────────────── */
212.ax-card {
213 background: var(--paper);
214 border: 1px solid var(--rule);
215 border-radius: 12px;
216 padding: 1.25rem;
217 margin-bottom: 1rem;
218}
219.ax-card-title {
220 font-family: var(--font-display, serif);
221 font-size: 1.15rem;
222 font-weight: 600;
223 margin-bottom: 1rem;
224}
225
226/* ─── Form fields ──────────────────────────────────────────────── */
227.ax-form { display: flex; flex-direction: column; gap: 0.85rem; }
228.ax-form-bio { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
229.ax-row { display: grid; gap: 0.85rem; }
230.ax-row-2 { grid-template-columns: 1fr 1fr; }
231@media (max-width: 600px) { .ax-row-2 { grid-template-columns: 1fr; } }
232
233.ax-field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
234.ax-field > span {
235 font-size: 0.8rem; font-weight: 600;
236 color: var(--ink-soft);
237 display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap;
238}
239.ax-field > span small { font-weight: 400; color: var(--ink-muted); font-size: 0.95em; }
240.ax-field input[type="text"],
241.ax-field input[type="email"],
242.ax-field input[type="password"],
243.ax-field input[type="url"],
244.ax-field select,
245.ax-field textarea {
246 width: 100%;
247 box-sizing: border-box;
248 padding: 0.6rem 0.75rem;
249 border: 1px solid var(--rule);
250 border-radius: 6px;
251 background: var(--paper-2);
252 color: var(--ink);
253 font-family: var(--font-ui, system-ui), sans-serif;
254 font-size: 0.95rem;
255 -webkit-appearance: none; appearance: none;
256 transition: border-color 120ms;
257}
258.ax-field textarea { resize: vertical; min-height: 70px; font-family: inherit; }
259.ax-field input:focus, .ax-field select:focus, .ax-field textarea:focus {
260 outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
261}
262
263/* ─── File upload ─────────────────────────────────────────────── */
264.ax-file-control {
265 display: flex; align-items: center; gap: 0.5rem;
266 flex-wrap: wrap;
267 position: relative;
268 min-height: 40px;
269}
270.ax-file-control input[type="file"] {
271 position: absolute; inset: 0;
272 opacity: 0; cursor: pointer;
273 z-index: 2;
274}
275.ax-file-btn { pointer-events: none; }
276.ax-file-name {
277 font-size: 0.85rem;
278 color: var(--ink);
279 word-break: break-all;
280 flex: 1; min-width: 0;
281}
282.ax-file-name[data-empty] { color: var(--ink-muted, var(--ink-soft)); }
283
284.ax-form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
285
286/* ─── Buttons ──────────────────────────────────────────────────── */
287.ax-btn {
288 display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
289 padding: 0.55rem 1rem;
290 border: 1px solid var(--rule); background: var(--paper-2);
291 color: var(--ink);
292 font-family: var(--font-ui, system-ui), sans-serif;
293 font-size: 0.9rem; font-weight: 500;
294 text-decoration: none; border-radius: 6px;
295 cursor: pointer; min-height: 40px;
296 transition: background 120ms, border-color 120ms;
297 -webkit-tap-highlight-color: transparent;
298}
299.ax-btn:hover { border-color: var(--accent); }
300.ax-btn-secondary { background: var(--paper-2); }
301.ax-btn-primary, a.ax-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
302.ax-btn-primary:hover, a.ax-btn-primary:hover { opacity: 0.92; border-color: var(--accent); color: #fff; }
303
304/* ─── Profile ID row ──────────────────────────────────────────── */
305.ax-profile-id {
306 display: flex; align-items: center; gap: 1rem;
307 padding-bottom: 1rem;
308 border-bottom: 1px solid var(--rule);
309 margin-bottom: 1rem;
310}
311.ax-avatar-form { margin: 0; flex-shrink: 0; }
312.ax-avatar-wrap {
313 position: relative; display: block;
314 width: 84px; height: 84px; cursor: pointer;
315}
316.ax-profile-avatar {
317 width: 84px; height: 84px;
318 border-radius: 50%;
319 overflow: hidden;
320 background: var(--paper-2); /* neutral so transparent avatars blend */
321 color: var(--accent); /* accent only for the fallback initial */
322 display: inline-flex; align-items: center; justify-content: center;
323 font-family: var(--font-display, serif);
324 font-size: 1.7rem; font-weight: 600;
325 border: 1px solid var(--rule);
326 transition: border-color 120ms;
327}
328.ax-avatar-wrap:hover .ax-profile-avatar { border-color: var(--accent); }
329.ax-profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
330.ax-avatar-edit {
331 position: absolute; right: -2px; bottom: -2px;
332 width: 28px; height: 28px; border-radius: 50%;
333 background: var(--accent); color: #fff;
334 display: flex; align-items: center; justify-content: center;
335 border: 3px solid var(--paper);
336 transition: transform 120ms;
337}
338.ax-avatar-wrap:hover .ax-avatar-edit { transform: scale(1.08); }
339.ax-avatar-remove { margin-top: 0.45rem; }
340.ax-linkbtn {
341 background: none; border: 0; padding: 0; cursor: pointer;
342 color: var(--ink-muted, var(--ink-soft)); font-size: 0.8rem; text-decoration: underline;
343 font-family: var(--font-ui, system-ui), sans-serif;
344}
345.ax-linkbtn:hover { color: #c33; }
346.ax-profile-meta { min-width: 0; }
347.ax-profile-name { font-weight: 600; font-size: 1.1rem; }
348.ax-profile-role,
349.ax-profile-joined {
350 color: var(--ink-muted, var(--ink-soft));
351 font-size: 0.85rem;
352}
353
354@media (max-width: 480px) {
355 .ax-profile-id { flex-direction: column; align-items: flex-start; gap: 0.75rem; text-align: left; }
356}
357
358.ax-oauth-empty { margin: 0; color: var(--ink-soft, #888); }
359.ax-oauth-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
360.ax-oauth-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem .85rem; border-radius: 12px; background: var(--paper-2, rgba(0,0,0,.04)); }
361.ax-oauth-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
362.ax-oauth-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
363.ax-oauth-meta { font-size: .8rem; color: var(--ink-soft, #888); }
364@media (max-width: 480px) {
365 .ax-oauth-item { flex-direction: column; align-items: stretch; }
366}
367</style>
Note: See TracBrowser for help on using the repository browser.