@poadio/starter-angular 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.dockerignore +9 -0
  2. package/.env.example +7 -0
  3. package/Dockerfile +20 -0
  4. package/README.md +91 -2
  5. package/angular.json +119 -0
  6. package/bun.lock +1057 -0
  7. package/docker/40-env-json.sh +39 -0
  8. package/docker/nginx.conf +24 -0
  9. package/package.json +86 -4
  10. package/public/logo.svg +1 -0
  11. package/public/providers/google.svg +1 -0
  12. package/public/providers/keycloak.svg +1 -0
  13. package/scripts/dev.mjs +30 -0
  14. package/scripts/env.mjs +96 -0
  15. package/scripts/routes.mjs +155 -0
  16. package/src/app/app.config.ts +16 -0
  17. package/src/app/app.meta.ts +43 -0
  18. package/src/app/app.routes.gen.ts +7 -0
  19. package/src/app/app.routes.ts +32 -0
  20. package/src/app/app.ts +17 -0
  21. package/src/app/core/auth.service.ts +117 -0
  22. package/src/app/core/captcha.ts +94 -0
  23. package/src/app/core/config.ts +17 -0
  24. package/src/app/core/env.ts +27 -0
  25. package/src/app/core/guards.ts +33 -0
  26. package/src/app/core/messages.ts +38 -0
  27. package/src/app/core/poad.ts +46 -0
  28. package/src/app/core/providers.ts +32 -0
  29. package/src/app/core/theme.service.ts +37 -0
  30. package/src/app/layout/_layout.scss +799 -0
  31. package/src/app/layout/app-layout.ts +263 -0
  32. package/src/app/layout/app-menu.ts +68 -0
  33. package/src/app/layout/app-menuitem.ts +105 -0
  34. package/src/app/layout/brand.ts +50 -0
  35. package/src/app/layout/canvas-head.ts +78 -0
  36. package/src/app/layout/layout.service.ts +159 -0
  37. package/src/app/pages/(auth)/login.html +128 -0
  38. package/src/app/pages/(auth)/login.ts +194 -0
  39. package/src/app/pages/(auth)/mfa.ts +61 -0
  40. package/src/app/pages/(auth)/reset.ts +53 -0
  41. package/src/app/pages/app/_layout.ts +5 -0
  42. package/src/app/pages/app/account.html +233 -0
  43. package/src/app/pages/app/account.ts +262 -0
  44. package/src/app/pages/app/hello/[name].ts +35 -0
  45. package/src/app/pages/app/index.ts +82 -0
  46. package/src/app/pages/app/public.ts +33 -0
  47. package/src/app/pages/index.ts +280 -0
  48. package/src/app/pages/setup.ts +51 -0
  49. package/src/index.html +13 -0
  50. package/src/main.ts +9 -0
  51. package/src/styles.scss +151 -0
  52. package/tsconfig.app.json +15 -0
  53. package/tsconfig.json +31 -0
