@frigear-nu/users 1.1.2 → 1.1.4
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.
- package/dist/module.d.mts +26 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +35 -29
- package/dist/runtime/app/components/UserCreateSlideover.vue +2 -1
- package/dist/runtime/app/composables/useUserActions.d.ts +1 -1
- package/dist/runtime/app/composables/useUserActions.js +6 -3
- package/dist/runtime/app/pages/admin-user.vue +14 -5
- package/dist/runtime/app/pages/admin.vue +85 -75
- package/dist/runtime/app/pages/revert-email-change.d.vue.ts +3 -0
- package/dist/runtime/app/pages/revert-email-change.vue +104 -0
- package/dist/runtime/app/pages/revert-email-change.vue.d.ts +3 -0
- package/dist/runtime/app/pages/verify-email-change.d.vue.ts +3 -0
- package/dist/runtime/app/pages/verify-email-change.vue +156 -0
- package/dist/runtime/app/pages/verify-email-change.vue.d.ts +3 -0
- package/dist/runtime/app/tabs/Overview.vue +51 -53
- package/dist/runtime/app/utils/admin-user.d.ts +4 -17
- package/dist/runtime/app/widgets/NewUsers.vue +2 -1
- package/dist/runtime/app/widgets/NewUsersStat.vue +2 -1
- package/dist/runtime/i18n/lang/da.json +46 -3
- package/dist/runtime/i18n/lang/en.json +46 -3
- package/dist/runtime/server/email-change.d.ts +6 -0
- package/dist/runtime/server/email-change.js +10 -0
- package/dist/runtime/server/routes/admin/new.get.js +2 -8
- package/dist/runtime/server/routes/admin/user-resend.post.js +3 -13
- package/dist/runtime/server/routes/admin/user.delete.js +6 -15
- package/dist/runtime/server/routes/admin/user.get.js +6 -16
- package/dist/runtime/server/routes/admin/user.patch.js +13 -23
- package/dist/runtime/server/routes/admin/users.get.js +24 -28
- package/dist/runtime/server/routes/admin/users.post.js +12 -13
- package/dist/runtime/server/routes/me/email-change-confirm.post.js +44 -0
- package/dist/runtime/server/routes/me/email-change-revert.get.js +13 -0
- package/dist/runtime/server/routes/me/email-change-revert.post.js +28 -0
- package/dist/runtime/server/routes/me/email-change.get.js +22 -0
- package/dist/runtime/server/routes/me/{change-email.post.js → email.put.js} +9 -10
- package/dist/runtime/server/routes/me/password.put.d.ts +2 -0
- package/dist/runtime/server/routes/me/{change-password.post.js → password.put.js} +4 -5
- package/dist/runtime/server/routes/me/profile.patch.d.ts +2 -0
- package/dist/runtime/server/routes/me/profile.patch.js +22 -0
- package/dist/runtime/server/schemas.d.ts +7 -0
- package/dist/runtime/server/schemas.js +4 -0
- package/dist/runtime/server/user-store.js +5 -3
- package/dist/runtime/server/utils/admin.d.ts +15 -3
- package/dist/runtime/server/utils/admin.js +16 -15
- package/dist/runtime/server/utils/dto.d.ts +19 -0
- package/dist/runtime/server/utils/dto.js +22 -0
- package/dist/runtime/server/utils/email.d.ts +18 -0
- package/dist/runtime/server/utils/email.js +18 -0
- package/dist/runtime/utils/api.d.ts +33 -0
- package/dist/runtime/utils/api.js +32 -0
- package/dist/runtime/utils/index.d.ts +3 -1
- package/dist/runtime/utils/index.js +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +18 -13
- package/dist/runtime/server/routes/me/profile.post.js +0 -17
- package/dist/runtime/server/routes/me/revert-email-change.get.js +0 -24
- package/dist/runtime/server/routes/me/verify-email-change.get.js +0 -37
- /package/dist/runtime/server/routes/me/{change-email.post.d.ts → email-change-confirm.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/me/{change-password.post.d.ts → email-change-revert.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/me/{profile.post.d.ts → email-change-revert.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/me/{revert-email-change.get.d.ts → email-change.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/me/{verify-email-change.get.d.ts → email.put.d.ts} +0 -0
package/dist/module.d.mts
CHANGED
|
@@ -21,16 +21,38 @@ type ModuleOptions = {
|
|
|
21
21
|
page?: string | boolean;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* A new email address only takes effect once its owner confirms it
|
|
25
|
-
*
|
|
24
|
+
* A new email address only takes effect once its owner confirms it: the emailed link opens the
|
|
25
|
+
* `/auth/verify-email-change` page, where the signed-in owner presses "Confirm". The old address then gets a notice
|
|
26
|
+
* with a link to the `/auth/revert-email-change` page. The pages need `@nuxt/ui`. Defaults to `false` (applied
|
|
27
|
+
* immediately).
|
|
26
28
|
*/
|
|
27
29
|
verifyEmailChange?: boolean;
|
|
28
|
-
/** Where
|
|
30
|
+
/** Where a confirmed email change lands (`?email-changed=1`). Without it the confirm page shows the result itself. */
|
|
29
31
|
profilePath?: string;
|
|
30
32
|
/** Expose the MCP tools of this module (`get-my-profile`) on the MCP endpoint. Needs `@frigear-nu/mcp`. Defaults to `false`. */
|
|
31
33
|
mcp?: boolean;
|
|
32
34
|
};
|
|
33
35
|
};
|
|
36
|
+
/** A user as the users admin API returns it (`GET /api/admin/users/:id`, create and edit): an allowlist, never the row. */
|
|
37
|
+
type AdminUserDto = {
|
|
38
|
+
id: number;
|
|
39
|
+
name: string;
|
|
40
|
+
email: string;
|
|
41
|
+
/** Only when an authorization module added the `role` column. */
|
|
42
|
+
role?: string;
|
|
43
|
+
avatar: string | null;
|
|
44
|
+
emailVerifiedAt: string | null;
|
|
45
|
+
lastLoginAt: string | null;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
};
|
|
48
|
+
/** The signed-in user's own profile, as the self-service routes return it. */
|
|
49
|
+
type ProfileDto = {
|
|
50
|
+
id: number;
|
|
51
|
+
name: string;
|
|
52
|
+
email: string;
|
|
53
|
+
avatar: string | null;
|
|
54
|
+
emailVerifiedAt: string | null;
|
|
55
|
+
};
|
|
34
56
|
|
|
35
57
|
declare module 'nitropack' {
|
|
36
58
|
interface NitroRuntimeHooks {
|
|
@@ -56,4 +78,4 @@ declare module 'nuxt/schema' {
|
|
|
56
78
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
57
79
|
|
|
58
80
|
export { _default as default };
|
|
59
|
-
export type { ModuleOptions, PublicModuleOptions };
|
|
81
|
+
export type { AdminUserDto, ModuleOptions, ProfileDto, PublicModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerImportsDir,
|
|
2
|
-
import { registerTailwindSource, registerLocales, registerDatabaseTable, inlineModuleRuntime,
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerImportsDir, hasNuxtModule } from '@nuxt/kit';
|
|
2
|
+
import { registerTailwindSource, registerLocales, registerDatabaseTable, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { setAuthUserStore, addAuthScope } from '@frigear-nu/auth/utils';
|
|
4
4
|
|
|
5
5
|
const module$1 = defineNuxtModule({
|
|
@@ -51,26 +51,34 @@ const module$1 = defineNuxtModule({
|
|
|
51
51
|
nuxt.hook("notify:email:templates", (sources) => sources.push({ dir: resolver.resolve("./runtime/emails") }));
|
|
52
52
|
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
53
53
|
inlineModuleRuntime(nuxt, resolver);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
]
|
|
59
|
-
addServerHandler({ route: moduleApiUrl("users", path), method: "post", handler: resolver.resolve(`./runtime/server/routes/me/${file}`) });
|
|
60
|
-
}
|
|
54
|
+
const selfRoutes = [
|
|
55
|
+
{ method: "patch", path: "me", file: "me/profile.patch" },
|
|
56
|
+
{ method: "put", path: "me/email", file: "me/email.put" },
|
|
57
|
+
{ method: "put", path: "me/password", file: "me/password.put" }
|
|
58
|
+
];
|
|
61
59
|
if (settings.verifyEmailChange) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
selfRoutes.push(
|
|
61
|
+
{ method: "get", path: "email-change", file: "me/email-change.get" },
|
|
62
|
+
{ method: "post", path: "email-change/confirm", file: "me/email-change-confirm.post" },
|
|
63
|
+
{ method: "get", path: "email-change/revert", file: "me/email-change-revert.get" },
|
|
64
|
+
{ method: "post", path: "email-change/revert", file: "me/email-change-revert.post" }
|
|
65
|
+
);
|
|
66
|
+
nuxt.hook("modules:done", () => {
|
|
67
|
+
if (!hasNuxtModule("@nuxt/ui", nuxt)) {
|
|
68
|
+
console.warn("[@frigear-nu/users] `settings.verifyEmailChange` is on, but `@nuxt/ui` is not installed: add your own pages at `/auth/verify-email-change` and `/auth/revert-email-change` (see the users module docs).");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
addModulePages("@frigear-nu/users", resolver, [
|
|
72
|
+
{ name: "users-verify-email-change", path: "/auth/verify-email-change", file: "./runtime/app/pages/verify-email-change.vue" },
|
|
73
|
+
{ name: "users-revert-email-change", path: "/auth/revert-email-change", file: "./runtime/app/pages/revert-email-change.vue" }
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
69
76
|
registerDatabaseTable(nuxt, {
|
|
70
77
|
resolver,
|
|
71
78
|
schema: (dialect) => `./runtime/db/email-changes.${dialect}`
|
|
72
79
|
});
|
|
73
80
|
}
|
|
81
|
+
addModuleRoutes(resolver, selfRoutes, { base: "/api/users" });
|
|
74
82
|
if (settings.mcp === true) {
|
|
75
83
|
const { addMcpDefinitions } = await import('@frigear-nu/mcp/utils');
|
|
76
84
|
addAuthScope(nuxt, { name: "profile:read", description: "Read your own name, email and role (MCP)" });
|
|
@@ -85,19 +93,17 @@ const module$1 = defineNuxtModule({
|
|
|
85
93
|
}
|
|
86
94
|
const adminPagePath = withAdmin && withAdminShell ? resolvePagePath(adminOptions.page ?? true, (await import('@frigear-nu/admin/utils')).adminRoute(nuxt, "users")) : void 0;
|
|
87
95
|
if (withAdmin) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
]
|
|
99
|
-
addServerHandler({ route: path, method, handler: resolver.resolve(`./runtime/server/routes/admin/${file}`) });
|
|
100
|
-
}
|
|
96
|
+
addModuleRoutes(resolver, [
|
|
97
|
+
{ method: "get", path: "", file: "admin/users.get" },
|
|
98
|
+
{ method: "post", path: "", file: "admin/users.post" },
|
|
99
|
+
{ method: "get", path: "new", file: "admin/new.get" },
|
|
100
|
+
{ method: "get", path: "stats", file: "admin/stats.get" },
|
|
101
|
+
{ method: "get", path: "roles", file: "admin/roles.get" },
|
|
102
|
+
{ method: "get", path: ":id", file: "admin/user.get" },
|
|
103
|
+
{ method: "patch", path: ":id", file: "admin/user.patch" },
|
|
104
|
+
{ method: "delete", path: ":id", file: "admin/user.delete" },
|
|
105
|
+
{ method: "post", path: ":id/resend", file: "admin/user-resend.post" }
|
|
106
|
+
], { base: "/api/admin/users" });
|
|
101
107
|
if (adminPagePath) {
|
|
102
108
|
addModulePages("@frigear-nu/users", resolver, [
|
|
103
109
|
{ name: "users-admin", path: adminPagePath, file: "./runtime/app/pages/admin.vue" },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { usersApi } from "../../utils/api";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
defineOptions({ name: "UsersUserCreateSlideover" });
|
|
4
5
|
const props = defineProps({
|
|
@@ -19,7 +20,7 @@ const roleLabel = (value) => t(`admin.roleNames.${value}`, value.charAt(0).toUpp
|
|
|
19
20
|
const roleItems = computed(() => (props.roles ?? []).map((value) => ({ label: roleLabel(value), value })));
|
|
20
21
|
async function save(event) {
|
|
21
22
|
const created = await run(
|
|
22
|
-
() => $fetch(
|
|
23
|
+
() => $fetch(usersApi.admin.users, {
|
|
23
24
|
method: "POST",
|
|
24
25
|
body: { ...event.data, role: roleItems.value.length && event.data.role ? event.data.role : void 0 }
|
|
25
26
|
}),
|
|
@@ -14,7 +14,7 @@ export interface UserMenuOptions {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Everything staff do to a user: `create` (a slideover), `remove` (confirm, toast, refresh) and `menu(user)` for the
|
|
17
|
+
* Everything staff do to a user: `create` (a slideover, then the new user's page), `remove` (confirm, toast, refresh) and `menu(user)` for the
|
|
18
18
|
* `RowMenu` of the list rows and the detail heading, ordered Open, sign-in link, extras, then Delete in its own group.
|
|
19
19
|
*/
|
|
20
20
|
export declare function useUserActions(): {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import UserCreateSlideover from "../components/UserCreateSlideover.vue";
|
|
2
2
|
import { ADMIN_USERS_KEY } from "../utils/admin-user.js";
|
|
3
|
+
import { usersApi } from "../../utils/api.js";
|
|
3
4
|
export function useUserActions() {
|
|
4
5
|
const t = useModuleT("users");
|
|
5
6
|
const overlay = useOverlay();
|
|
@@ -10,7 +11,9 @@ export function useUserActions() {
|
|
|
10
11
|
const listPath = computed(() => localize(adminPage.replace(/\/+$/, "")));
|
|
11
12
|
const userPath = (id) => `${listPath.value}/${id}`;
|
|
12
13
|
async function create(options = {}) {
|
|
13
|
-
|
|
14
|
+
const created = await overlay.create(UserCreateSlideover).open({ roles: options.roles ?? [] });
|
|
15
|
+
if (created) await navigateTo(userPath(created.id));
|
|
16
|
+
return created;
|
|
14
17
|
}
|
|
15
18
|
async function remove(user, options = {}) {
|
|
16
19
|
const confirmed = await confirm({
|
|
@@ -21,7 +24,7 @@ export function useUserActions() {
|
|
|
21
24
|
});
|
|
22
25
|
if (!confirmed) return false;
|
|
23
26
|
const done = await run(
|
|
24
|
-
() => $fetch(
|
|
27
|
+
() => $fetch(usersApi.admin.user(user.id), { method: "DELETE" }).then(() => true),
|
|
25
28
|
{ success: t("admin.deleted", "User deleted.") }
|
|
26
29
|
);
|
|
27
30
|
if (!done) return false;
|
|
@@ -31,7 +34,7 @@ export function useUserActions() {
|
|
|
31
34
|
}
|
|
32
35
|
async function resend(user) {
|
|
33
36
|
const sent = await run(
|
|
34
|
-
() => $fetch(
|
|
37
|
+
() => $fetch(usersApi.admin.resend(user.id), { method: "POST" }).then(() => true),
|
|
35
38
|
{ success: t("admin.resent", "Sign-in link sent.") }
|
|
36
39
|
);
|
|
37
40
|
return !!sent;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { usersApi } from "../../utils/api";
|
|
2
3
|
import OverviewTab from "../tabs/Overview.vue";
|
|
3
4
|
import { useUserActions } from "../composables/useUserActions";
|
|
4
5
|
defineOptions({ name: "UsersAdminUserPage" });
|
|
@@ -6,7 +7,8 @@ const t = useModuleT("users");
|
|
|
6
7
|
const route = useRoute();
|
|
7
8
|
const actions = useUserActions();
|
|
8
9
|
const id = computed(() => route.params.id);
|
|
9
|
-
const { data: user, refresh, error } = await useFetch(() =>
|
|
10
|
+
const { data: user, refresh, error } = await useFetch(() => usersApi.admin.user(id.value));
|
|
11
|
+
const forbidden = computed(() => [401, 403].includes(error.value?.statusCode ?? 0));
|
|
10
12
|
const Tabs = resolveComponent("WidgetTabs");
|
|
11
13
|
const tabs = typeof Tabs === "string" ? void 0 : Tabs;
|
|
12
14
|
const menu = computed(() => user.value ? actions.menu(user.value, {
|
|
@@ -21,7 +23,14 @@ const menu = computed(() => user.value ? actions.menu(user.value, {
|
|
|
21
23
|
<template>
|
|
22
24
|
<div class="flex flex-col gap-4">
|
|
23
25
|
<UEmpty
|
|
24
|
-
v-if="error
|
|
26
|
+
v-if="error && error.statusCode !== 404"
|
|
27
|
+
:icon="forbidden ? 'i-lucide-lock' : 'i-lucide-circle-alert'"
|
|
28
|
+
:title="forbidden ? t('admin.forbidden', 'You do not have access to users') : t('admin.detail.loadFailed', 'The user could not be loaded')"
|
|
29
|
+
:description="errorMessage(error, '')"
|
|
30
|
+
:actions="forbidden ? [] : [{ label: t('admin.tryAgain', 'Try again'), icon: 'i-lucide-rotate-ccw', color: 'neutral', variant: 'outline', onClick: () => refresh() }]"
|
|
31
|
+
/>
|
|
32
|
+
<UEmpty
|
|
33
|
+
v-else-if="error || !user"
|
|
25
34
|
icon="i-lucide-user-x"
|
|
26
35
|
:title="t('admin.detail.notFound', 'User not found')"
|
|
27
36
|
:description="t('admin.detail.notFoundHint', 'It may have been deleted.')"
|
|
@@ -34,9 +43,9 @@ const menu = computed(() => user.value ? actions.menu(user.value, {
|
|
|
34
43
|
:breadcrumb="[{ label: t('admin.title', 'Users'), to: actions.listPath.value }, { label: user.name }]"
|
|
35
44
|
>
|
|
36
45
|
<template #badge>
|
|
37
|
-
<
|
|
38
|
-
:
|
|
39
|
-
|
|
46
|
+
<StatusBadge
|
|
47
|
+
:status="user.emailVerifiedAt ? 'verified' : 'unverified'"
|
|
48
|
+
:colors="{ verified: 'success', unverified: 'warning' }"
|
|
40
49
|
:label="user.emailVerifiedAt ? t('admin.filters.verified', 'Verified') : t('admin.filters.unverified', 'Unverified')"
|
|
41
50
|
/>
|
|
42
51
|
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { usersApi } from "../../utils/api";
|
|
2
3
|
import { ADMIN_USERS_KEY } from "../utils/admin-user";
|
|
3
4
|
import { useUserActions } from "../composables/useUserActions";
|
|
4
5
|
defineOptions({ name: "UsersAdminPage" });
|
|
@@ -11,20 +12,22 @@ const { page, pageSize, search, sort: sortState, filters, query, filtered, reset
|
|
|
11
12
|
});
|
|
12
13
|
const sort = useTableSort(null, sortState);
|
|
13
14
|
const { sorting } = sort;
|
|
14
|
-
const { data, status } = await useFetch(
|
|
15
|
+
const { data, status, error, refresh } = await useFetch(usersApi.admin.users, {
|
|
15
16
|
key: ADMIN_USERS_KEY,
|
|
16
|
-
query
|
|
17
|
-
default: () => ({ items: [], total: 0, page: 1, pageSize: 20, hasRoles: false, hasSubscriptions: false, roles: [] })
|
|
17
|
+
query
|
|
18
18
|
});
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const rows = computed(() => data.value?.items ?? []);
|
|
20
|
+
const hasRoles = computed(() => data.value?.hasRoles ?? false);
|
|
21
|
+
const hasSubscriptions = computed(() => data.value?.hasSubscriptions ?? false);
|
|
22
|
+
const roles = computed(() => data.value?.roles ?? []);
|
|
23
|
+
const forbidden = computed(() => [401, 403].includes(error.value?.statusCode ?? 0));
|
|
21
24
|
const roleLabel = (value) => t(`admin.roleNames.${value}`, value.charAt(0).toUpperCase() + value.slice(1));
|
|
22
|
-
const roleItems = computed(() =>
|
|
25
|
+
const roleItems = computed(() => roles.value.map((value) => ({ label: roleLabel(value), value })));
|
|
23
26
|
const roleFilterItems = computed(() => [{ label: t("admin.filters.allRoles", "All roles"), value: "all" }, ...roleItems.value]);
|
|
24
27
|
const pending = computed(() => status.value === "pending");
|
|
25
|
-
const loading = computed(() => pending.value && !data.value
|
|
26
|
-
const refreshing = computed(() => pending.value && !!data.value
|
|
27
|
-
const
|
|
28
|
+
const loading = computed(() => pending.value && !data.value);
|
|
29
|
+
const refreshing = computed(() => pending.value && !!data.value);
|
|
30
|
+
const StatusBadge = resolveComponent("StatusBadge");
|
|
28
31
|
const TableIdentity = resolveComponent("TableIdentity");
|
|
29
32
|
const RowMenu = resolveComponent("RowMenu");
|
|
30
33
|
const dateCell = (value) => value ? h("time", { datetime: value, title: format.dateTime(value), class: "tabular-nums" }, format.date(value)) : emptyCell();
|
|
@@ -45,18 +48,18 @@ const columns = computed(() => [
|
|
|
45
48
|
}] : [],
|
|
46
49
|
...hasSubscriptions.value ? [{
|
|
47
50
|
id: "subscription",
|
|
48
|
-
header: t("admin.subscription", "
|
|
51
|
+
header: t("admin.subscription", "Membership"),
|
|
49
52
|
cell: ({ row }) => {
|
|
50
53
|
const subscription = row.original.subscription;
|
|
51
|
-
return subscription ? h(
|
|
54
|
+
return subscription ? h(StatusBadge, { status: subscription.status, label: subscription.planKey ?? subscription.status }) : emptyCell();
|
|
52
55
|
}
|
|
53
56
|
}] : [],
|
|
54
57
|
{
|
|
55
58
|
id: "verified",
|
|
56
59
|
header: t("admin.verified", "Verified"),
|
|
57
|
-
cell: ({ row }) => h(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
cell: ({ row }) => h(StatusBadge, {
|
|
61
|
+
status: row.original.emailVerifiedAt ? "verified" : "unverified",
|
|
62
|
+
colors: { verified: "success" },
|
|
60
63
|
label: row.original.emailVerifiedAt ? t("admin.filters.verified", "Verified") : t("admin.filters.unverified", "Unverified")
|
|
61
64
|
})
|
|
62
65
|
},
|
|
@@ -81,10 +84,7 @@ const verifiedOptions = computed(() => [
|
|
|
81
84
|
function openUser(_event, row) {
|
|
82
85
|
return navigateTo(actions.userPath(row.original.id));
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
const created = await actions.create({ roles: hasRoles.value ? data.value.roles : [] });
|
|
86
|
-
if (created) await navigateTo(actions.userPath(created.id));
|
|
87
|
-
}
|
|
87
|
+
const addUser = () => actions.create({ roles: hasRoles.value ? roles.value : [] });
|
|
88
88
|
</script>
|
|
89
89
|
|
|
90
90
|
<template>
|
|
@@ -92,72 +92,82 @@ async function addUser() {
|
|
|
92
92
|
<PageHeading :title="t('admin.title', 'Users')">
|
|
93
93
|
<template #actions>
|
|
94
94
|
<UButton
|
|
95
|
-
icon="i-lucide-
|
|
95
|
+
icon="i-lucide-plus"
|
|
96
96
|
:label="t('admin.create', 'Add user')"
|
|
97
97
|
@click="addUser"
|
|
98
98
|
/>
|
|
99
99
|
</template>
|
|
100
100
|
</PageHeading>
|
|
101
101
|
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/>
|
|
110
|
-
<USelect
|
|
111
|
-
v-model="filters.verified"
|
|
112
|
-
:items="verifiedOptions"
|
|
113
|
-
class="w-40"
|
|
114
|
-
/>
|
|
115
|
-
<USelect
|
|
116
|
-
v-if="hasRoles"
|
|
117
|
-
v-model="filters.role"
|
|
118
|
-
:items="roleFilterItems"
|
|
119
|
-
class="w-48"
|
|
120
|
-
icon="i-lucide-shield"
|
|
121
|
-
/>
|
|
122
|
-
<UButton
|
|
123
|
-
v-if="filtered"
|
|
124
|
-
variant="ghost"
|
|
125
|
-
color="neutral"
|
|
126
|
-
icon="i-lucide-x"
|
|
127
|
-
:label="t('admin.filters.clear', 'Clear filters')"
|
|
128
|
-
@click="reset"
|
|
129
|
-
/>
|
|
130
|
-
</PageToolbar>
|
|
102
|
+
<UEmpty
|
|
103
|
+
v-if="error && !data"
|
|
104
|
+
:icon="forbidden ? 'i-lucide-lock' : 'i-lucide-circle-alert'"
|
|
105
|
+
:title="forbidden ? t('admin.forbidden', 'You do not have access to users') : t('admin.loadFailed', 'Users could not be loaded')"
|
|
106
|
+
:description="errorMessage(error, '')"
|
|
107
|
+
:actions="forbidden ? [] : [{ label: t('admin.tryAgain', 'Try again'), icon: 'i-lucide-rotate-ccw', color: 'neutral', variant: 'outline', onClick: () => refresh() }]"
|
|
108
|
+
/>
|
|
131
109
|
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
110
|
+
<template v-else>
|
|
111
|
+
<PageToolbar>
|
|
112
|
+
<UInput
|
|
113
|
+
v-model="search"
|
|
114
|
+
class="w-full max-w-sm"
|
|
115
|
+
icon="i-lucide-search"
|
|
116
|
+
:loading="pending"
|
|
117
|
+
:placeholder="t('admin.search', 'Search name, email or role...')"
|
|
118
|
+
/>
|
|
119
|
+
<USelect
|
|
120
|
+
v-model="filters.verified"
|
|
121
|
+
:items="verifiedOptions"
|
|
122
|
+
class="w-40"
|
|
123
|
+
/>
|
|
124
|
+
<USelect
|
|
125
|
+
v-if="hasRoles"
|
|
126
|
+
v-model="filters.role"
|
|
127
|
+
:items="roleFilterItems"
|
|
128
|
+
class="w-48"
|
|
129
|
+
icon="i-lucide-shield"
|
|
130
|
+
/>
|
|
131
|
+
<UButton
|
|
132
|
+
v-if="filtered"
|
|
133
|
+
variant="ghost"
|
|
134
|
+
color="neutral"
|
|
135
|
+
icon="i-lucide-x"
|
|
136
|
+
:label="t('admin.filters.clear', 'Clear filters')"
|
|
137
|
+
@click="reset"
|
|
138
|
+
/>
|
|
139
|
+
</PageToolbar>
|
|
140
|
+
|
|
141
|
+
<TableCard
|
|
142
|
+
:loading="loading"
|
|
143
|
+
:refreshing="refreshing"
|
|
144
144
|
>
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
<UTable
|
|
146
|
+
v-model:sorting="sorting"
|
|
147
|
+
:data="rows"
|
|
148
|
+
:columns="columns"
|
|
149
|
+
:sorting-options="{ manualSorting: true }"
|
|
150
|
+
:ui="tableUi({}, { sticky: true })"
|
|
151
|
+
sticky
|
|
152
|
+
@select="openUser"
|
|
153
|
+
>
|
|
154
|
+
<template #empty>
|
|
155
|
+
<UEmpty
|
|
156
|
+
icon="i-lucide-users"
|
|
157
|
+
variant="naked"
|
|
158
|
+
:title="t('admin.empty', 'No users match')"
|
|
159
|
+
:actions="[filtered ? { label: t('admin.filters.clear', 'Clear filters'), color: 'neutral', variant: 'outline', onClick: reset } : { label: t('admin.create', 'Add user'), icon: 'i-lucide-plus', onClick: addUser }]"
|
|
160
|
+
/>
|
|
161
|
+
</template>
|
|
162
|
+
</UTable>
|
|
163
|
+
<template #footer>
|
|
164
|
+
<TablePagination
|
|
165
|
+
v-model:page="page"
|
|
166
|
+
v-model:page-size="pageSize"
|
|
167
|
+
:total="data?.total ?? 0"
|
|
151
168
|
/>
|
|
152
169
|
</template>
|
|
153
|
-
</
|
|
154
|
-
|
|
155
|
-
<TablePagination
|
|
156
|
-
v-model:page="page"
|
|
157
|
-
v-model:page-size="pageSize"
|
|
158
|
-
:total="data.total"
|
|
159
|
-
/>
|
|
160
|
-
</template>
|
|
161
|
-
</TableCard>
|
|
170
|
+
</TableCard>
|
|
171
|
+
</template>
|
|
162
172
|
</div>
|
|
163
173
|
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { usersApi } from "../../utils/api";
|
|
3
|
+
defineOptions({ name: "UsersRevertEmailChangePage" });
|
|
4
|
+
const t = useModuleT("users.emailChange");
|
|
5
|
+
const route = useRoute();
|
|
6
|
+
const { fetch: refreshSession } = useUserSession();
|
|
7
|
+
const loginPath = useAuthPages().login;
|
|
8
|
+
const passwordReset = useRuntimeConfig().public.authentication?.passwordReset === true;
|
|
9
|
+
const code = computed(() => typeof route.query.code === "string" ? route.query.code : "");
|
|
10
|
+
const { data: preview, error: previewError } = await useFetch(usersApi.emailChangeRevert, {
|
|
11
|
+
query: { code },
|
|
12
|
+
immediate: !!code.value
|
|
13
|
+
});
|
|
14
|
+
const reverting = ref(false);
|
|
15
|
+
const restoredEmail = ref(null);
|
|
16
|
+
const error = ref(null);
|
|
17
|
+
const state = computed(() => {
|
|
18
|
+
if (restoredEmail.value) return "done";
|
|
19
|
+
if (!code.value || previewError.value || !preview.value || preview.value.status === "expired") return "invalid";
|
|
20
|
+
return preview.value.status === "reverted" ? "reverted" : "revert";
|
|
21
|
+
});
|
|
22
|
+
async function onRevert() {
|
|
23
|
+
reverting.value = true;
|
|
24
|
+
error.value = null;
|
|
25
|
+
try {
|
|
26
|
+
const result = await $fetch(usersApi.emailChangeRevert, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: { code: code.value }
|
|
29
|
+
});
|
|
30
|
+
if (result.signedOut) await refreshSession();
|
|
31
|
+
restoredEmail.value = result.email;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
const status = err?.statusCode;
|
|
34
|
+
error.value = status === 400 ? t("revert.invalid", "This link is invalid or has expired.") : status === 409 ? t("revert.taken", "Another account now uses your old e-mail address. Contact us to get your account back.") : t("revert.failed", "Could not restore your e-mail address. Try again.");
|
|
35
|
+
} finally {
|
|
36
|
+
reverting.value = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<AuthCard :title="t('revert.title', 'Undo e-mail change')">
|
|
43
|
+
<template v-if="state === 'invalid'">
|
|
44
|
+
<UAlert
|
|
45
|
+
color="error"
|
|
46
|
+
variant="subtle"
|
|
47
|
+
:title="t('revert.invalid', 'This link is invalid or has expired.')"
|
|
48
|
+
:description="t('revert.invalidHint', 'The link works once, for 7 days after the change.')"
|
|
49
|
+
/>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<template v-else-if="state === 'reverted'">
|
|
53
|
+
<UAlert
|
|
54
|
+
color="neutral"
|
|
55
|
+
variant="subtle"
|
|
56
|
+
icon="i-lucide-circle-check"
|
|
57
|
+
:title="t('revert.already', 'This change was already undone.')"
|
|
58
|
+
/>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<template v-else-if="state === 'done'">
|
|
62
|
+
<UAlert
|
|
63
|
+
color="success"
|
|
64
|
+
variant="subtle"
|
|
65
|
+
icon="i-lucide-circle-check"
|
|
66
|
+
:title="t('revert.done', 'Your e-mail address is {email} again.', { email: restoredEmail ?? '' })"
|
|
67
|
+
:description="passwordReset ? t('revert.doneHint', 'Sign in again. If you did not ask for the change, reset your password too.') : t('revert.doneHintNoReset', 'Sign in again to continue.')"
|
|
68
|
+
/>
|
|
69
|
+
<UButton
|
|
70
|
+
block
|
|
71
|
+
:to="loginPath"
|
|
72
|
+
icon="i-lucide-log-in"
|
|
73
|
+
:label="t('revert.signIn', 'Sign in')"
|
|
74
|
+
/>
|
|
75
|
+
<UButton
|
|
76
|
+
v-if="passwordReset"
|
|
77
|
+
block
|
|
78
|
+
color="neutral"
|
|
79
|
+
variant="outline"
|
|
80
|
+
to="/forgot-password"
|
|
81
|
+
:label="t('revert.resetPassword', 'Reset password')"
|
|
82
|
+
/>
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
<template v-else-if="preview">
|
|
86
|
+
<p class="text-center text-sm text-muted">
|
|
87
|
+
{{ t("revert.description", "The e-mail address of your account was changed to {newEmail}. If that was not you, restore {oldEmail}.", { newEmail: preview.newEmail, oldEmail: preview.oldEmail }) }}
|
|
88
|
+
</p>
|
|
89
|
+
<UAlert
|
|
90
|
+
v-if="error"
|
|
91
|
+
color="error"
|
|
92
|
+
variant="subtle"
|
|
93
|
+
:title="error"
|
|
94
|
+
/>
|
|
95
|
+
<UButton
|
|
96
|
+
block
|
|
97
|
+
color="error"
|
|
98
|
+
:loading="reverting"
|
|
99
|
+
:label="t('revert.submit', 'Restore {email}', { email: preview.oldEmail })"
|
|
100
|
+
@click="onRevert"
|
|
101
|
+
/>
|
|
102
|
+
</template>
|
|
103
|
+
</AuthCard>
|
|
104
|
+
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|