Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Each package documents itself in its README, which is also its page on npm.
| Package | Does |
|---|---|
| [@service-soft/ui](./projects/ui/README.md) | The design system every other library builds on: the design tokens, theming, dark mode and the basic components, like buttons, inputs, dialogs and menus |
| [@service-soft/ngx-auth](./projects/ngx-auth/README.md) | Logs in at the auth routes of zibri with tokens or cookies, a second factor and password resets, protects routes by login and permission in a tenant, and has the pages for the login and passwords |
| [@service-soft/ngx-auth](./projects/ngx-auth/README.md) | Logs in at the auth routes of zibri with tokens or cookies, a second factor and password resets, protects routes by login and permission in a tenant, answers invitations, and has the pages for the login, passwords and invitations |
| [@service-soft/ngx-change-sets](./projects/ngx-change-sets/README.md) | Shows the change sets of an entity as its history, like the ones zibri keeps, and lets the user undo them |
| [@service-soft/ngx-ecommerce](./projects/ngx-ecommerce/README.md) | Lets the user add extras to a booking or order, like breakfast per day or a second bike, and sums up an order with its discounts, taxes and total, in the currency and language of the app |
| [@service-soft/ngx-entity](./projects/ngx-entity/README.md) | Describes the entities of an app with decorators like zibri's and builds their forms from them, on a grid of 12 columns with rows and tabs, reads and writes them at the routes of zibri, and shows them in tables a page at a time, with the filters and orders the server allows, which create, edit and delete them in dialogs or on pages of their own, asking before changes are lost, and offline with ngx-pwa if you like |
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
"typescript": "~6.0.2",
"uqr": "^0.1.3",
"vitest": "^5.0.0",
"zibri-contract": "^3.1.0"
"zibri-contract": "^3.2.0"
}
}
20 changes: 19 additions & 1 deletion projects/ngx-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ Everything works with server-side rendering: on the server nobody is logged in,
- [Providers](#providers)
- [Sessions and email](#sessions-and-email)
- [Passwords](#passwords)
- [Invitations](#invitations)
- [The pages](#the-pages)
- [Moving from ngx-material-auth](#moving-from-ngx-material-auth)
- [License](#license)

# Requirements
Angular 22 with the router, and a backend with the `AuthController` of zibri 3.1 or later. What the routes answer and take, like `CurrentUserProfile`, `UserLogin` and `OtpRegistration`, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in.
Angular 22 with the router, and a backend with the `AuthController` of zibri 3.1 or later, 3.2 with `invitationRoutes: true` for [invitations](#invitations). What the routes answer and take, like `CurrentUserProfile`, `UserLogin` and `OtpRegistration`, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in.

```sh
npm install @service-soft/ngx-auth zibri-contract
Expand Down Expand Up @@ -239,6 +240,17 @@ The links of these emails open `ConfirmEmailComponent` of `@service-soft/ngx-aut
# Passwords
`requestPasswordReset(email)` mails a link, `verifyPasswordResetToken(token)` says whether its token still works, and `confirmPasswordReset(token, newPassword)` sets the new password. `changePassword(currentPassword, newPassword)` changes the password of the logged in user.

# Invitations
With `invitationRoutes: true` of the `AuthController` of zibri 3.2, zibri mails invitations to an app or to a tenant, whose link is answered here:

| Method | Does |
|---|---|
| `verifyInvitationToken(token)` | Answers an `InvitationTokenValidity`: whether the link works, whether a new one was mailed for one that ran out, and for a link that works the invited email, its tenant, whether accepting needs a login (`requiresLogin`) and whether it may be declined (`declinable`) |
| `acceptInvitation(token, password?)` | Accepts with the password of the account the invitation creates, or, without one, as the logged in account of the invited email |
| `declineInvitation(token)` | Declines it, which needs no login |

zibri finds an invitation by its token in every tenant, so the requests name none, and a link zibri refuses ends no login. The [`AcceptInvitationComponent`](#the-pages) does all of it.

# The pages
Ready pages for these, built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui), each in its own entry point, so an app only loads the ones it uses:

Expand All @@ -252,6 +264,11 @@ const routes: Routes = [
{
path: 'reset-password/:token',
loadComponent: () => import('@service-soft/ngx-auth/confirm-password-reset').then(m => m.ConfirmPasswordResetComponent)
},
// no guard: accepting works logged out and logged in
{
path: 'accept-invitation/:token',
loadComponent: () => import('@service-soft/ngx-auth/accept-invitation').then(m => m.AcceptInvitationComponent)
}
];
```
Expand All @@ -262,6 +279,7 @@ const routes: Routes = [
| `RequestPasswordResetComponent` | Has zibri mail a link to reset the password |
| `ConfirmPasswordResetComponent` | The page of that link: zibri adds the token to its `CONFIRM_PASSWORD_RESET_URL` as the last segment, so set that to the url of this route, like `https://app.example.com/reset-password`. Checks the link in the browser, and offers a new one when it doesn't work anymore |
| `ChangePasswordComponent` | The current and a new password, for the page of the user's account, with a `h2` heading |
| `AcceptInvitationComponent` | The page of the link of an [invitation](#invitations): zibri adds the token to the `acceptInvitationUrl` of its `INVITATION_OPTIONS` as the last segment, so set that to the url of this route, like `https://app.example.com/accept-invitation`. Checks the link in the browser, and says when it doesn't work, and when a new one was mailed. An invitation that creates its account asks for its password, then links to the login. One to an email with an account links to the login while nobody is logged in, and back here once they are; offers logging out to another account; and accepts with one button as that account, which then acts in the tenant of the invitation. A decline button shows next to accepting when the invitation may be declined |

A refused attempt shows the message of zibri, in the language of the request, and keeps what the user typed. Each page has a `provideXConfig`, like `provideLoginConfig`, for its texts and options. Values you leave out keep their defaults, so a translation can change single labels:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ButtonVariant } from '@service-soft/ui/button';

/**
* A link or a button of the page of an invitation, ready to render.
*/
export type AcceptInvitationActionView = {
/**
* The text of the link or the button.
*/
label: string,
/**
* How it looks.
*/
variant: ButtonVariant
} & ({
/**
* Says that it is a link.
*/
kind: 'link',
/**
* Where it goes.
*/
route: string,
/**
* The query of the route, like the returnUrl of the login.
*/
queryParams?: Record<string, string>
} | {
/**
* Says that it is a button.
*/
kind: 'button',
/**
* What it does.
*/
run: () => Promise<void>
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AcceptInvitationConfig, AcceptInvitationLabels } from './accept-invitation-config.model';

/**
* The values to change in the config of the page the link of an invitation opens. Everything is optional, including
* every single label.
*/
export type AcceptInvitationConfigChanges = Partial<Omit<AcceptInvitationConfig, 'labels'>> & {
/**
* The labels to change.
*/
labels?: Partial<AcceptInvitationLabels>
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* The texts of the page the link of an invitation opens.
*/
export type AcceptInvitationLabels = {
/**
* The heading of the page.
*/
title: string,
/**
* Shown before the invited email.
*/
invitedAs: string,
/**
* Shown when the link doesn't work, like when it was used, revoked or ran out.
*/
invalid: string,
/**
* Shown when the link ran out and zibri mailed a new one to the invited email.
*/
renewed: string,
/**
* The label of the input of the password of the account the invitation creates.
*/
password: string,
/**
* The button that accepts the invitation.
*/
accept: string,
/**
* The button that declines the invitation.
*/
decline: string,
/**
* Shown when accepting needs a login as the invited account, while nobody is logged in.
*/
loginRequired: string,
/**
* Shown while somebody else than the invited email is logged in.
*/
otherAccount: string,
/**
* The link to the login.
*/
login: string,
/**
* The button that logs out of another account.
*/
logout: string,
/**
* Shown once the invitation was accepted by a logged in account.
*/
accepted: string,
/**
* Shown once the invitation was accepted with the password of the account it created.
*/
acceptedWithPassword: string,
/**
* The link on into the app once the invitation was accepted by a logged in account.
*/
continue: string,
/**
* Shown once the invitation was declined.
*/
declined: string,
/**
* Shown when a request failed without a message of zibri, like without a connection.
*/
failed: string
};

/**
* How the page the link of an invitation opens looks and works.
*/
export type AcceptInvitationConfig = {
/**
* The texts of the page.
*/
labels: AcceptInvitationLabels,
/**
* The least number of characters of the password of the account an invitation creates, the minLength of the
* password policy of zibri. Without it, zibri says what is too short.
*/
newPasswordMinLength: number | undefined
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { inject, InjectionToken, Provider } from '@angular/core';

import { AcceptInvitationConfigChanges } from './accept-invitation-config-changes.model';
import { AcceptInvitationConfig } from './accept-invitation-config.model';

const DEFAULT_ACCEPT_INVITATION_CONFIG: AcceptInvitationConfig = {
labels: {
title: 'Invitation',
invitedAs: 'You are invited as',
invalid: 'This link doesn\'t work. It ran out, or was used or revoked already.',
renewed: 'This link ran out. A new one was mailed to the invited address.',
password: 'Password',
accept: 'Accept invitation',
decline: 'Decline',
loginRequired: 'Log in as the invited account to accept the invitation.',
otherAccount: 'You are logged in with another account. Log out, and log in as the invited one to accept the invitation.',
login: 'Log in',
logout: 'Log out',
accepted: 'The invitation was accepted.',
acceptedWithPassword: 'Your account is ready. Log in with your password.',
continue: 'Continue',
declined: 'The invitation was declined.',
failed: 'Something went wrong. Please try again.'
},
newPasswordMinLength: undefined
};

/**
* How the page the link of an invitation opens looks and works. Change it with provideAcceptInvitationConfig.
*/
export const ACCEPT_INVITATION_CONFIG: InjectionToken<AcceptInvitationConfig> = new InjectionToken<AcceptInvitationConfig>(
'ACCEPT_INVITATION_CONFIG',
{ providedIn: 'root', factory: () => DEFAULT_ACCEPT_INVITATION_CONFIG }
);

/**
* Changes how the page the link of an invitation opens looks and works, like its texts to translate them. Values you
* leave out keep the ones of the parent injector, including single labels.
* @param config - The values to change.
* @returns The provider for ACCEPT_INVITATION_CONFIG.
*/
export function provideAcceptInvitationConfig(config: AcceptInvitationConfigChanges): Provider {
return {
provide: ACCEPT_INVITATION_CONFIG,
useFactory: (): AcceptInvitationConfig => {
const parent: AcceptInvitationConfig = inject(ACCEPT_INVITATION_CONFIG, { skipSelf: true, optional: true })
?? DEFAULT_ACCEPT_INVITATION_CONFIG;
return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } };
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<ui-form class="grid gap-4" (submit)="accepted.emit(password())">
<ui-input-string
name="password"
type="password"
autocomplete="new-password"
[label]="labels().password"
[minLength]="minLength()"
[(value)]="password"
/>
<div class="flex flex-wrap gap-2">
<button ui-button type="submit">{{ labels().accept }}</button>
@if (declinable()) {
<button ui-button type="button" variant="outlined" (click)="declined.emit()">{{ labels().decline }}</button>
}
</div>
</ui-form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Component, input, InputSignal, output, OutputEmitterRef, signal, WritableSignal } from '@angular/core';
import { ButtonComponent } from '@service-soft/ui/button';
import { FormComponent } from '@service-soft/ui/form';
import { InputStringComponent } from '@service-soft/ui/input-string';

import { AcceptInvitationLabels } from './accept-invitation-config.model';

/**
* The form of the page of an invitation that creates its account, which asks for its password.
*/
@Component({
selector: 'ngx-accept-invitation-password',
templateUrl: './accept-invitation-password.component.html',
imports: [FormComponent, InputStringComponent, ButtonComponent],
host: {
class: 'block'
}
})
export class AcceptInvitationPasswordComponent {
/**
* The texts of the page.
*/
readonly labels: InputSignal<AcceptInvitationLabels> = input.required<AcceptInvitationLabels>();

/**
* The least number of characters of the password, or undefined to leave it to zibri.
*/
readonly minLength: InputSignal<number | undefined> = input.required<number | undefined>();

/**
* Whether the invitation may be declined, which a button next to accepting does.
*/
readonly declinable: InputSignal<boolean> = input.required<boolean>();

/**
* Emits the password once the user accepts with it.
*/
readonly accepted: OutputEmitterRef<string> = output<string>();

/**
* Emits once the user declines.
*/
readonly declined: OutputEmitterRef<void> = output<void>();

/**
* The password the user typed.
*/
protected readonly password: WritableSignal<string> = signal('');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Where the page of an invitation stands: checking the link, refusing a link that doesn't work, asking for the
* password of the account it creates, asking to log in or to log out of another account, offering to accept, or
* done.
*/
export type AcceptInvitationState
= 'verifying' | 'invalid' | 'password' | 'loginRequired' | 'otherAccount' | 'accept' | 'accepted' | 'declined';
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- takes the focus once a request is answered without a link to go on with -->
<h1 #heading class="font-heading text-headline text-on-surface" tabindex="-1">{{ labels.title }}</h1>
@for (paragraph of paragraphs(); track $index) {
<p class="mt-4 text-body text-on-surface">{{ paragraph }}</p>
}
@if (state() === 'password') {
<ngx-accept-invitation-password
class="mt-6"
[labels]="labels"
[minLength]="config.newPasswordMinLength"
[declinable]="declinable()"
(accepted)="accept($event)"
(declined)="decline()"
/>
}
<div class="mt-6 flex flex-wrap gap-2 empty:hidden">
@for (action of actions(); track action.label) {
@if (action.kind === 'link') {
<a #actionLink ui-button [variant]="action.variant" [routerLink]="action.route" [queryParams]="action.queryParams">{{ action.label }}</a>
}
@else {
<button ui-button type="button" [variant]="action.variant" (click)="action.run()">{{ action.label }}</button>
}
}
</div>
<!-- always rendered, screen readers only announce changes of live regions that already exist. empty:hidden: it takes
no space while nothing was refused -->
<div class="mt-4 text-body text-error empty:hidden" role="alert">
@for (paragraph of errorParagraphs(); track $index) {
<p>{{ paragraph }}</p>
}
</div>
<p class="mt-4 text-body text-on-surface" role="status">{{ status() }}</p>
Loading
Loading