source: Klonkt/src/views/pages/account.ejs@ c80e78b

main
Last change on this file since c80e78b was c80e78b, checked in by roboburr <roboburr@…>, 3 months ago

auth: replace username/password with Google login

Listeners (and the owner) now log in via Google instead of a local
username/password account. This lowers the barrier to commenting and
removes the home-built password/registration system.

  • src/config/google.js: raw OAuth2 helpers (authorize/token/userinfo) via the built-in fetch, config-driven. Boot keeps working without credentials.
  • src/routes/auth.js: /auth/google + /auth/google/callback (find-or-create user on email, ADMIN_EMAIL -> god, set session). login/register/reset POST handlers removed; /login now shows the Google button.
  • database.js: idempotent column users.google_sub.
  • account.js + account.ejs: change-password removed.
  • auth-login.ejs / welcome.ejs: Google button instead of password form.
  • shared-styles.ejs: .btn-google styling.
  • .env.example: GOOGLE_CLIENT_ID/SECRET/REDIRECT_URI + ADMIN_EMAIL.

Existing users are matched on email (owner retains their site).
DO NOT deploy to roboburr until the Google credentials are in .env, otherwise
the owner locks themselves out.

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

  • Property mode set to 100644
File size: 8.9 KB
RevLine 
[7bc636b]1<div class="container ax-page">
2
3 <header class="ax-header">
4 <a href="/" class="ax-back" aria-label="Terug naar home">←</a>
5 <div>
6 <h1>Account</h1>
[c80e78b]7 <p class="ax-tagline">Profiel en avatar.</p>
[7bc636b]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 <%# ── PROFILE ────────────────────────────────────────────── %>
15 <section class="ax-card">
16 <div class="ax-card-title">Profiel</div>
17
18 <div class="ax-profile-id">
19 <div class="ax-profile-avatar">
20 <% if (account.avatar_url) { %>
21 <img src="<%= account.avatar_url %>" alt="">
22 <% } else { %>
23 <span><%= account.username.charAt(0).toUpperCase() %></span>
24 <% } %>
25 </div>
26 <div class="ax-profile-meta">
27 <div class="ax-profile-name"><%= account.username %></div>
28 <div class="ax-profile-role"><%= account.role %> · <%= account.email %></div>
29 <% if (account.created_at) { %>
30 <div class="ax-profile-joined">Lid sinds <%= formatDate(account.created_at) %></div>
31 <% } %>
32 </div>
33 </div>
34
35 <form action="/account/avatar" method="post" enctype="multipart/form-data" class="ax-form">
36 <label class="ax-field ax-file">
37 <span>Avatar uploaden <small>(jpg/png/webp/gif, max 5 MB)</small></span>
38 <span class="ax-file-control">
39 <span class="ax-btn ax-btn-secondary ax-file-btn">📷 Kies bestand</span>
40 <span class="ax-file-name" data-empty>Geen bestand gekozen</span>
41 <input type="file" name="avatar" accept="image/jpeg,image/png,image/webp,image/gif" required>
42 </span>
43 </label>
44 <div class="ax-form-actions">
45 <button type="submit" class="ax-btn ax-btn-primary">⬆ Uploaden</button>
46 <% if (account.avatar_url) { %>
47 <%# Separate <form> block kept inline since it submits to a different endpoint. %>
48 <button type="button" class="ax-btn" onclick="document.getElementById('avatar-remove-form').submit()">Avatar verwijderen</button>
49 <% } %>
50 </div>
51 </form>
52 <% if (account.avatar_url) { %>
53 <form action="/account/avatar/remove" method="post" id="avatar-remove-form" hidden></form>
54 <% } %>
55
56 <form action="/account/profile" method="post" class="ax-form ax-form-bio">
57 <label class="ax-field">
58 <span>Bio</span>
59 <textarea name="bio" rows="3" maxlength="500" placeholder="Een korte regel over jezelf"><%= account.bio || '' %></textarea>
60 </label>
61 <div class="ax-form-actions">
62 <button type="submit" class="ax-btn ax-btn-primary">💾 Bio opslaan</button>
63 </div>
64 </form>
65 </section>
66
[c80e78b]67 <%# ── INLOG ─────────────────────────────────────────────── %>
[7bc636b]68 <section class="ax-card">
[c80e78b]69 <div class="ax-card-title">Inloggen</div>
70 <p class="ax-tagline" style="margin:0">Je bent ingelogd via Google (<%= account.email %>). Er is geen apart wachtwoord.</p>
[7bc636b]71 </section>
72
73</div>
74
75<style>
76.ax-page { max-width: 720px; margin: 1.5rem auto 4rem; padding: 0 1rem; }
77.ax-header { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 1.5rem; }
78.ax-header h1 { font-family: var(--font-display, serif); font-size: 1.75rem; margin: 0 0 0.25rem; }
79.ax-tagline { color: var(--ink-muted, var(--ink-soft)); margin: 0; font-size: 0.9rem; }
80.ax-back {
81 display: inline-flex; align-items: center; justify-content: center;
82 width: 40px; height: 40px;
83 border: 1px solid var(--rule); border-radius: 8px;
84 background: var(--paper); color: var(--ink); text-decoration: none;
85 font-size: 1.1rem; flex-shrink: 0; transition: border-color 120ms;
86}
87.ax-back:hover { border-color: var(--accent); }
88
89.ax-flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
90.ax-flash-ok { background: rgba(40,160,90,.15); color: #2a9d5e; border: 1px solid rgba(40,160,90,.3); }
91.ax-flash-err { background: rgba(200,60,60,.15); color: #c33; border: 1px solid rgba(200,60,60,.3); }
92
93/* ─── Cards ────────────────────────────────────────────────────── */
94.ax-card {
95 background: var(--paper);
96 border: 1px solid var(--rule);
97 border-radius: 12px;
98 padding: 1.25rem;
99 margin-bottom: 1rem;
100}
101.ax-card-title {
102 font-family: var(--font-display, serif);
103 font-size: 1.15rem;
104 font-weight: 600;
105 margin-bottom: 1rem;
106}
107
108/* ─── Form fields ──────────────────────────────────────────────── */
109.ax-form { display: flex; flex-direction: column; gap: 0.85rem; }
110.ax-form-bio { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
111.ax-row { display: grid; gap: 0.85rem; }
112.ax-row-2 { grid-template-columns: 1fr 1fr; }
113@media (max-width: 600px) { .ax-row-2 { grid-template-columns: 1fr; } }
114
115.ax-field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
116.ax-field > span {
117 font-size: 0.8rem; font-weight: 600;
118 color: var(--ink-soft);
119 display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap;
120}
121.ax-field > span small { font-weight: 400; color: var(--ink-muted); font-size: 0.95em; }
122.ax-field input[type="text"],
123.ax-field input[type="email"],
124.ax-field input[type="password"],
125.ax-field input[type="url"],
126.ax-field select,
127.ax-field textarea {
128 width: 100%;
129 box-sizing: border-box;
130 padding: 0.6rem 0.75rem;
131 border: 1px solid var(--rule);
132 border-radius: 6px;
133 background: var(--paper-2);
134 color: var(--ink);
135 font-family: var(--font-ui, system-ui), sans-serif;
136 font-size: 0.95rem;
137 -webkit-appearance: none; appearance: none;
138 transition: border-color 120ms;
139}
140.ax-field textarea { resize: vertical; min-height: 70px; font-family: inherit; }
141.ax-field input:focus, .ax-field select:focus, .ax-field textarea:focus {
142 outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
143}
144
145/* ─── File upload ─────────────────────────────────────────────── */
146.ax-file-control {
147 display: flex; align-items: center; gap: 0.5rem;
148 flex-wrap: wrap;
149 position: relative;
150 min-height: 40px;
151}
152.ax-file-control input[type="file"] {
153 position: absolute; inset: 0;
154 opacity: 0; cursor: pointer;
155 z-index: 2;
156}
157.ax-file-btn { pointer-events: none; }
158.ax-file-name {
159 font-size: 0.85rem;
160 color: var(--ink);
161 word-break: break-all;
162 flex: 1; min-width: 0;
163}
164.ax-file-name[data-empty] { color: var(--ink-muted, var(--ink-soft)); }
165
166.ax-form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
167
168/* ─── Buttons ──────────────────────────────────────────────────── */
169.ax-btn {
170 display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
171 padding: 0.55rem 1rem;
172 border: 1px solid var(--rule); background: var(--paper-2);
173 color: var(--ink);
174 font-family: var(--font-ui, system-ui), sans-serif;
175 font-size: 0.9rem; font-weight: 500;
176 text-decoration: none; border-radius: 6px;
177 cursor: pointer; min-height: 40px;
178 transition: background 120ms, border-color 120ms;
179 -webkit-tap-highlight-color: transparent;
180}
181.ax-btn:hover { border-color: var(--accent); }
182.ax-btn-secondary { background: var(--paper-2); }
183.ax-btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
184.ax-btn-primary:hover { opacity: 0.92; border-color: var(--accent); }
185
186/* ─── Profile ID row ──────────────────────────────────────────── */
187.ax-profile-id {
188 display: flex; align-items: center; gap: 1rem;
189 padding-bottom: 1rem;
190 border-bottom: 1px solid var(--rule);
191 margin-bottom: 1rem;
192}
193.ax-profile-avatar {
194 width: 64px; height: 64px;
195 border-radius: 50%;
196 overflow: hidden;
197 background: var(--paper-2); /* neutral so transparent avatars blend */
198 color: var(--accent); /* accent only for the fallback initial */
199 display: inline-flex; align-items: center; justify-content: center;
200 font-family: var(--font-display, serif);
201 font-size: 1.6rem; font-weight: 600;
202 flex-shrink: 0;
203}
204.ax-profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
205.ax-profile-meta { min-width: 0; }
206.ax-profile-name { font-weight: 600; font-size: 1.1rem; }
207.ax-profile-role,
208.ax-profile-joined {
209 color: var(--ink-muted, var(--ink-soft));
210 font-size: 0.85rem;
211}
212
213@media (max-width: 480px) {
214 .ax-profile-id { flex-direction: column; align-items: flex-start; gap: 0.75rem; text-align: left; }
215}
216</style>
Note: See TracBrowser for help on using the repository browser.