@@ -0,0 +1,233 @@
1
+ @if (auth.user(); as user) {
2
+ <section class="page page-wide">
3
+ <div class="row">
4
+ <h1>{{ user.user_metadata['name'] || user.email || 'Compte anonyme' }}</h1>
5
+ @if (user.is_anonymous) {
6
+ <cad-tag value="anonyme" severity="warning" size="sm" />
7
+ }
8
+ @if (user.email_confirmed_at) {
9
+ <cad-tag value="adresse confirmée" severity="success" size="sm" />
10
+ }
11
+ </div>
12
+
13
+ <cad-tabs [(value)]="tab" variant="line" scrollable>
14
+ <!-- Profil ---------------------------------------------------------->
15
+ <cad-tab value="profile" label="Profil" icon="user">
16
+ <cad-card>
17
+ <dl class="props">
18
+ <dt>Identifiant</dt>
19
+ <dd class="mono">{{ user.id }}</dd>
20
+ <dt>Adresse</dt>
21
+ <dd>{{ user.email || '—' }}</dd>
22
+ @if (user.new_email) {
23
+ <dt>Nouvelle adresse</dt>
24
+ <dd>{{ user.new_email }} (en attente)</dd>
25
+ }
26
+ <dt>Fournisseurs</dt>
27
+ <dd>{{ (user.app_metadata.providers ?? []).join(', ') || '—' }}</dd>
28
+ <dt>Créé le</dt>
29
+ <dd>{{ user.created_at | date: 'medium' }}</dd>
30
+ <dt>Dernière connexion</dt>
31
+ <dd>{{ user.last_sign_in_at | date: 'medium' }}</dd>
32
+ </dl>
33
+ </cad-card>
34
+ <cad-card header="Métadonnées">
35
+ <form class="form" (ngSubmit)="saveProfile()">
36
+ <cad-field label="Nom" hint="Enregistré dans user_metadata.name">
37
+ <input cadInput name="name" [(ngModel)]="name" />
38
+ </cad-field>
39
+ <cad-field plain label="Langue des e-mails" hint="Enregistrée dans user_metadata.locale">
40
+ <cad-select name="locale" [(ngModel)]="locale" [options]="locales" optionLabel="label" optionValue="value" />
41
+ </cad-field>
42
+ <div class="row">
43
+ <button cadButton type="submit" [loading]="busy() === 'profile'">Enregistrer</button>
44
+ <button cadButton type="button" variant="text" [loading]="busy() === 'reload'" (click)="reloadUser()">
45
+ <cad-icon name="refresh" [size]="16" /> Relire
46
+ </button>
47
+ </div>
48
+ </form>
49
+ </cad-card>
50
+ </cad-tab>
51
+
52
+ <!-- Sécurité -------------------------------------------------------->
53
+ <cad-tab value="security" label="Sécurité" icon="lock">
54
+ @if (user.is_anonymous) {
55
+ <cad-message severity="info" variant="soft">
56
+ Compte anonyme : ajoutez une adresse pour le garder. Confirmez-la, puis choisissez un mot de passe.
57
+ </cad-message>
58
+ }
59
+ <cad-card [header]="user.is_anonymous ? 'Ajouter une adresse' : 'Changer d’adresse'">
60
+ @if (emailSentTo(); as to) {
61
+ <form class="form" (ngSubmit)="confirmEmail()">
62
+ <p class="muted">Code envoyé à {{ to }} (le lien de l’e-mail marche aussi).</p>
63
+ <cad-field label="Code" required>
64
+ <input cadInput mono name="ecode" [(ngModel)]="emailCode" inputmode="numeric" maxlength="6" autocomplete="one-time-code" />
65
+ </cad-field>
66
+ <div class="row">
67
+ <button cadButton type="submit" [loading]="busy() === 'email'" [disabled]="emailCode().length !== 6">Confirmer</button>
68
+ <button cadButton type="button" variant="text" (click)="emailSentTo.set(null)">Annuler</button>
69
+ </div>
70
+ </form>
71
+ } @else {
72
+ <form class="form" (ngSubmit)="changeEmail()">
73
+ <cad-field label="Nouvelle adresse" required>
74
+ <input cadInput type="email" name="nemail" [(ngModel)]="newEmail" autocomplete="email" />
75
+ </cad-field>
76
+ <button cadButton type="submit" [loading]="busy() === 'email'" [disabled]="!newEmail()">Envoyer la confirmation</button>
77
+ </form>
78
+ }
79
+ </cad-card>
80
+ <cad-card header="Mot de passe">
81
+ <form class="form" (ngSubmit)="changePassword()">
82
+ <cad-field plain label="Nouveau mot de passe" required>
83
+ <cad-password name="npass" [(ngModel)]="newPassword" toggleMask feedback autocomplete="new-password" />
84
+ </cad-field>
85
+ <cad-field label="Code de réauthentification" optionalText="si exigé" hint="Exigé quand secure_password_change est actif">
86
+ <input cadInput mono name="nonce" [(ngModel)]="nonce" inputmode="numeric" maxlength="6" />
87
+ </cad-field>
88
+ <div class="row">
89
+ <button cadButton type="submit" [loading]="busy() === 'password'" [disabled]="!newPassword()">Changer</button>
90
+ <button cadButton type="button" variant="text" [loading]="busy() === 'reauth'" (click)="reauthenticate()" [disabled]="!user.email">
91
+ Recevoir un code
92
+ </button>
93
+ </div>
94
+ </form>
95
+ </cad-card>
96
+ </cad-tab>
97
+
98
+ <!-- MFA ------------------------------------------------------------->
99
+ <cad-tab value="mfa" label="MFA" icon="shield" [count]="factors().length || null">
100
+ <cad-card header="Application d’authentification (TOTP)">
101
+ <div class="form">
102
+ <div class="row">
103
+ <span class="muted">Niveau de la session</span>
104
+ <cad-tag [value]="auth.claims()?.aal ?? '—'" [severity]="auth.claims()?.aal === 'aal2' ? 'success' : 'neutral'" size="sm" />
105
+ </div>
106
+ @if (factors().length) {
107
+ <ul class="list">
108
+ @for (f of factors(); track f.id) {
109
+ <li>
110
+ <cad-icon name="smartphone" [size]="18" />
111
+ <span class="grow">{{ f.friendly_name || 'TOTP' }} <span class="muted mono">{{ f.id.slice(0, 8) }}</span></span>
112
+ <cad-tag [value]="f.status === 'verified' ? 'actif' : 'non vérifié'" [severity]="f.status === 'verified' ? 'success' : 'warning'" size="sm" />
113
+ <button cadButton variant="text" severity="danger" size="sm" [loading]="busy() === 'factor-' + f.id" (click)="unenroll(f.id)">
114
+ <cad-icon name="trash-2" [size]="16" /> Retirer
115
+ </button>
116
+ </li>
117
+ }
118
+ </ul>
119
+ @if (auth.claims()?.aal !== 'aal2') {
120
+ <cad-message severity="warning" variant="soft" size="sm">Retirer un facteur actif, ou en ajouter un, exige une session aal2.</cad-message>
121
+ }
122
+ } @else {
123
+ <p class="muted">Aucun facteur.</p>
124
+ }
125
+ </div>
126
+ </cad-card>
127
+
128
+ <cad-card header="Ajouter un facteur">
129
+ @if (enrollment(); as e) {
130
+ <form class="form" (ngSubmit)="confirmEnroll()">
131
+ <div class="qr">
132
+ <img [src]="qrUrl()" alt="QR code à scanner avec l’application d’authentification" />
133
+ <div>
134
+ <p class="muted">Scannez le QR code, ou saisissez la clé :</p>
135
+ <p class="mono">{{ e.totp.secret }}</p>
136
+ </div>
137
+ </div>
138
+ <cad-field label="Code affiché par l’application" required>
139
+ <input cadInput mono name="ecode" [(ngModel)]="enrollCode" inputmode="numeric" maxlength="6" autocomplete="one-time-code" />
140
+ </cad-field>
141
+ <div class="row">
142
+ <button cadButton type="submit" [loading]="busy() === 'enroll'" [disabled]="enrollCode().length !== 6">Activer</button>
143
+ <button cadButton type="button" variant="text" (click)="cancelEnroll()">Annuler</button>
144
+ </div>
145
+ </form>
146
+ } @else {
147
+ <form class="form" (ngSubmit)="enroll()">
148
+ <cad-field label="Nom du facteur" optionalText="facultatif">
149
+ <input cadInput name="fname" [(ngModel)]="factorName" placeholder="Téléphone" />
150
+ </cad-field>
151
+ <button cadButton type="submit" [loading]="busy() === 'enroll'"><cad-icon name="qr-code" [size]="16" /> Générer le QR code</button>
152
+ </form>
153
+ }
154
+ </cad-card>
155
+ </cad-tab>
156
+
157
+ <!-- Identités ------------------------------------------------------->
158
+ <cad-tab value="identities" label="Identités" icon="link" [count]="identities().length || null">
159
+ <cad-card>
160
+ <ul class="list">
161
+ @for (i of identities(); track i.identity_id) {
162
+ <li>
163
+ <cad-tag [value]="label(i.provider)" severity="info" size="sm" />
164
+ <span class="grow">{{ i.email || i.identity_data['email'] || i.id }}</span>
165
+ <span class="muted">{{ i.last_sign_in_at | date: 'short' }}</span>
166
+ <button
167
+ cadButton
168
+ variant="text"
169
+ severity="danger"
170
+ size="sm"
171
+ [disabled]="identities().length < 2"
172
+ [loading]="busy() === 'unlink-' + i.identity_id"
173
+ (click)="unlink(i.identity_id)"
174
+ >
175
+ <cad-icon name="unlink" [size]="16" /> Retirer
176
+ </button>
177
+ </li>
178
+ } @empty {
179
+ <li class="muted">Aucune identité (compte anonyme).</li>
180
+ }
181
+ </ul>
182
+ </cad-card>
183
+ @if (linkable().length) {
184
+ <cad-card header="Lier un fournisseur">
185
+ <div class="row">
186
+ @for (p of linkable(); track p) {
187
+ <button cadButton variant="outline" [loading]="busy() === 'link-' + p" (click)="link(p)">@if (logo(p); as src) {<img class="logo" [src]="src" alt="" />} @else {<cad-icon name="link" [size]="16" />} {{ label(p) }}</button>
188
+ }
189
+ </div>
190
+ </cad-card>
191
+ }
192
+ </cad-tab>
193
+
194
+ <!-- Session --------------------------------------------------------->
195
+ <cad-tab value="session" label="Session" icon="key-round">
196
+ <cad-card header="Déconnexion">
197
+ <div class="row">
198
+ <button cadButton variant="outline" severity="danger" [loading]="busy() === 'signout-local'" (click)="signOut('local')">Se déconnecter</button>
199
+ <button cadButton variant="outline" severity="danger" [loading]="busy() === 'signout-others'" (click)="signOut('others')">Fermer les autres sessions</button>
200
+ <button cadButton variant="outline" severity="danger" [loading]="busy() === 'signout-global'" (click)="signOut('global')">Fermer toutes les sessions</button>
201
+ </div>
202
+ </cad-card>
203
+ <cad-card header="Sessions ouvertes">
204
+ <ul class="list">
205
+ @for (s of openSessions() ?? []; track s.id) {
206
+ <li>
207
+ <cad-icon [name]="s.current ? 'check' : 'smartphone'" [size]="18" />
208
+ <span class="grow">
209
+ {{ device(s.user_agent) }}
210
+ <span class="muted">· {{ s.ip || '—' }} · {{ s.refreshed_at || s.created_at | date: 'short' }}</span>
211
+ </span>
212
+ @if (s.current) {
213
+ <cad-tag value="cette session" severity="success" size="sm" />
214
+ }
215
+ <cad-tag [value]="s.aal" [severity]="s.aal === 'aal2' ? 'success' : 'neutral'" size="sm" />
216
+ <button cadButton variant="text" severity="danger" size="sm" [loading]="busy() === 'revoke-' + s.id" (click)="revokeSession(s)">
217
+ <cad-icon name="log-out" [size]="16" /> Fermer
218
+ </button>
219
+ </li>
220
+ } @empty {
221
+ <li class="muted">{{ openSessions() ? 'Aucune session' : 'Chargement…' }}</li>
222
+ }
223
+ </ul>
224
+ <div class="row" style="margin-top: 12px">
225
+ <button cadButton variant="text" size="sm" [loading]="busy() === 'sessions'" (click)="loadSessions()">
226
+ <cad-icon name="refresh" [size]="16" /> Actualiser
227
+ </button>
228
+ </div>
229
+ </cad-card>
230
+ </cad-tab>
231
+ </cad-tabs>
232
+ </section>
233
+ }
@@ -0,0 +1,262 @@
1
+ import { Component, computed, effect, inject, signal, untracked } from '@angular/core';
2
+ import { DatePipe } from '@angular/common';
3
+ import { FormsModule } from '@angular/forms';
4
+ import {
5
+ CadButtonComponent,
6
+ CadCardComponent,
7
+ CadFieldComponent,
8
+ CadIconComponent,
9
+ CadInputDirective,
10
+ CadMessageComponent,
11
+ CadPasswordComponent,
12
+ CadSelectComponent,
13
+ CadTabComponent,
14
+ CadTabsComponent,
15
+ CadTagComponent,
16
+ } from '@cadriciel/ui';
17
+ import type { SessionInfo, TotpEnrollment } from '@poadio/client-js';
18
+ import { AuthService } from '../../core/auth.service';
19
+ import { Poad } from '../../core/poad';
20
+ import { providerLabel, providerLogo } from '../../core/providers';
21
+
22
+ /** Options de la route (titre, accès), lues par le générateur de routes */
23
+ export const route = { title: 'Mon compte', auth: true };
24
+
25
+ @Component({
26
+ selector: 'app-account',
27
+ imports: [
28
+ DatePipe,
29
+ FormsModule,
30
+ CadButtonComponent,
31
+ CadCardComponent,
32
+ CadFieldComponent,
33
+ CadIconComponent,
34
+ CadInputDirective,
35
+ CadMessageComponent,
36
+ CadPasswordComponent,
37
+ CadSelectComponent,
38
+ CadTabComponent,
39
+ CadTabsComponent,
40
+ CadTagComponent,
41
+ ],
42
+ templateUrl: './account.html',
43
+ styles: `
44
+ .logo {
45
+ width: 16px;
46
+ height: 16px;
47
+ }
48
+ .qr {
49
+ display: flex;
50
+ gap: 16px;
51
+ align-items: center;
52
+ flex-wrap: wrap;
53
+ img {
54
+ width: 180px;
55
+ height: 180px;
56
+ background: #fff;
57
+ border-radius: 8px;
58
+ padding: 6px;
59
+ }
60
+ }
61
+ .list {
62
+ list-style: none;
63
+ margin: 0;
64
+ padding: 0;
65
+ display: flex;
66
+ flex-direction: column;
67
+ gap: 10px;
68
+ li {
69
+ display: flex;
70
+ align-items: center;
71
+ gap: 10px;
72
+ flex-wrap: wrap;
73
+ }
74
+ .grow {
75
+ flex: 1;
76
+ min-width: 12ch;
77
+ }
78
+ }
79
+ `,
80
+ })
81
+ export default class AccountPage {
82
+ protected readonly auth = inject(AuthService);
83
+ protected readonly poad = inject(Poad);
84
+ protected readonly tab = signal<unknown>('profile');
85
+ protected readonly label = providerLabel;
86
+ protected readonly logo = providerLogo;
87
+
88
+ constructor() {
89
+ // Liste des sessions chargée à l'ouverture de l'onglet
90
+ effect(() => {
91
+ if (this.tab() === 'session') untracked(() => void this.loadSessions());
92
+ });
93
+ }
94
+ protected readonly busy = signal<string | null>(null);
95
+
96
+ // Profil
97
+ protected readonly name = signal(String(this.auth.user()?.user_metadata['name'] ?? ''));
98
+ /** Langue des e-mails : vide = celle du navigateur */
99
+ protected readonly locale = signal(String(this.auth.user()?.user_metadata['locale'] ?? ''));
100
+ protected readonly locales = [
101
+ { value: '', label: 'Celle du navigateur' },
102
+ { value: 'fr', label: 'Français' },
103
+ { value: 'en', label: 'English' },
104
+ ];
105
+
106
+ // Sécurité
107
+ protected readonly newPassword = signal('');
108
+ protected readonly nonce = signal('');
109
+ protected readonly newEmail = signal('');
110
+ protected readonly emailCode = signal('');
111
+ protected readonly emailSentTo = signal<string | null>(null);
112
+
113
+ // MFA
114
+ protected readonly factorName = signal('');
115
+ protected readonly enrollment = signal<TotpEnrollment | null>(null);
116
+ protected readonly enrollCode = signal('');
117
+ /** QR code en URL blob: (Angular refuse data:image/svg+xml dans <img src>) */
118
+ protected readonly qrUrl = computed(() => {
119
+ const qr = this.enrollment()?.totp.qr_code;
120
+ if (!qr) return null;
121
+ const raw = qr.slice(qr.indexOf(',') + 1);
122
+ let svg = raw;
123
+ try {
124
+ svg = decodeURIComponent(raw);
125
+ } catch {
126
+ /* SVG brut, non encodé */
127
+ }
128
+ return URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
129
+ });
130
+
131
+ // Session
132
+ protected readonly openSessions = signal<SessionInfo[] | null>(null);
133
+
134
+ protected readonly factors = computed(() => this.auth.user()?.factors ?? []);
135
+ protected readonly identities = computed(() => this.auth.user()?.identities ?? []);
136
+ protected readonly linkable = computed(() => {
137
+ const linked = new Set(this.identities().map((i) => i.provider));
138
+ return this.auth.oauthProviders().filter((p) => !linked.has(p));
139
+ });
140
+
141
+ protected async saveProfile(): Promise<void> {
142
+ await this.step(
143
+ 'profile',
144
+ () => this.poad.auth.updateUser({ data: { name: this.name(), locale: this.locale() || null } }),
145
+ 'Profil enregistré'
146
+ );
147
+ }
148
+
149
+ protected async changePassword(): Promise<void> {
150
+ const ok = await this.step(
151
+ 'password',
152
+ () => this.poad.auth.updateUser({ password: this.newPassword(), nonce: this.nonce() || undefined }),
153
+ 'Mot de passe changé'
154
+ );
155
+ if (ok) {
156
+ this.newPassword.set('');
157
+ this.nonce.set('');
158
+ }
159
+ }
160
+
161
+ protected async reauthenticate(): Promise<void> {
162
+ await this.step('reauth', () => this.poad.auth.reauthenticate(), 'Code envoyé par e-mail');
163
+ }
164
+
165
+ protected async changeEmail(): Promise<void> {
166
+ const ok = await this.step(
167
+ 'email',
168
+ () => this.poad.auth.updateUser({ email: this.newEmail() }, { redirectTo: this.auth.redirect('/account') }),
169
+ 'Confirmation envoyée à la nouvelle adresse'
170
+ );
171
+ if (ok) this.emailSentTo.set(this.newEmail());
172
+ }
173
+
174
+ protected async confirmEmail(): Promise<void> {
175
+ const to = this.emailSentTo();
176
+ if (!to) return;
177
+ const ok = await this.step(
178
+ 'email',
179
+ () => this.poad.auth.verifyOtp({ email: to, token: this.emailCode(), type: 'email_change' }),
180
+ 'Adresse changée'
181
+ );
182
+ if (ok) {
183
+ this.emailSentTo.set(null);
184
+ this.emailCode.set('');
185
+ this.newEmail.set('');
186
+ }
187
+ }
188
+
189
+ protected async enroll(): Promise<void> {
190
+ const e = await this.step('enroll', () => this.poad.auth.mfa.enroll({ friendlyName: this.factorName() || undefined }));
191
+ if (e) this.enrollment.set(e);
192
+ }
193
+
194
+ protected async confirmEnroll(): Promise<void> {
195
+ const e = this.enrollment();
196
+ if (!e) return;
197
+ const ok = await this.step(
198
+ 'enroll',
199
+ () => this.poad.auth.mfa.challengeAndVerify({ factorId: e.id, code: this.enrollCode() }),
200
+ 'Facteur activé, session en aal2'
201
+ );
202
+ if (ok) {
203
+ this.enrollment.set(null);
204
+ this.enrollCode.set('');
205
+ this.factorName.set('');
206
+ }
207
+ }
208
+
209
+ protected async cancelEnroll(): Promise<void> {
210
+ const e = this.enrollment();
211
+ this.enrollment.set(null);
212
+ if (e) await this.auth.run(() => this.poad.auth.mfa.unenroll(e.id));
213
+ }
214
+
215
+ protected async unenroll(id: string): Promise<void> {
216
+ await this.step(`factor-${id}`, () => this.poad.auth.mfa.unenroll(id), 'Facteur retiré');
217
+ }
218
+
219
+ protected async link(provider: string): Promise<void> {
220
+ await this.step(`link-${provider}`, () => this.poad.auth.linkIdentity({ provider, redirectTo: this.auth.redirect('/account') }));
221
+ }
222
+
223
+ protected async unlink(id: string): Promise<void> {
224
+ await this.step(`unlink-${id}`, () => this.poad.auth.unlinkIdentity(id), 'Identité retirée');
225
+ }
226
+
227
+ protected async loadSessions(): Promise<void> {
228
+ const list = await this.step('sessions', () => this.poad.auth.listSessions());
229
+ if (list) this.openSessions.set(list);
230
+ }
231
+
232
+ protected async revokeSession(s: SessionInfo): Promise<void> {
233
+ const ok = await this.step(`revoke-${s.id}`, () => this.poad.auth.revokeSession(s.id), s.current ? 'Déconnecté' : 'Session fermée');
234
+ if (ok && !s.current) await this.loadSessions();
235
+ }
236
+
237
+ /** Navigateur et système, lus grossièrement dans le user-agent */
238
+ protected device(ua: string | null): string {
239
+ if (!ua) return 'Inconnu';
240
+ const browser = /Edg\//.test(ua) ? 'Edge' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : /node|undici/i.test(ua) ? 'Node.js' : ua.split(/[ /]/)[0];
241
+ const os = /Mac OS X/.test(ua) ? 'macOS' : /Windows/.test(ua) ? 'Windows' : /Android/.test(ua) ? 'Android' : /iPhone|iPad/.test(ua) ? 'iOS' : /Linux/.test(ua) ? 'Linux' : '';
242
+ return os ? `${browser} · ${os}` : browser;
243
+ }
244
+
245
+ protected async reloadUser(): Promise<void> {
246
+ await this.step('reload', () => this.poad.auth.getUser());
247
+ }
248
+
249
+ protected async signOut(scope: 'local' | 'others' | 'global'): Promise<void> {
250
+ const msg = { local: 'Déconnecté', others: 'Autres sessions fermées', global: 'Toutes les sessions fermées' }[scope];
251
+ await this.step(`signout-${scope}`, () => this.poad.auth.signOut({ scope }), msg);
252
+ }
253
+
254
+ private async step<T>(key: string, fn: () => Promise<import('@poadio/client-js').Result<T>>, success?: string): Promise<T | null> {
255
+ this.busy.set(key);
256
+ try {
257
+ return await this.auth.run(fn, success);
258
+ } finally {
259
+ this.busy.set(null);
260
+ }
261
+ }
262
+ }
@@ -0,0 +1,35 @@
1
+ import { Component, input } from '@angular/core';
2
+ import { RouterLink } from '@angular/router';
3
+ import { CadCardComponent } from '@cadriciel/ui';
4
+
5
+ /** Exemple de route dynamique : /app/hello/:name, le paramètre arrive en input() */
6
+ export const route = { title: 'Route dynamique' };
7
+
8
+ @Component({
9
+ selector: 'app-hello',
10
+ imports: [RouterLink, CadCardComponent],
11
+ template: `
12
+ <section class="page">
13
+ <p class="lead">
14
+ Le fichier <code>pages/app/hello/[name].ts</code> répond à <code>/app/hello/:name</code> ; le paramètre arrive dans
15
+ <code>name = input()</code>.
16
+ </p>
17
+ <cad-card>
18
+ <h2 class="hello">Bonjour {{ name() }} !</h2>
19
+ <p class="muted">
20
+ Essayez <a routerLink="/app/hello/Ada">Ada</a>, <a routerLink="/app/hello/Grace">Grace</a> ou
21
+ <a routerLink="/app/hello/Linus">Linus</a>.
22
+ </p>
23
+ </cad-card>
24
+ </section>
25
+ `,
26
+ styles: `
27
+ .hello {
28
+ margin: 0 0 8px;
29
+ font-size: 20px;
30
+ }
31
+ `,
32
+ })
33
+ export default class HelloPage {
34
+ readonly name = input('');
35
+ }
@@ -0,0 +1,82 @@
1
+ import { Component, computed, inject } from '@angular/core';
2
+ import { RouterLink } from '@angular/router';
3
+ import { CadButtonComponent, CadCardComponent, CadIconComponent, CadTagComponent } from '@cadriciel/ui';
4
+ import { AuthService } from '../../core/auth.service';
5
+ import { providerLabel } from '../../core/providers';
6
+
7
+ /** Page d'accueil de l'application connectée : point de départ de vos propres pages */
8
+ /** Options de la route (titre, accès), lues par le générateur de routes */
9
+ export const route = { title: 'Tableau de bord', auth: true };
10
+
11
+ @Component({
12
+ selector: 'app-dashboard',
13
+ imports: [RouterLink, CadButtonComponent, CadCardComponent, CadIconComponent, CadTagComponent],
14
+ template: `
15
+ <section class="page page-wide">
16
+ <h2 class="hello">Bonjour {{ auth.displayName() }}</h2>
17
+ <p class="lead">Vous êtes connecté. Cette page est protégée par la garde <code>signedIn()</code>.</p>
18
+
19
+ <div class="cards">
20
+ <cad-card header="Session">
21
+ <dl class="props">
22
+ <dt>Adresse</dt>
23
+ <dd>{{ auth.user()?.email || '—' }}</dd>
24
+ <dt>Connexion</dt>
25
+ <dd>{{ providers() }}</dd>
26
+ <dt>Niveau</dt>
27
+ <dd>
28
+ <cad-tag [severity]="auth.claims()?.aal === 'aal2' ? 'success' : 'neutral'">{{ auth.claims()?.aal }}</cad-tag>
29
+ </dd>
30
+ <dt>Rôle</dt>
31
+ <dd>{{ auth.claims()?.role }}</dd>
32
+ </dl>
33
+ </cad-card>
34
+
35
+ <cad-card header="Et maintenant ?">
36
+ <ul class="next">
37
+ <li><cad-icon name="file-plus" [size]="15" /> Ajoutez vos pages dans <code>src/app/pages</code> et vos routes dans <code>app.routes.ts</code>.</li>
38
+ <li><cad-icon name="menu" [size]="15" /> Le menu se règle dans <code>app.meta.ts</code>.</li>
39
+ <li><cad-icon name="palette" [size]="15" /> Le nom vient de <code>package.json</code>, le logo de <code>public/logo.svg</code>.</li>
40
+ </ul>
41
+ <a cadButton variant="outline" size="sm" routerLink="/app/account"><cad-icon name="user" [size]="15" /> Mon compte</a>
42
+ </cad-card>
43
+ </div>
44
+ </section>
45
+ `,
46
+ styles: `
47
+ .hello {
48
+ margin: 0;
49
+ font-size: 20px;
50
+ letter-spacing: -0.02em;
51
+ }
52
+ .cards {
53
+ display: grid;
54
+ gap: 16px;
55
+ grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
56
+ }
57
+ .next {
58
+ margin: 0 0 14px;
59
+ padding: 0;
60
+ list-style: none;
61
+ display: flex;
62
+ flex-direction: column;
63
+ gap: 10px;
64
+ font-size: 14px;
65
+ li {
66
+ line-height: 1.5;
67
+ }
68
+ cad-icon {
69
+ vertical-align: -2px;
70
+ margin-right: 6px;
71
+ color: var(--cad-fg-muted);
72
+ }
73
+ }
74
+ `,
75
+ })
76
+ export default class DashboardPage {
77
+ protected readonly auth = inject(AuthService);
78
+ protected readonly providers = computed(() => {
79
+ const list = (this.auth.user()?.app_metadata?.['providers'] as string[] | undefined) ?? [];
80
+ return list.length ? list.map(providerLabel).join(', ') : this.auth.user()?.is_anonymous ? 'Anonyme' : '—';
81
+ });
82
+ }
@@ -0,0 +1,33 @@
1
+ import { Component, inject } from '@angular/core';
2
+ import { RouterLink } from '@angular/router';
3
+ import { CadButtonComponent, CadCardComponent, CadMessageComponent } from '@cadriciel/ui';
4
+ import { AuthService } from '../../core/auth.service';
5
+
6
+ /** Page du cadre ouverte à tous : pas de garde sur sa route */
7
+ /** Options de la route (titre, accès), lues par le générateur de routes */
8
+ export const route = { title: 'Page publique' };
9
+
10
+ @Component({
11
+ selector: 'app-public',
12
+ imports: [RouterLink, CadButtonComponent, CadCardComponent, CadMessageComponent],
13
+ template: `
14
+ <section class="page">
15
+ <p class="lead">Dans le cadre de l’application, sans connexion : sa route n’a pas de garde.</p>
16
+ <cad-card>
17
+ @if (auth.session()) {
18
+ <cad-message severity="success" variant="soft">Connecté en tant que {{ auth.displayName() }}.</cad-message>
19
+ } @else {
20
+ <div class="form">
21
+ <cad-message severity="info" variant="soft">Vous n’êtes pas connecté.</cad-message>
22
+ <div class="row">
23
+ <a cadButton routerLink="/login" [queryParams]="{ next: '/app' }">Se connecter</a>
24
+ </div>
25
+ </div>
26
+ }
27
+ </cad-card>
28
+ </section>
29
+ `,
30
+ })
31
+ export default class PublicPage {
32
+ protected readonly auth = inject(AuthService);
33
+ }