@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,159 @@
1
+ import { Injectable, computed, effect, signal } from '@angular/core';
2
+ const LOCK_KEY = 'app.rail-locked';
3
+ const WIDTH_KEY = 'app.rail-width';
4
+
5
+ /** En deçà, le rail ne tient plus dans le flux : le tiroir est imposé. */
6
+ export const NARROW_AT = 992;
7
+
8
+ export const RAIL_MIN = 190;
9
+ export const RAIL_MAX = 380;
10
+ export const RAIL_DEFAULT = 238;
11
+
12
+ /** Sous ce seuil, relâcher la poignée range le rail au lieu de le rétrécir. */
13
+ export const RAIL_COLLAPSE_AT = 160;
14
+
15
+ /**
16
+ * État du rail.
17
+ *
18
+ * Le verrou est une PRÉFÉRENCE de l'utilisateur, pas un état d'affichage : le
19
+ * rail n'occupe la mise en page que si la préférence ET la largeur le
20
+ * permettent. En fenêtre étroite le tiroir s'impose, sans choix offert — et la
21
+ * préférence reprend d'elle-même à l'élargissement.
22
+ *
23
+ * Le thème appartient à `ThemeService` et l'élément de menu
24
+ * actif à `routerLinkActive` : ni l'un ni l'autre ne transite par ici.
25
+ */
26
+ @Injectable({
27
+ providedIn: 'root',
28
+ })
29
+ export class LayoutService {
30
+ /** Préférence : le rail reste-t-il en place ? */
31
+ readonly locked = signal<boolean>(readBool(LOCK_KEY, true));
32
+
33
+ /** Largeur du rail quand il est dans le flux. */
34
+ readonly railWidth = signal<number>(readWidth());
35
+
36
+ /** Tiroir déployé (n'a de sens que hors du flux). */
37
+ readonly drawerOpen = signal(false);
38
+
39
+ /** Vrai pendant un glissement de la poignée. */
40
+ readonly resizing = signal(false);
41
+
42
+ readonly viewportWidth = signal<number>(typeof window === 'undefined' ? 1280 : window.innerWidth);
43
+ readonly narrow = computed(() => this.viewportWidth() < NARROW_AT);
44
+
45
+ /** Le rail occupe-t-il réellement la mise en page ? */
46
+ readonly railInFlow = computed(() => this.locked() && !this.narrow());
47
+
48
+ private closeTimer: ReturnType<typeof setTimeout> | null = null;
49
+ private openTimer: ReturnType<typeof setTimeout> | null = null;
50
+
51
+ constructor() {
52
+ if (typeof window !== 'undefined') {
53
+ window.addEventListener('resize', () => this.viewportWidth.set(window.innerWidth), { passive: true });
54
+ }
55
+
56
+ effect(() => write(LOCK_KEY, this.locked() ? '1' : '0'));
57
+ effect(() => write(WIDTH_KEY, String(this.railWidth())));
58
+
59
+ // Passer en fenêtre étroite referme le tiroir : on ne laisse pas un
60
+ // panneau ouvert par-dessus un écran devenu exigu.
61
+ effect(() => {
62
+ if (this.narrow()) this.drawerOpen.set(false);
63
+ });
64
+ }
65
+
66
+ toggleLock(): void {
67
+ if (this.narrow()) return; // aucun choix à offrir : le tiroir s'impose
68
+ const next = !this.locked();
69
+ this.locked.set(next);
70
+ this.drawerOpen.set(false);
71
+ }
72
+
73
+ /** Range le rail : il quitte la mise en page et se referme. */
74
+ stow(): void {
75
+ this.locked.set(false);
76
+ this.drawerOpen.set(false);
77
+ }
78
+
79
+ openDrawer(): void {
80
+ if (!this.railInFlow()) this.drawerOpen.set(true);
81
+ }
82
+
83
+ closeDrawer(): void {
84
+ this.drawerOpen.set(false);
85
+ }
86
+
87
+ toggleDrawer(): void {
88
+ if (this.railInFlow()) return;
89
+ this.drawerOpen.update((v) => !v);
90
+ }
91
+
92
+ /**
93
+ * ⌘B : range le rail s'il est en place, sinon bascule le tiroir.
94
+ * Une seule touche pour un seul concept — la visibilité du rail.
95
+ */
96
+ toggleFromKeyboard(): void {
97
+ if (this.railInFlow()) this.stow();
98
+ else this.toggleDrawer();
99
+ }
100
+
101
+ /** Ouverture différée au survol du bord — un passage rapide ne déclenche rien. */
102
+ peek(on: boolean): void {
103
+ if (this.railInFlow()) return;
104
+ this.clearTimers();
105
+ if (on) this.openTimer = setTimeout(() => this.drawerOpen.set(true), 120);
106
+ else this.closeTimer = setTimeout(() => this.drawerOpen.set(false), 160);
107
+ }
108
+
109
+ holdOpen(): void {
110
+ this.clearTimers();
111
+ }
112
+
113
+ private clearTimers(): void {
114
+ if (this.openTimer) clearTimeout(this.openTimer);
115
+ if (this.closeTimer) clearTimeout(this.closeTimer);
116
+ this.openTimer = this.closeTimer = null;
117
+ }
118
+
119
+ resizeTo(px: number): void {
120
+ if (px < RAIL_COLLAPSE_AT) {
121
+ this.stow();
122
+ return;
123
+ }
124
+ this.railWidth.set(Math.min(RAIL_MAX, Math.max(RAIL_MIN, Math.round(px))));
125
+ }
126
+
127
+ resetWidth(): void {
128
+ this.railWidth.set(RAIL_DEFAULT);
129
+ }
130
+ }
131
+
132
+ function readBool(key: string, fallback: boolean): boolean {
133
+ if (typeof localStorage === 'undefined') return fallback;
134
+ try {
135
+ const v = localStorage.getItem(key);
136
+ return v === null ? fallback : v === '1';
137
+ } catch {
138
+ return fallback;
139
+ }
140
+ }
141
+
142
+ function readWidth(): number {
143
+ if (typeof localStorage === 'undefined') return RAIL_DEFAULT;
144
+ try {
145
+ const n = Number(localStorage.getItem(WIDTH_KEY));
146
+ return Number.isFinite(n) && n >= RAIL_MIN && n <= RAIL_MAX ? n : RAIL_DEFAULT;
147
+ } catch {
148
+ return RAIL_DEFAULT;
149
+ }
150
+ }
151
+
152
+ function write(key: string, value: string): void {
153
+ if (typeof localStorage === 'undefined') return;
154
+ try {
155
+ localStorage.setItem(key, value);
156
+ } catch {
157
+ // stockage indisponible : la préférence vaut pour la session
158
+ }
159
+ }
@@ -0,0 +1,128 @@
1
+ <section class="auth">
2
+ <div class="head">
3
+ <a routerLink="/"><app-brand [size]="32" /></a>
4
+ <h1>Connexion</h1>
5
+ </div>
6
+
7
+ <cad-card>
8
+ <cad-tabs [value]="tab()" (valueChange)="changeTab($event)" variant="line" stretch>
9
+ <cad-tab value="password" label="Mot de passe">
10
+ <form class="form" (ngSubmit)="signIn()">
11
+ <cad-field label="Adresse e-mail" required>
12
+ <input cadInput type="email" name="email" [(ngModel)]="email" autocomplete="username" required />
13
+ </cad-field>
14
+ <cad-field plain label="Mot de passe" required>
15
+ <cad-password name="password" [(ngModel)]="password" toggleMask autocomplete="current-password" />
16
+ </cad-field>
17
+ <div class="row">
18
+ <button cadButton type="submit" [loading]="busy()" [disabled]="!email() || !password() || blocked()">
19
+ <cad-icon name="log-in" [size]="16" /> Se connecter
20
+ </button>
21
+ <button cadButton type="button" variant="text" (click)="changeTab('recovery')">Mot de passe oublié ?</button>
22
+ </div>
23
+ </form>
24
+ </cad-tab>
25
+
26
+ <cad-tab value="signup" label="Inscription">
27
+ @if (sent()?.type === 'signup') {
28
+ <ng-container *ngTemplateOutlet="codeForm; context: { label: 'Code de confirmation', canResend: true }" />
29
+ } @else {
30
+ <form class="form" (ngSubmit)="signUp()">
31
+ <cad-field label="Nom" optionalText="facultatif">
32
+ <input cadInput name="name" [(ngModel)]="name" autocomplete="name" />
33
+ </cad-field>
34
+ <cad-field label="Adresse e-mail" required>
35
+ <input cadInput type="email" name="email" [(ngModel)]="email" autocomplete="email" required />
36
+ </cad-field>
37
+ <cad-field plain label="Mot de passe" required hint="8 caractères au moins">
38
+ <cad-password name="password" [(ngModel)]="password" toggleMask feedback autocomplete="new-password" />
39
+ </cad-field>
40
+ <button cadButton type="submit" [loading]="busy()" [disabled]="!email() || !password() || blocked()">
41
+ <cad-icon name="user-plus" [size]="16" /> Créer le compte
42
+ </button>
43
+ </form>
44
+ }
45
+ </cad-tab>
46
+
47
+ <cad-tab value="otp" label="Lien magique">
48
+ @if (sent()?.type === 'email') {
49
+ <ng-container *ngTemplateOutlet="codeForm; context: { label: 'Code reçu par e-mail' }" />
50
+ } @else {
51
+ <form class="form" (ngSubmit)="sendLink()">
52
+ <p class="muted">Un e-mail avec un lien et un code à 6 chiffres. Le compte est créé s’il n’existe pas.</p>
53
+ <cad-field label="Adresse e-mail" required>
54
+ <input cadInput type="email" name="email" [(ngModel)]="email" autocomplete="email" required />
55
+ </cad-field>
56
+ <button cadButton type="submit" [loading]="busy()" [disabled]="!email() || blocked()">
57
+ <cad-icon name="mail" [size]="16" /> Envoyer
58
+ </button>
59
+ </form>
60
+ }
61
+ </cad-tab>
62
+
63
+ <cad-tab value="recovery" label="Oubli">
64
+ @if (sent()?.type === 'recovery') {
65
+ <ng-container *ngTemplateOutlet="codeForm; context: { label: 'Code de réinitialisation' }" />
66
+ } @else {
67
+ <form class="form" (ngSubmit)="sendRecovery()">
68
+ <p class="muted">Le lien de l’e-mail ramène ici pour choisir un nouveau mot de passe.</p>
69
+ <cad-field label="Adresse e-mail" required>
70
+ <input cadInput type="email" name="email" [(ngModel)]="email" autocomplete="email" required />
71
+ </cad-field>
72
+ <button cadButton type="submit" [loading]="busy()" [disabled]="!email() || blocked()">
73
+ <cad-icon name="key-round" [size]="16" /> Envoyer le lien
74
+ </button>
75
+ </form>
76
+ }
77
+ </cad-tab>
78
+ </cad-tabs>
79
+ @if (captcha(); as c) {
80
+ <app-captcha [provider]="c.provider" [siteKey]="c.siteKey" (token)="captchaToken.set($event)" />
81
+ }
82
+ </cad-card>
83
+
84
+ @if (auth.settings()) {
85
+ <cad-divider />
86
+ <div class="providers">
87
+ <span class="muted">Ou continuer avec</span>
88
+ @for (p of auth.oauthProviders(); track p) {
89
+ <button cadButton variant="outline" block [loading]="pending() === p" (click)="oauth(p)">
90
+ @if (logo(p); as src) {
91
+ <img class="logo" [src]="src" alt="" />
92
+ } @else {
93
+ <cad-icon name="log-in" [size]="16" />
94
+ }
95
+ Continuer avec {{ label(p) }}
96
+ </button>
97
+ } @empty {
98
+ <span class="muted">Aucun fournisseur OAuth sur ce projet (Keycloak local : <code>poad run kc</code>).</span>
99
+ }
100
+ @if (auth.settings()?.external?.['anonymous_users']) {
101
+ <button cadButton variant="text" severity="secondary" block (click)="anonymous()" [loading]="busy() && pending() === 'anonymous'" [disabled]="blocked()">
102
+ <cad-icon name="ghost" [size]="16" /> Continuer sans compte
103
+ </button>
104
+ }
105
+ </div>
106
+ }
107
+ </section>
108
+
109
+ <ng-template #codeForm let-label="label" let-canResend="canResend">
110
+ <form class="form" (ngSubmit)="verify()">
111
+ <cad-message severity="info" variant="soft" size="sm">
112
+ E-mail envoyé à <strong>{{ sent()?.email }}</strong>. Cliquez sur le lien, ou saisissez le code.
113
+ @if (auth.config()?.mail; as mail) {
114
+ <a [href]="mail" target="_blank" rel="noopener">Ouvrir la boîte de test</a>
115
+ }
116
+ </cad-message>
117
+ <cad-field [label]="label" required>
118
+ <input cadInput mono name="code" [(ngModel)]="code" inputmode="numeric" autocomplete="one-time-code" maxlength="6" required />
119
+ </cad-field>
120
+ <div class="row">
121
+ <button cadButton type="submit" [loading]="busy()" [disabled]="code().length !== 6">Valider</button>
122
+ @if (canResend) {
123
+ <button cadButton type="button" variant="text" (click)="resend()">Renvoyer</button>
124
+ }
125
+ <button cadButton type="button" variant="text" (click)="sent.set(null)">Changer d’adresse</button>
126
+ </div>
127
+ </form>
128
+ </ng-template>
@@ -0,0 +1,194 @@
1
+ import { Component, computed, inject, signal, viewChild } from '@angular/core';
2
+ import { NgTemplateOutlet } from '@angular/common';
3
+ import { FormsModule } from '@angular/forms';
4
+ import {
5
+ CadButtonComponent,
6
+ CadCardComponent,
7
+ CadDividerComponent,
8
+ CadFieldComponent,
9
+ CadIconComponent,
10
+ CadInputDirective,
11
+ CadMessageComponent,
12
+ CadPasswordComponent,
13
+ CadTabComponent,
14
+ CadTabsComponent,
15
+ } from '@cadriciel/ui';
16
+ import { AuthService } from '../../core/auth.service';
17
+ import { Poad } from '../../core/poad';
18
+ import { CaptchaComponent } from '../../core/captcha';
19
+ import { providerLabel, providerLogo } from '../../core/providers';
20
+ import { BrandComponent } from '../../layout/brand';
21
+ import { RouterLink } from '@angular/router';
22
+
23
+ /** Options de la route (titre, accès), lues par le générateur de routes */
24
+ export const route = { title: 'Connexion', guest: true };
25
+
26
+ @Component({
27
+ selector: 'app-login',
28
+ imports: [
29
+ FormsModule,
30
+ NgTemplateOutlet,
31
+ CadButtonComponent,
32
+ CadCardComponent,
33
+ CadDividerComponent,
34
+ CadFieldComponent,
35
+ CadIconComponent,
36
+ CadInputDirective,
37
+ CadMessageComponent,
38
+ CadPasswordComponent,
39
+ CadTabComponent,
40
+ CadTabsComponent,
41
+ CaptchaComponent,
42
+ BrandComponent,
43
+ RouterLink,
44
+ ],
45
+ templateUrl: './login.html',
46
+ styles: `
47
+ :host {
48
+ display: grid;
49
+ place-items: center;
50
+ min-height: 100vh;
51
+ padding: 32px 16px;
52
+ background: var(--cad-bg);
53
+ }
54
+ .auth {
55
+ width: 100%;
56
+ max-width: 420px;
57
+ display: flex;
58
+ flex-direction: column;
59
+ gap: 16px;
60
+ }
61
+ .head {
62
+ display: flex;
63
+ flex-direction: column;
64
+ gap: 18px;
65
+ margin-bottom: 4px;
66
+ }
67
+ .head a {
68
+ color: inherit;
69
+ text-decoration: none;
70
+ }
71
+ h1 {
72
+ margin: 0;
73
+ font-size: 22px;
74
+ letter-spacing: -0.02em;
75
+ }
76
+ .providers {
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: 8px;
80
+ }
81
+ .logo {
82
+ width: 18px;
83
+ height: 18px;
84
+ }
85
+ `,
86
+ })
87
+ export default class LoginPage {
88
+ protected readonly auth = inject(AuthService);
89
+ protected readonly poad = inject(Poad);
90
+ protected readonly tab = signal<string>('password');
91
+ protected readonly busy = signal(false);
92
+ /** Fournisseur (ou « anonymous ») en cours, pour l'indicateur du bon bouton */
93
+ protected readonly pending = signal<string | null>(null);
94
+ protected readonly label = providerLabel;
95
+ protected readonly logo = providerLogo;
96
+ protected readonly email = signal('');
97
+ protected readonly password = signal('');
98
+ protected readonly name = signal('');
99
+ protected readonly code = signal('');
100
+ /** Adresse à laquelle un code vient d'être envoyé, et pour quoi */
101
+ protected readonly sent = signal<{ email: string; type: 'signup' | 'email' | 'recovery' } | null>(null);
102
+
103
+ /** CAPTCHA exigé par le service (/settings) */
104
+ protected readonly captcha = computed(() => {
105
+ const c = this.auth.settings()?.captcha;
106
+ return c && c.site_key ? { provider: c.provider, siteKey: c.site_key } : null;
107
+ });
108
+ protected readonly captchaToken = signal<string | null>(null);
109
+ /** Envoi impossible tant que le CAPTCHA exigé n'est pas résolu */
110
+ protected readonly blocked = computed(() => Boolean(this.captcha()) && !this.captchaToken());
111
+ private readonly widget = viewChild(CaptchaComponent);
112
+
113
+ protected async signIn(): Promise<void> {
114
+ await this.call(() => this.poad.auth.signInWithPassword({ email: this.email(), password: this.password(), captchaToken: this.token() }));
115
+ }
116
+
117
+ protected async signUp(): Promise<void> {
118
+ const data = await this.call(() =>
119
+ this.poad.auth.signUp({
120
+ email: this.email(),
121
+ password: this.password(),
122
+ data: this.name() ? { name: this.name() } : {},
123
+ redirectTo: this.auth.redirect('/app'),
124
+ captchaToken: this.token(),
125
+ })
126
+ );
127
+ if (data && !data.session) this.sent.set({ email: this.email(), type: 'signup' });
128
+ }
129
+
130
+ protected async sendLink(): Promise<void> {
131
+ const data = await this.call(
132
+ () => this.poad.auth.signInWithOtp({ email: this.email(), redirectTo: this.auth.redirect('/app'), captchaToken: this.token() }),
133
+ 'E-mail envoyé'
134
+ );
135
+ if (data) this.sent.set({ email: this.email(), type: 'email' });
136
+ }
137
+
138
+ protected async sendRecovery(): Promise<void> {
139
+ const data = await this.call(
140
+ () => this.poad.auth.resetPasswordForEmail(this.email(), { redirectTo: this.auth.redirect('/reset'), captchaToken: this.token() }),
141
+ 'E-mail envoyé s’il existe un compte'
142
+ );
143
+ if (data) this.sent.set({ email: this.email(), type: 'recovery' });
144
+ }
145
+
146
+ protected async verify(): Promise<void> {
147
+ const sent = this.sent();
148
+ if (!sent) return;
149
+ const ok = await this.call(() => this.poad.auth.verifyOtp({ email: sent.email, token: this.code(), type: sent.type }));
150
+ if (ok) {
151
+ this.sent.set(null);
152
+ this.code.set('');
153
+ }
154
+ }
155
+
156
+ protected async resend(): Promise<void> {
157
+ const sent = this.sent();
158
+ if (sent?.type !== 'signup') return;
159
+ await this.call(() => this.poad.auth.resend({ type: 'signup', email: sent.email, redirectTo: this.auth.redirect('/app'), captchaToken: this.token() }), 'E-mail renvoyé');
160
+ }
161
+
162
+ protected async oauth(provider: string): Promise<void> {
163
+ // La page part chez le fournisseur : l'indicateur reste jusqu'au départ
164
+ this.pending.set(provider);
165
+ await this.call(() => this.poad.auth.signInWithOAuth({ provider, redirectTo: this.auth.redirect('/app') }));
166
+ }
167
+
168
+ protected async anonymous(): Promise<void> {
169
+ this.pending.set('anonymous');
170
+ await this.call(() => this.poad.auth.signInAnonymously({ captchaToken: this.token() }));
171
+ this.pending.set(null);
172
+ }
173
+
174
+ protected changeTab(tab: unknown): void {
175
+ this.tab.set(String(tab));
176
+ this.sent.set(null);
177
+ this.code.set('');
178
+ }
179
+
180
+ private async call<T>(fn: () => Promise<import('@poadio/client-js').Result<T>>, success?: string): Promise<T | null> {
181
+ this.busy.set(true);
182
+ try {
183
+ return await this.auth.run(fn, success);
184
+ } finally {
185
+ this.busy.set(false);
186
+ // Un jeton CAPTCHA ne sert qu'une fois
187
+ this.widget()?.reset();
188
+ }
189
+ }
190
+
191
+ private token(): string | undefined {
192
+ return this.captchaToken() ?? undefined;
193
+ }
194
+ }
@@ -0,0 +1,61 @@
1
+ import { Component, computed, inject, signal } from '@angular/core';
2
+ import { FormsModule } from '@angular/forms';
3
+ import { CadButtonComponent, CadCardComponent, CadFieldComponent, CadInputDirective, CadSelectComponent } from '@cadriciel/ui';
4
+ import { AuthService } from '../../core/auth.service';
5
+ import { Poad } from '../../core/poad';
6
+
7
+ /** Second facteur demandé après la connexion (aal1 → aal2) */
8
+ /** Options de la route (titre, accès), lues par le générateur de routes */
9
+ export const route = { title: 'Vérification en deux étapes', auth: { mfa: false } };
10
+
11
+ @Component({
12
+ selector: 'app-mfa-challenge',
13
+ imports: [FormsModule, CadButtonComponent, CadCardComponent, CadFieldComponent, CadInputDirective, CadSelectComponent],
14
+ template: `
15
+ <section class="page page-narrow">
16
+ <h1>Vérification en deux étapes</h1>
17
+ <p class="lead">Saisissez le code à 6 chiffres de votre application d’authentification.</p>
18
+ <cad-card>
19
+ <form class="form" (ngSubmit)="verify()">
20
+ @if (factors().length > 1) {
21
+ <cad-field label="Facteur">
22
+ <cad-select name="factor" [(ngModel)]="factorId" [options]="factors()" optionLabel="label" optionValue="id" />
23
+ </cad-field>
24
+ }
25
+ <cad-field label="Code" required>
26
+ <input cadInput mono name="code" [(ngModel)]="code" inputmode="numeric" autocomplete="one-time-code" maxlength="6" required />
27
+ </cad-field>
28
+ <div class="row">
29
+ <button cadButton type="submit" [loading]="busy()" [disabled]="code().length !== 6">Vérifier</button>
30
+ <button cadButton type="button" variant="text" (click)="signOut()">Se déconnecter</button>
31
+ </div>
32
+ </form>
33
+ </cad-card>
34
+ </section>
35
+ `,
36
+ })
37
+ export default class MfaChallengePage {
38
+ protected readonly auth = inject(AuthService);
39
+ protected readonly poad = inject(Poad);
40
+ protected readonly factors = computed(() =>
41
+ (this.auth.user()?.factors ?? [])
42
+ .filter((f) => f.status === 'verified')
43
+ .map((f) => ({ id: f.id, label: f.friendly_name || `TOTP ${f.id.slice(0, 8)}` }))
44
+ );
45
+ protected readonly factorId = signal(this.factors()[0]?.id ?? '');
46
+ protected readonly code = signal('');
47
+ protected readonly busy = signal(false);
48
+
49
+ protected async verify(): Promise<void> {
50
+ const factorId = this.factorId() || this.factors()[0]?.id;
51
+ if (!factorId) return;
52
+ this.busy.set(true);
53
+ await this.auth.run(() => this.poad.auth.mfa.challengeAndVerify({ factorId, code: this.code() }));
54
+ this.busy.set(false);
55
+ this.code.set('');
56
+ }
57
+
58
+ protected signOut(): void {
59
+ void this.auth.run(() => this.poad.auth.signOut());
60
+ }
61
+ }
@@ -0,0 +1,53 @@
1
+ import { Component, inject, signal } from '@angular/core';
2
+ import { FormsModule } from '@angular/forms';
3
+ import { Router } from '@angular/router';
4
+ import { CadButtonComponent, CadCardComponent, CadFieldComponent, CadPasswordComponent } from '@cadriciel/ui';
5
+ import { AuthService } from '../../core/auth.service';
6
+ import { Poad } from '../../core/poad';
7
+
8
+ /** Options de la route (titre, accès), lues par le générateur de routes */
9
+ export const route = { title: 'Nouveau mot de passe', auth: { mfa: false } };
10
+
11
+ @Component({
12
+ selector: 'app-reset',
13
+ imports: [FormsModule, CadButtonComponent, CadCardComponent, CadFieldComponent, CadPasswordComponent],
14
+ template: `
15
+ <section class="page page-narrow">
16
+ <h1>Nouveau mot de passe</h1>
17
+ <p class="lead">Session ouverte par le lien de réinitialisation ({{ auth.user()?.email }}).</p>
18
+ <cad-card>
19
+ <form class="form" (ngSubmit)="save()">
20
+ <cad-field plain label="Nouveau mot de passe" required>
21
+ <cad-password name="password" [(ngModel)]="password" toggleMask feedback autocomplete="new-password" />
22
+ </cad-field>
23
+ <cad-field plain label="Confirmation" required [error]="confirm() && confirm() !== password() ? 'Les deux saisies diffèrent' : ''">
24
+ <cad-password name="confirm" [(ngModel)]="confirm" autocomplete="new-password" />
25
+ </cad-field>
26
+ <div class="row">
27
+ <button cadButton type="submit" [loading]="busy()" [disabled]="!password() || password() !== confirm()">Enregistrer</button>
28
+ <button cadButton type="button" variant="text" (click)="skip()">Plus tard</button>
29
+ </div>
30
+ </form>
31
+ </cad-card>
32
+ </section>
33
+ `,
34
+ })
35
+ export default class ResetPage {
36
+ protected readonly auth = inject(AuthService);
37
+ protected readonly poad = inject(Poad);
38
+ private readonly router = inject(Router);
39
+ protected readonly password = signal('');
40
+ protected readonly confirm = signal('');
41
+ protected readonly busy = signal(false);
42
+
43
+ protected async save(): Promise<void> {
44
+ this.busy.set(true);
45
+ const user = await this.auth.run(() => this.poad.auth.updateUser({ password: this.password() }), 'Mot de passe changé');
46
+ this.busy.set(false);
47
+ if (user) void this.router.navigateByUrl(this.auth.needsMfa() ? '/mfa' : '/app');
48
+ }
49
+
50
+ protected skip(): void {
51
+ void this.router.navigateByUrl(this.auth.needsMfa() ? '/mfa' : '/app');
52
+ }
53
+ }
@@ -0,0 +1,5 @@
1
+ // Cadre des pages de app/ : rail, barre du haut, canevas.
2
+ // En mode « files », toutes les pages de ce dossier s'y affichent.
3
+ export { AppLayout as default } from '../../layout/app-layout';
4
+
5
+ export const route = { configured: true };