source: Klonkt/src/views/pages/account.ejs@ 3d7312a

main
Last change on this file since 3d7312a was 82079ad, checked in by Robin Genis <roboburr@…>, 3 months ago

feat: one identity — user avatar falls back to the site photo everywhere

When a user has no own account avatar, display their site's profile photo across
the account page, top nav (render.js) and comments. No DB copy → stays in sync.

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

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