source: Klonkt/src/views/pages/admin.ejs@ 2e247e4

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

Newsletter / mailing list (premium feature #1) + SMTP wiring

Email infrastructure reuses src/config/mailer.js (env SMTP_*, graceful: without
SMTP no sending, sign-ups still work via single opt-in).

  • DB: subscribers table (per-site, status pending/confirmed/unsub, token) + newsletters table (send history). Idempotent in initializeDatabase.
  • SubscriberService: addSubscriber (double opt-in if SMTP, otherwise single), confirm, unsubscribe, confirmedFor, counts. Email validation + dedupe per (site, email).
  • routes/newsletter.js (public, premium-gated; unsubscribe always works): GET/POST /nieuwsbrief, /nieuwsbrief/bevestigen/:token, /nieuwsbrief/uitschrijven/:token. Confirm/unsub links absolute via PUBLIC_BASE_URL + siteUrlBase.
  • routes/admin-newsletter.js (site admin + premium): GET /admin/newsletter (compose + counts + history + shareable signup link + SMTP warning), POST /admin/newsletter/send (to confirmed subscribers, unsubscribe link per email, history written).
  • views: pages/newsletter.ejs (multi-state) + pages/admin-newsletter.ejs.
  • admin dashboard: premium links Newsletter + Press kit added.

Feature #2 (download-for-email) and #8 (notify) reuse subscribers. node --check
passed; local test suite missing better-sqlite3 (runs on the VPS).

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

  • Property mode set to 100644
File size: 8.8 KB
Line 
1<div class="container admin-page">
2 <h1>Beheer</h1>
3 <% if (tenancy === 'hub') { %>
4 <p class="admin-tagline">Hub-modus — bedrijfssite met gebruikers, elk hun eigen Klonkt Hub.</p>
5 <% } else { %>
6 <p class="admin-tagline">Solo-modus — jouw site.</p>
7 <% } %>
8
9 <nav class="admin-quick-links" aria-label="Beheer-snelkoppelingen">
10 <% if (tenancy === 'hub') { %>
11 <a href="/admin/sites" class="btn">🌐 Sites</a>
12 <a href="/admin/users" class="btn">👥 Gebruikers</a>
13 <a href="/admin/audio" class="btn">🎵 Audio</a>
14 <a href="/admin/playlists" class="btn">📃 Playlists</a>
15 <a href="/admin/comments" class="btn">💬 Reacties</a>
16 <% if (primarySite) { %><a href="/admin/seo" class="btn">🔎 SEO</a><% } %>
17 <a href="/admin/settings" class="btn">⚙️ Instellingen</a>
18 <% } else { %>
19 <a href="/posts/new" class="btn">✍️ Nieuwe post</a>
20 <a href="/admin/audio" class="btn">🎵 Audio</a>
21 <a href="/admin/comments" class="btn">💬 Reacties</a>
22 <% if (primarySite) { %>
23 <a href="/admin/sites/<%= primarySite.slug %>/edit" class="btn">🎨 Uiterlijk</a>
24 <% } else { %>
25 <a href="/admin/sites/new" class="btn">🎨 Maak je site aan</a>
26 <% } %>
27 <% if (tenancy === 'circle') { %>
28 <a href="/admin/circle" class="btn">🔗 Cirkel</a>
29 <% } %>
30 <% if (primarySite) { %><a href="/admin/seo" class="btn">🔎 SEO</a><% } %>
31 <a href="/admin/settings" class="btn">⚙️ Instellingen</a>
32 <% } %>
33 <% if (typeof premiumUnlocked === 'undefined' || premiumUnlocked) { %>
34 <a href="/admin/stats" class="btn">📊 Statistieken</a>
35 <a href="/admin/newsletter" class="btn">✉️ Nieuwsbrief</a>
36 <% if (tenancy !== 'hub' && primarySite) { %><a href="/pers" class="btn" target="_blank">📰 Perskit</a><% } %>
37 <% } %>
38 <a href="/admin/updates" class="btn">🔄 Updates</a>
39 </nav>
40
41 <div class="admin-stats">
42 <% if (tenancy === 'hub') { %>
43 <div class="stat-card"><div class="stat-num"><%= stats.users %></div><div class="stat-label">Gebruikers</div></div>
44 <div class="stat-card"><div class="stat-num"><%= stats.sites %></div><div class="stat-label">Sites</div></div>
45 <% } %>
46 <div class="stat-card"><div class="stat-num"><%= stats.posts %></div><div class="stat-label">Posts</div></div>
47 <div class="stat-card"><div class="stat-num"><%= stats.published %></div><div class="stat-label">Gepubliceerd</div></div>
48 </div>
49
50 <% if (typeof posts !== 'undefined' && posts && posts.length) { %>
51 <% var _drafts = posts.filter(function(p){ return p.isDraft; }).length; %>
52 <h2>Posts<% if (_drafts) { %> <span class="pl-draftcount"><%= _drafts %> concept<%= _drafts === 1 ? '' : 'en' %></span><% } %></h2>
53 <ul class="post-admin-list">
54 <% posts.forEach(function(p) { %>
55 <li class="pal-row<%= p.isDraft ? ' is-draft' : '' %>">
56 <a class="pal-title" href="<%= p.editUrl %>">
57 <% if (p.isDraft) { %><span class="pal-badge">Concept</span><% } %>
58 <span class="pal-name"><%= p.title || '(zonder titel)' %></span>
59 </a>
60 <span class="pal-actions">
61 <a class="pal-link" href="<%= p.editUrl %>">Bewerken</a>
62 <% if (!p.isDraft) { %><a class="pal-link" href="<%= p.viewUrl %>">Bekijk</a><% } %>
63 </span>
64 </li>
65 <% }); %>
66 </ul>
67 <% } %>
68
69 <% if (sites && sites.length) { %>
70 <h2>Sites</h2>
71 <table class="admin-table">
72 <thead>
73 <tr><th>Slug</th><th>Title</th><th>Owner</th><th>Created</th></tr>
74 </thead>
75 <tbody>
76 <% sites.forEach(function(s) { %>
77 <tr>
78 <td><code><%= s.slug %></code></td>
79 <td><%= s.title %></td>
80 <td><%= s.owner_username || '—' %></td>
81 <td><%= formatDate(s.created_at) %></td>
82 </tr>
83 <% }); %>
84 </tbody>
85 </table>
86 <% } %>
87
88 <% if (users && users.length) { %>
89 <h2>Users</h2>
90 <table class="admin-table">
91 <thead>
92 <tr><th>Username</th><th>Email</th><th>Role</th><th>Joined</th></tr>
93 </thead>
94 <tbody>
95 <% users.forEach(function(u) { %>
96 <tr>
97 <td><%= u.username %></td>
98 <td><%= u.email %></td>
99 <td><span class="role-pill role-<%= u.role %>"><%= u.role %></span></td>
100 <td><%= formatDate(u.created_at) %></td>
101 </tr>
102 <% }); %>
103 </tbody>
104 </table>
105 <% } %>
106
107</div>
108
109<style>
110.admin-page { max-width: 1000px; margin: 3rem auto; padding: 0 1rem; }
111.admin-page h1 { font-family: var(--font-display, serif); font-size: 2rem; margin: 0 0 0.25rem; }
112.admin-page h2 { font-family: var(--font-display, serif); font-size: 1.4rem; margin: 2rem 0 0.75rem; }
113.admin-tagline { color: var(--ink-muted); margin: 0 0 2rem; }
114.admin-tagline em { font-style: normal; opacity: 0.7; }
115
116/* Posts/concepten-lijst */
117.pl-draftcount { font-family: var(--font-ui, system-ui); font-size: 0.8rem; font-weight: 700; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.1rem 0.55rem; border-radius: 99px; vertical-align: middle; }
118.post-admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
119.pal-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.9rem; border: 1px solid var(--rule); border-radius: 10px; background: var(--paper-2); transition: border-color 120ms; }
120.pal-row:hover { border-color: var(--accent); }
121.pal-row.is-draft { border-left: 3px solid var(--accent); }
122.pal-title { display: inline-flex; align-items: center; gap: 0.6rem; min-width: 0; color: var(--ink); text-decoration: none; font-weight: 600; }
123.pal-title:hover { color: var(--accent); }
124.pal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
125.pal-badge { flex-shrink: 0; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.1rem 0.5rem; border-radius: 99px; }
126.pal-actions { display: flex; gap: 0.75rem; flex-shrink: 0; }
127.pal-link { color: var(--ink-muted); font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
128.pal-link:hover { color: var(--accent); text-decoration: underline; }
129
130/* Quick-links grid — mobile-first.
131 auto-fit + minmax means: as many equal columns as fit, each at least 140px.
132 Mobile (~360-440px): 2 per row.
133 Tablet (~480-700px): 3 per row.
134 Desktop (≥ ~720px): all 5 in a single row. */
135.admin-quick-links {
136 display: grid;
137 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
138 gap: 0.5rem;
139 margin: 0 0 1.5rem;
140 padding: 0;
141}
142.admin-quick-links .btn {
143 justify-content: center;
144 padding: 0.7rem 0.9rem;
145 font-weight: 600;
146 text-align: center;
147}
148.admin-quick-links .btn:hover {
149 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
150 border-color: var(--accent);
151}
152
153.admin-stats {
154 display: grid;
155 grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
156 gap: 0.75rem;
157 margin-bottom: 1rem;
158}
159.stat-card {
160 background: var(--paper-2);
161 border: 1px solid var(--rule);
162 border-radius: 8px;
163 padding: 1rem 1.25rem;
164 text-align: center;
165}
166.stat-num {
167 font-size: 2rem;
168 font-weight: 700;
169 color: var(--accent);
170 line-height: 1;
171 font-family: var(--font-display, serif);
172}
173.stat-label {
174 color: var(--ink-muted);
175 font-size: 0.85rem;
176 text-transform: uppercase;
177 letter-spacing: 0.05em;
178 margin-top: 0.25rem;
179}
180
181.admin-table {
182 width: 100%;
183 border-collapse: collapse;
184 background: var(--paper-2);
185 border: 1px solid var(--rule);
186 border-radius: 8px;
187 overflow: hidden;
188}
189.admin-table th, .admin-table td {
190 padding: 0.6rem 0.9rem;
191 text-align: left;
192 border-bottom: 1px solid var(--rule);
193}
194.admin-table th {
195 background: var(--paper);
196 font-weight: 600;
197 font-size: 0.85rem;
198 text-transform: uppercase;
199 letter-spacing: 0.05em;
200 color: var(--ink-muted);
201}
202.admin-table tr:last-child td { border-bottom: 0; }
203.admin-table code { background: var(--paper); padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85rem; }
204
205.role-pill {
206 display: inline-block;
207 padding: 0.1rem 0.5rem;
208 border-radius: 10px;
209 font-size: 0.75rem;
210 text-transform: uppercase;
211 letter-spacing: 0.05em;
212 background: var(--paper);
213 color: var(--ink-muted);
214}
215.role-pill.role-god { background: var(--accent); color: white; }
216.role-pill.role-admin { background: var(--paper); color: var(--accent); border: 1px solid var(--accent); }
217
218.admin-todo {
219 margin: 2rem 0 0;
220 padding: 0.75rem 1rem;
221 background: var(--paper-2);
222 border-left: 3px solid var(--accent);
223 border-radius: 4px;
224 font-size: 0.9rem;
225 color: var(--ink-muted);
226}
227
228@media (max-width: 600px) {
229 .admin-table { font-size: 0.85rem; }
230 .admin-table th, .admin-table td { padding: 0.45rem 0.6rem; }
231}
232</style>
Note: See TracBrowser for help on using the repository browser.