nuxt-users 1.4.0 → 1.5.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.
- package/CHANGELOG.md +34 -0
- package/dist/cli.mjs +12 -30
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +37 -0
- package/dist/runtime/components/LoginForm.vue.d.ts +3 -3
- package/dist/runtime/components/PasswordStrengthIndicator.vue +132 -0
- package/dist/runtime/components/PasswordStrengthIndicator.vue.d.ts +12 -0
- package/dist/runtime/components/ProfileForm.vue +240 -0
- package/dist/runtime/components/ProfileForm.vue.d.ts +20 -0
- package/dist/runtime/components/ResetPasswordForm.vue +30 -4
- package/dist/runtime/composables/useAuth.d.ts +20 -2
- package/dist/runtime/composables/useAuth.js +53 -2
- package/dist/runtime/composables/usePasswordValidation.d.ts +33 -0
- package/dist/runtime/composables/usePasswordValidation.js +37 -0
- package/dist/runtime/plugin.js +29 -1
- package/dist/runtime/server/api/auth/reset-password.post.js +9 -3
- package/dist/runtime/server/api/profile/update-password.post.d.ts +4 -0
- package/dist/runtime/server/api/profile/update-password.post.js +60 -0
- package/dist/runtime/server/api/profile.get.d.ts +11 -0
- package/dist/runtime/server/api/profile.get.js +23 -0
- package/dist/shared/{nuxt-users.DZkU2AbH.mjs → nuxt-users.37k1R3_g.mjs} +172 -1
- package/dist/shared/{nuxt-users.DGRKT2Tq.d.mts → nuxt-users.CMEtv_Mw.d.mts} +64 -6
- package/dist/shared/{nuxt-users.DGRKT2Tq.d.ts → nuxt-users.CMEtv_Mw.d.ts} +64 -6
- package/dist/utils.d.mts +28 -2
- package/dist/utils.d.ts +28 -2
- package/dist/utils.mjs +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.5.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.4.0...v1.5.0)
|
|
7
|
+
|
|
8
|
+
### 🚀 Enhancements
|
|
9
|
+
|
|
10
|
+
- Implement forgot password closes #57 ([#57](https://github.com/rrd108/nuxt-users/issues/57))
|
|
11
|
+
- Add profile page closes #58 ([#58](https://github.com/rrd108/nuxt-users/issues/58))
|
|
12
|
+
|
|
13
|
+
### 🩹 Fixes
|
|
14
|
+
|
|
15
|
+
- Css color ([1d72336](https://github.com/rrd108/nuxt-users/commit/1d72336))
|
|
16
|
+
- Auth middleware ([113b165](https://github.com/rrd108/nuxt-users/commit/113b165))
|
|
17
|
+
- Enhances auth middleware and improves logging ([f519bbc](https://github.com/rrd108/nuxt-users/commit/f519bbc))
|
|
18
|
+
- Playground colors ([f87ade1](https://github.com/rrd108/nuxt-users/commit/f87ade1))
|
|
19
|
+
- Enhances user authentication and data handling ([d15c77f](https://github.com/rrd108/nuxt-users/commit/d15c77f))
|
|
20
|
+
|
|
21
|
+
### 💅 Refactors
|
|
22
|
+
|
|
23
|
+
- Have a dedicated playground login page ([487d754](https://github.com/rrd108/nuxt-users/commit/487d754))
|
|
24
|
+
- Module options and defaults ([00aa094](https://github.com/rrd108/nuxt-users/commit/00aa094))
|
|
25
|
+
|
|
26
|
+
### 🏡 Chore
|
|
27
|
+
|
|
28
|
+
- **release:** V1.4.0 ([e07ca9a](https://github.com/rrd108/nuxt-users/commit/e07ca9a))
|
|
29
|
+
|
|
30
|
+
### ✅ Tests
|
|
31
|
+
|
|
32
|
+
- Do not run unit tests for various dbs ([5b5e3aa](https://github.com/rrd108/nuxt-users/commit/5b5e3aa))
|
|
33
|
+
|
|
34
|
+
### ❤️ Contributors
|
|
35
|
+
|
|
36
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
37
|
+
|
|
4
38
|
## v1.4.0
|
|
5
39
|
|
|
6
40
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.3.0...v1.4.0)
|
package/dist/cli.mjs
CHANGED
|
@@ -2,36 +2,11 @@
|
|
|
2
2
|
import { defineCommand, runMain } from 'citty';
|
|
3
3
|
import 'db0';
|
|
4
4
|
import 'bcrypt';
|
|
5
|
-
import { r as runMigrations, a as createUser$1, d as createUsersTable$1, e as createPersonalAccessTokensTable$1, g as createPasswordResetTokensTable$1, h as createMigrationsTable$1 } from './shared/nuxt-users.
|
|
5
|
+
import { r as runMigrations, i as getPasswordValidationOptions, v as validatePassword, a as createUser$1, d as createUsersTable$1, e as createPersonalAccessTokensTable$1, g as createPasswordResetTokensTable$1, h as createMigrationsTable$1 } from './shared/nuxt-users.37k1R3_g.mjs';
|
|
6
|
+
import { defaultOptions } from './module.mjs';
|
|
6
7
|
import { loadNuxt } from '@nuxt/kit';
|
|
8
|
+
import 'defu';
|
|
7
9
|
|
|
8
|
-
const defaultOptions = {
|
|
9
|
-
connector: {
|
|
10
|
-
name: "sqlite",
|
|
11
|
-
options: {
|
|
12
|
-
path: "./data/users.sqlite3"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
tables: {
|
|
16
|
-
migrations: "migrations",
|
|
17
|
-
users: "users",
|
|
18
|
-
personalAccessTokens: "personal_access_tokens",
|
|
19
|
-
passwordResetTokens: "password_reset_tokens"
|
|
20
|
-
},
|
|
21
|
-
mailer: {
|
|
22
|
-
host: "smtp.ethereal.email",
|
|
23
|
-
port: 587,
|
|
24
|
-
secure: false,
|
|
25
|
-
auth: {
|
|
26
|
-
user: "user@ethereal.email",
|
|
27
|
-
pass: "password"
|
|
28
|
-
},
|
|
29
|
-
defaults: {
|
|
30
|
-
from: '"Nuxt Users Module" <noreply@example.com>'
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
passwordResetBaseUrl: "http://localhost:3000"
|
|
34
|
-
};
|
|
35
10
|
const getOptionsFromEnv = () => {
|
|
36
11
|
const connectorName = process.env.DB_CONNECTOR || "sqlite";
|
|
37
12
|
let connectorOptions;
|
|
@@ -74,7 +49,7 @@ const loadOptions = async () => {
|
|
|
74
49
|
try {
|
|
75
50
|
console.log("[Nuxt Users] Loading Nuxt project...");
|
|
76
51
|
const nuxt = await loadNuxt({ cwd: process.cwd() });
|
|
77
|
-
const nuxtUsersConfig = nuxt.options.
|
|
52
|
+
const nuxtUsersConfig = nuxt.options.nuxtUsers;
|
|
78
53
|
await nuxt.close();
|
|
79
54
|
if (nuxtUsersConfig) {
|
|
80
55
|
console.log("[Nuxt Users] Using configuration from Nuxt project");
|
|
@@ -144,6 +119,13 @@ const createUser = defineCommand({
|
|
|
144
119
|
const { email, name, password, role } = args;
|
|
145
120
|
const options = await loadOptions();
|
|
146
121
|
try {
|
|
122
|
+
const passwordOptions = getPasswordValidationOptions(options);
|
|
123
|
+
const passwordValidation = validatePassword(password, passwordOptions);
|
|
124
|
+
if (!passwordValidation.isValid) {
|
|
125
|
+
console.error("[Nuxt Users] Password validation failed:");
|
|
126
|
+
passwordValidation.errors.forEach((error) => console.error(` - ${error}`));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
147
129
|
const user = await createUser$1({ email, name, password, role }, options);
|
|
148
130
|
console.log(`[Nuxt Users] User created successfully: ${user.email} (role: ${user.role})`);
|
|
149
131
|
process.exit(0);
|
|
@@ -248,7 +230,7 @@ const projectInfo = defineCommand({
|
|
|
248
230
|
} else {
|
|
249
231
|
console.log("[Nuxt Users] \u26A0\uFE0F Nuxt Users module not configured in runtime config");
|
|
250
232
|
}
|
|
251
|
-
const publicConfig = nuxt.options.runtimeConfig?.
|
|
233
|
+
const publicConfig = nuxt.options.runtimeConfig?.nuxtUsers;
|
|
252
234
|
if (publicConfig) {
|
|
253
235
|
console.log("[Nuxt Users] \u{1F30D} Public runtime config:");
|
|
254
236
|
console.log("[Nuxt Users] Users table exists:", publicConfig.tables?.users);
|
package/dist/module.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { M as ModuleOptions } from './shared/nuxt-users.
|
|
2
|
+
import { M as ModuleOptions } from './shared/nuxt-users.CMEtv_Mw.mjs';
|
|
3
3
|
|
|
4
4
|
declare const defaultOptions: ModuleOptions;
|
|
5
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { M as ModuleOptions } from './shared/nuxt-users.
|
|
2
|
+
import { M as ModuleOptions } from './shared/nuxt-users.CMEtv_Mw.js';
|
|
3
3
|
|
|
4
4
|
declare const defaultOptions: ModuleOptions;
|
|
5
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -29,8 +29,17 @@ const defaultOptions = {
|
|
|
29
29
|
from: '"Nuxt Users Module" <noreply@example.com>'
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
+
passwordResetBaseUrl: "http://localhost:3000",
|
|
32
33
|
auth: {
|
|
33
34
|
whitelist: ["/login"]
|
|
35
|
+
},
|
|
36
|
+
passwordValidation: {
|
|
37
|
+
minLength: 8,
|
|
38
|
+
requireUppercase: true,
|
|
39
|
+
requireLowercase: true,
|
|
40
|
+
requireNumbers: true,
|
|
41
|
+
requireSpecialChars: true,
|
|
42
|
+
preventCommonPasswords: true
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
45
|
const module = defineNuxtModule({
|
|
@@ -55,6 +64,20 @@ const module = defineNuxtModule({
|
|
|
55
64
|
whitelist: [...defaultOptions.auth?.whitelist || [], ...options.auth?.whitelist || []]
|
|
56
65
|
}
|
|
57
66
|
};
|
|
67
|
+
nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {};
|
|
68
|
+
nuxt.options.runtimeConfig.public.nuxtUsers = {
|
|
69
|
+
passwordValidation: {
|
|
70
|
+
minLength: options.passwordValidation?.minLength || defaultOptions.passwordValidation.minLength,
|
|
71
|
+
requireUppercase: options.passwordValidation?.requireUppercase ?? defaultOptions.passwordValidation.requireUppercase,
|
|
72
|
+
requireLowercase: options.passwordValidation?.requireLowercase ?? defaultOptions.passwordValidation.requireLowercase,
|
|
73
|
+
requireNumbers: options.passwordValidation?.requireNumbers ?? defaultOptions.passwordValidation.requireNumbers,
|
|
74
|
+
requireSpecialChars: options.passwordValidation?.requireSpecialChars ?? defaultOptions.passwordValidation.requireSpecialChars,
|
|
75
|
+
preventCommonPasswords: options.passwordValidation?.preventCommonPasswords ?? defaultOptions.passwordValidation.preventCommonPasswords
|
|
76
|
+
},
|
|
77
|
+
auth: {
|
|
78
|
+
whitelist: [...defaultOptions.auth?.whitelist || [], ...options.auth?.whitelist || []]
|
|
79
|
+
}
|
|
80
|
+
};
|
|
58
81
|
addPlugin({
|
|
59
82
|
src: resolver.resolve("./runtime/plugin"),
|
|
60
83
|
mode: "server"
|
|
@@ -80,6 +103,16 @@ const module = defineNuxtModule({
|
|
|
80
103
|
method: "get",
|
|
81
104
|
handler: resolver.resolve("./runtime/server/api/logout.get")
|
|
82
105
|
});
|
|
106
|
+
addServerHandler({
|
|
107
|
+
route: "/api/profile",
|
|
108
|
+
method: "get",
|
|
109
|
+
handler: resolver.resolve("./runtime/server/api/profile.get")
|
|
110
|
+
});
|
|
111
|
+
addServerHandler({
|
|
112
|
+
route: "/api/profile/update-password",
|
|
113
|
+
method: "post",
|
|
114
|
+
handler: resolver.resolve("./runtime/server/api/profile/update-password.post")
|
|
115
|
+
});
|
|
83
116
|
addComponent({
|
|
84
117
|
name: "LoginForm",
|
|
85
118
|
filePath: resolver.resolve("./runtime/components/LoginForm.vue")
|
|
@@ -96,6 +129,10 @@ const module = defineNuxtModule({
|
|
|
96
129
|
name: "LogoutLink",
|
|
97
130
|
filePath: resolver.resolve("./runtime/components/LogoutLink.vue")
|
|
98
131
|
});
|
|
132
|
+
addComponent({
|
|
133
|
+
name: "ProfileForm",
|
|
134
|
+
filePath: resolver.resolve("./runtime/components/ProfileForm.vue")
|
|
135
|
+
});
|
|
99
136
|
nuxt.options.css = nuxt.options.css || [];
|
|
100
137
|
nuxt.options.css.push(resolver.resolve("./runtime/assets/colors.css"));
|
|
101
138
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LoginFormData, LoginFormProps,
|
|
1
|
+
import type { LoginFormData, LoginFormProps, UserWithoutPassword } from '../../types.js';
|
|
2
2
|
declare var __VLS_1: {}, __VLS_3: {}, __VLS_5: {}, __VLS_7: {}, __VLS_9: {}, __VLS_11: {}, __VLS_13: {
|
|
3
3
|
message: string;
|
|
4
4
|
}, __VLS_15: {
|
|
@@ -24,13 +24,13 @@ type __VLS_Slots = {} & {
|
|
|
24
24
|
declare const __VLS_component: import("vue").DefineComponent<LoginFormProps, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
25
25
|
error: (error: string) => any;
|
|
26
26
|
submit: (data: LoginFormData) => any;
|
|
27
|
-
success: (user:
|
|
27
|
+
success: (user: UserWithoutPassword) => any;
|
|
28
28
|
"forgot-password-error": (error: string) => any;
|
|
29
29
|
"forgot-password-success": () => any;
|
|
30
30
|
}, string, import("vue").PublicProps, Readonly<LoginFormProps> & Readonly<{
|
|
31
31
|
onError?: ((error: string) => any) | undefined;
|
|
32
32
|
onSubmit?: ((data: LoginFormData) => any) | undefined;
|
|
33
|
-
onSuccess?: ((user:
|
|
33
|
+
onSuccess?: ((user: UserWithoutPassword) => any) | undefined;
|
|
34
34
|
"onForgot-password-error"?: ((error: string) => any) | undefined;
|
|
35
35
|
"onForgot-password-success"?: (() => any) | undefined;
|
|
36
36
|
}>, {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
const props = defineProps({
|
|
4
|
+
password: { type: String, required: true },
|
|
5
|
+
validationResult: { type: [Object, null], required: true },
|
|
6
|
+
showHints: { type: Boolean, required: false, default: true },
|
|
7
|
+
showRules: { type: Boolean, required: false, default: true }
|
|
8
|
+
});
|
|
9
|
+
const hasErrors = computed(() => (props.validationResult?.errors?.length || 0) > 0);
|
|
10
|
+
const hasHints = computed(() => (props.validationResult?.hints?.length || 0) > 0);
|
|
11
|
+
const hasPassword = computed(() => props.password.length > 0);
|
|
12
|
+
const validationRules = computed(() => {
|
|
13
|
+
if (!props.password) return [];
|
|
14
|
+
const rules = [];
|
|
15
|
+
const minLength = 8;
|
|
16
|
+
const hasMinLength = props.password.length >= minLength;
|
|
17
|
+
rules.push({
|
|
18
|
+
text: `At least ${minLength} characters`,
|
|
19
|
+
passed: hasMinLength
|
|
20
|
+
});
|
|
21
|
+
const hasUppercase = /[A-Z]/.test(props.password);
|
|
22
|
+
rules.push({
|
|
23
|
+
text: "Contains uppercase letter (A-Z)",
|
|
24
|
+
passed: hasUppercase
|
|
25
|
+
});
|
|
26
|
+
const hasLowercase = /[a-z]/.test(props.password);
|
|
27
|
+
rules.push({
|
|
28
|
+
text: "Contains lowercase letter (a-z)",
|
|
29
|
+
passed: hasLowercase
|
|
30
|
+
});
|
|
31
|
+
const hasNumbers = /\d/.test(props.password);
|
|
32
|
+
rules.push({
|
|
33
|
+
text: "Contains number (0-9)",
|
|
34
|
+
passed: hasNumbers
|
|
35
|
+
});
|
|
36
|
+
const hasSpecialChars = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(props.password);
|
|
37
|
+
rules.push({
|
|
38
|
+
text: "Contains special character (!@#$%^&*)",
|
|
39
|
+
passed: hasSpecialChars
|
|
40
|
+
});
|
|
41
|
+
return rules;
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<!-- Password strength indicator -->
|
|
47
|
+
<div
|
|
48
|
+
v-if="hasPassword"
|
|
49
|
+
class="password-strength"
|
|
50
|
+
>
|
|
51
|
+
<div class="strength-bar">
|
|
52
|
+
<div
|
|
53
|
+
class="strength-fill"
|
|
54
|
+
:style="{
|
|
55
|
+
width: `${validationResult?.score || 0}%`,
|
|
56
|
+
backgroundColor: validationResult?.strength === 'weak' ? '#dc3545' : validationResult?.strength === 'medium' ? '#ffc107' : validationResult?.strength === 'strong' ? '#28a745' : '#6c757d'
|
|
57
|
+
}"
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
<span
|
|
61
|
+
class="strength-text"
|
|
62
|
+
:style="{
|
|
63
|
+
color: validationResult?.strength === 'weak' ? '#dc3545' : validationResult?.strength === 'medium' ? '#ffc107' : validationResult?.strength === 'strong' ? '#28a745' : '#6c757d'
|
|
64
|
+
}"
|
|
65
|
+
>
|
|
66
|
+
{{ validationResult?.strength === "weak" ? "Weak" : validationResult?.strength === "medium" ? "Medium" : validationResult?.strength === "strong" ? "Strong" : "Unknown" }}
|
|
67
|
+
({{ validationResult?.score || 0 }}%)
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<!-- Validation rules -->
|
|
72
|
+
<div
|
|
73
|
+
v-if="showRules && hasPassword"
|
|
74
|
+
class="validation-rules"
|
|
75
|
+
>
|
|
76
|
+
<div class="rules-title">
|
|
77
|
+
Password Requirements:
|
|
78
|
+
</div>
|
|
79
|
+
<ul class="rules-list">
|
|
80
|
+
<li
|
|
81
|
+
v-for="rule in validationRules"
|
|
82
|
+
:key="rule.text"
|
|
83
|
+
class="rule-item"
|
|
84
|
+
:class="{ 'rule-passed': rule.passed, 'rule-failed': !rule.passed }"
|
|
85
|
+
>
|
|
86
|
+
<span class="rule-icon">
|
|
87
|
+
{{ rule.passed ? "\u2713" : "\u2717" }}
|
|
88
|
+
</span>
|
|
89
|
+
<span class="rule-text">
|
|
90
|
+
{{ rule.text }}
|
|
91
|
+
</span>
|
|
92
|
+
</li>
|
|
93
|
+
</ul>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<!-- Validation errors -->
|
|
97
|
+
<div
|
|
98
|
+
v-if="hasErrors"
|
|
99
|
+
class="validation-errors"
|
|
100
|
+
>
|
|
101
|
+
<small
|
|
102
|
+
v-for="error in validationResult?.errors || []"
|
|
103
|
+
:key="String(error)"
|
|
104
|
+
class="error-text"
|
|
105
|
+
>
|
|
106
|
+
{{ error }}
|
|
107
|
+
</small>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<!-- Password improvement hints -->
|
|
111
|
+
<div
|
|
112
|
+
v-if="showHints && hasPassword && hasHints"
|
|
113
|
+
class="password-hints"
|
|
114
|
+
>
|
|
115
|
+
<div class="hint-title">
|
|
116
|
+
How to make your password stronger:
|
|
117
|
+
</div>
|
|
118
|
+
<ul class="hint-list">
|
|
119
|
+
<li
|
|
120
|
+
v-for="hint in validationResult?.hints || []"
|
|
121
|
+
:key="'hint-' + hint"
|
|
122
|
+
class="hint-item"
|
|
123
|
+
>
|
|
124
|
+
{{ hint }}
|
|
125
|
+
</li>
|
|
126
|
+
</ul>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<style scoped>
|
|
131
|
+
.password-strength{margin-top:8px}.strength-bar{background-color:#e9ecef;border-radius:2px;height:4px;margin-bottom:4px;overflow:hidden;width:100%}.strength-fill{height:100%;transition:width .3s ease,background-color .3s ease}.strength-text{font-size:.75rem;font-weight:500}.validation-rules{background-color:#f8f9fa;border:1px solid #e9ecef;border-radius:4px;margin-top:12px;padding:12px}.rules-title{color:#495057;font-size:.875rem;font-weight:600;margin-bottom:8px}.rules-list{list-style:none;margin:0;padding-left:0}.rule-item{align-items:center;display:flex;font-size:.875rem;margin-bottom:6px;transition:color .2s ease}.rule-item:last-child{margin-bottom:0}.rule-passed{color:#28a745}.rule-failed{color:#dc3545}.rule-icon{font-weight:700;margin-right:8px;min-width:16px;text-align:center}.rule-text{flex:1}.validation-errors{margin-top:8px}.error-text{color:#dc3545;display:block;font-size:.875rem;margin-bottom:4px}.error-text:last-child{margin-bottom:0}.password-hints{background-color:#f8f9fa;border:1px solid #e9ecef;border-radius:4px;margin-top:8px;padding:12px}.hint-title{color:#495057;font-size:.875rem;font-weight:600;margin-bottom:8px}.hint-list{margin:0;padding-left:16px}.hint-item{color:#6c757d;font-size:.875rem;margin-bottom:4px}.hint-item:last-child{margin-bottom:0}
|
|
132
|
+
</style>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PasswordValidationResult } from '../../utils/password-validation.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
password: string;
|
|
4
|
+
validationResult: PasswordValidationResult | null;
|
|
5
|
+
showHints?: boolean;
|
|
6
|
+
showRules?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: import("vue").DefineComponent<Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
9
|
+
showHints: boolean;
|
|
10
|
+
showRules: boolean;
|
|
11
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, onMounted, watch } from "vue";
|
|
3
|
+
import { usePasswordValidation } from "../composables/usePasswordValidation";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import PasswordStrengthIndicator from "./PasswordStrengthIndicator.vue";
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
apiEndpoint: { type: String, required: false, default: "/api/profile" },
|
|
8
|
+
updatePasswordEndpoint: { type: String, required: false, default: "/api/profile/update-password" }
|
|
9
|
+
});
|
|
10
|
+
const emit = defineEmits(["success", "error", "password-error", "password-updated"]);
|
|
11
|
+
const isLoading = ref(false);
|
|
12
|
+
const isPasswordLoading = ref(false);
|
|
13
|
+
const error = ref("");
|
|
14
|
+
const passwordError = ref("");
|
|
15
|
+
const passwordSuccess = ref("");
|
|
16
|
+
const user = ref(null);
|
|
17
|
+
const passwordForm = ref({
|
|
18
|
+
currentPassword: "",
|
|
19
|
+
newPassword: "",
|
|
20
|
+
newPasswordConfirmation: ""
|
|
21
|
+
});
|
|
22
|
+
const { public: { nuxtUsers } } = useRuntimeConfig();
|
|
23
|
+
const moduleOptions = nuxtUsers;
|
|
24
|
+
const passwordValidation = usePasswordValidation(moduleOptions);
|
|
25
|
+
watch(() => passwordForm.value.newPassword, (newPassword) => {
|
|
26
|
+
if (newPassword) {
|
|
27
|
+
passwordValidation.validate(newPassword);
|
|
28
|
+
} else {
|
|
29
|
+
passwordValidation.clearValidation();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const loadProfile = async () => {
|
|
33
|
+
isLoading.value = true;
|
|
34
|
+
error.value = "";
|
|
35
|
+
try {
|
|
36
|
+
const response = await $fetch(props.apiEndpoint, {
|
|
37
|
+
method: "GET"
|
|
38
|
+
});
|
|
39
|
+
user.value = response.user;
|
|
40
|
+
emit("success", response.user);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
const errorMessage = err && typeof err === "object" && "data" in err && err.data && typeof err.data === "object" && "statusMessage" in err.data ? String(err.data.statusMessage) : err instanceof Error ? err.message : "Failed to load profile";
|
|
43
|
+
error.value = errorMessage;
|
|
44
|
+
emit("error", errorMessage);
|
|
45
|
+
} finally {
|
|
46
|
+
isLoading.value = false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const updatePassword = async () => {
|
|
50
|
+
isPasswordLoading.value = true;
|
|
51
|
+
passwordError.value = "";
|
|
52
|
+
passwordSuccess.value = "";
|
|
53
|
+
try {
|
|
54
|
+
await $fetch(props.updatePasswordEndpoint, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: passwordForm.value
|
|
57
|
+
});
|
|
58
|
+
passwordSuccess.value = "Password updated successfully";
|
|
59
|
+
emit("password-updated");
|
|
60
|
+
passwordForm.value = {
|
|
61
|
+
currentPassword: "",
|
|
62
|
+
newPassword: "",
|
|
63
|
+
newPasswordConfirmation: ""
|
|
64
|
+
};
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const errorMessage = err && typeof err === "object" && "data" in err && err.data && typeof err.data === "object" && "statusMessage" in err.data ? String(err.data.statusMessage) : err instanceof Error ? err.message : "Failed to update password";
|
|
67
|
+
passwordError.value = errorMessage;
|
|
68
|
+
emit("password-error", errorMessage);
|
|
69
|
+
} finally {
|
|
70
|
+
isPasswordLoading.value = false;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const formatDate = (dateString) => {
|
|
74
|
+
return new Date(dateString).toLocaleDateString("en-US", {
|
|
75
|
+
year: "numeric",
|
|
76
|
+
month: "long",
|
|
77
|
+
day: "numeric",
|
|
78
|
+
hour: "2-digit",
|
|
79
|
+
minute: "2-digit"
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
onMounted(() => {
|
|
83
|
+
loadProfile();
|
|
84
|
+
});
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<div class="profile-form">
|
|
89
|
+
<!-- Profile Information Section -->
|
|
90
|
+
<div class="profile-section">
|
|
91
|
+
<h2 class="section-title">
|
|
92
|
+
Profile Information
|
|
93
|
+
</h2>
|
|
94
|
+
|
|
95
|
+
<div
|
|
96
|
+
v-if="isLoading"
|
|
97
|
+
class="loading"
|
|
98
|
+
>
|
|
99
|
+
Loading profile...
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div
|
|
103
|
+
v-else-if="error"
|
|
104
|
+
class="error-message"
|
|
105
|
+
>
|
|
106
|
+
{{ error }}
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<div
|
|
110
|
+
v-else-if="user"
|
|
111
|
+
class="profile-info"
|
|
112
|
+
>
|
|
113
|
+
<div class="info-row">
|
|
114
|
+
<label class="info-label">Name:</label>
|
|
115
|
+
<span class="info-value">{{ user.name }}</span>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div class="info-row">
|
|
119
|
+
<label class="info-label">Email:</label>
|
|
120
|
+
<span class="info-value">{{ user.email }}</span>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<div class="info-row">
|
|
124
|
+
<label class="info-label">Role:</label>
|
|
125
|
+
<span class="info-value">{{ user.role }}</span>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div class="info-row">
|
|
129
|
+
<label class="info-label">Member since:</label>
|
|
130
|
+
<span class="info-value">{{ formatDate(user.created_at) }}</span>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<div class="info-row">
|
|
134
|
+
<label class="info-label">Last updated:</label>
|
|
135
|
+
<span class="info-value">{{ formatDate(user.updated_at) }}</span>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<!-- Change Password Section -->
|
|
141
|
+
<div class="password-section">
|
|
142
|
+
<h2 class="section-title">
|
|
143
|
+
Change Password
|
|
144
|
+
</h2>
|
|
145
|
+
|
|
146
|
+
<form
|
|
147
|
+
class="password-form"
|
|
148
|
+
@submit.prevent="updatePassword"
|
|
149
|
+
>
|
|
150
|
+
<div class="form-group">
|
|
151
|
+
<label
|
|
152
|
+
for="currentPassword"
|
|
153
|
+
class="form-label"
|
|
154
|
+
>Current Password</label>
|
|
155
|
+
<input
|
|
156
|
+
id="currentPassword"
|
|
157
|
+
v-model="passwordForm.currentPassword"
|
|
158
|
+
type="password"
|
|
159
|
+
class="form-input"
|
|
160
|
+
required
|
|
161
|
+
:disabled="isPasswordLoading"
|
|
162
|
+
>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<div class="form-group">
|
|
166
|
+
<label
|
|
167
|
+
for="newPassword"
|
|
168
|
+
class="form-label"
|
|
169
|
+
>New Password</label>
|
|
170
|
+
<input
|
|
171
|
+
id="newPassword"
|
|
172
|
+
v-model="passwordForm.newPassword"
|
|
173
|
+
type="password"
|
|
174
|
+
class="form-input"
|
|
175
|
+
required
|
|
176
|
+
:minlength="moduleOptions.passwordValidation?.minLength || 8"
|
|
177
|
+
:class="{ error: passwordValidation.errors.value.length > 0 && passwordForm.newPassword }"
|
|
178
|
+
:disabled="isPasswordLoading"
|
|
179
|
+
>
|
|
180
|
+
|
|
181
|
+
<PasswordStrengthIndicator
|
|
182
|
+
:password="passwordForm.newPassword"
|
|
183
|
+
:validation-result="passwordValidation.validationResult.value"
|
|
184
|
+
/>
|
|
185
|
+
|
|
186
|
+
<!-- Password requirements -->
|
|
187
|
+
<small class="form-help">
|
|
188
|
+
Password must contain at least {{ moduleOptions.passwordValidation?.minLength || 8 }} characters
|
|
189
|
+
<span v-if="moduleOptions.passwordValidation?.requireUppercase">, including uppercase letters</span>
|
|
190
|
+
<span v-if="moduleOptions.passwordValidation?.requireLowercase">, lowercase letters</span>
|
|
191
|
+
<span v-if="moduleOptions.passwordValidation?.requireNumbers">, numbers</span>
|
|
192
|
+
<span v-if="moduleOptions.passwordValidation?.requireSpecialChars">, and special characters</span>.
|
|
193
|
+
</small>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<div class="form-group">
|
|
197
|
+
<label
|
|
198
|
+
for="newPasswordConfirmation"
|
|
199
|
+
class="form-label"
|
|
200
|
+
>Confirm New Password</label>
|
|
201
|
+
<input
|
|
202
|
+
id="newPasswordConfirmation"
|
|
203
|
+
v-model="passwordForm.newPasswordConfirmation"
|
|
204
|
+
type="password"
|
|
205
|
+
class="form-input"
|
|
206
|
+
required
|
|
207
|
+
:disabled="isPasswordLoading"
|
|
208
|
+
>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<div
|
|
212
|
+
v-if="passwordError"
|
|
213
|
+
class="error-message"
|
|
214
|
+
>
|
|
215
|
+
{{ passwordError }}
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<div
|
|
219
|
+
v-if="passwordSuccess"
|
|
220
|
+
class="success-message"
|
|
221
|
+
>
|
|
222
|
+
{{ passwordSuccess }}
|
|
223
|
+
</div>
|
|
224
|
+
|
|
225
|
+
<button
|
|
226
|
+
type="submit"
|
|
227
|
+
class="btn btn-primary"
|
|
228
|
+
:disabled="isPasswordLoading"
|
|
229
|
+
>
|
|
230
|
+
<span v-if="isPasswordLoading">Updating...</span>
|
|
231
|
+
<span v-else>Update Password</span>
|
|
232
|
+
</button>
|
|
233
|
+
</form>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</template>
|
|
237
|
+
|
|
238
|
+
<style scoped>
|
|
239
|
+
.profile-form{margin:0 auto;max-width:600px;padding:20px}.password-section,.profile-section{background:#fff;border:1px solid #e2e8f0;border-radius:8px;margin-bottom:24px;padding:24px}.section-title{border-bottom:2px solid #e2e8f0;color:#1a202c;font-size:1.5rem;font-weight:600;margin:0 0 20px;padding-bottom:12px}.loading{color:#718096;font-style:italic;text-align:center}.profile-info{display:flex;flex-direction:column;gap:16px}.info-row{align-items:center;border-bottom:1px solid #f7fafc;display:flex;padding:12px 0}.info-row:last-child{border-bottom:none}.info-label{color:#4a5568;font-weight:600;margin-right:16px;min-width:120px}.info-value{color:#2d3748;flex:1}.password-form{gap:20px}.form-group,.password-form{display:flex;flex-direction:column}.form-group{gap:8px}.form-label{color:#4a5568;font-size:.875rem;font-weight:500}.form-input{border:1px solid #e2e8f0;border-radius:6px;font-size:1rem;padding:12px 16px;transition:border-color .2s,box-shadow .2s}.form-input:focus{border-color:#4299e1;box-shadow:0 0 0 3px rgba(66,153,225,.1);outline:none}.form-input:disabled{background-color:#f7fafc;cursor:not-allowed}.form-help{color:#718096;font-size:.75rem;margin-top:4px}.btn{align-self:flex-start;border:none;border-radius:6px;cursor:pointer;font-size:1rem;font-weight:500;padding:12px 24px;transition:background-color .2s,transform .1s}.btn:disabled{cursor:not-allowed;opacity:.6;transform:none}.btn-primary{background-color:#4299e1;color:#fff}.btn-primary:hover:not(:disabled){background-color:#3182ce;transform:translateY(-1px)}.error-message{background-color:#fed7d7;border:1px solid #feb2b2;border-radius:6px;color:#e53e3e;font-size:.875rem;padding:12px}.success-message{background-color:#f0fff4;border:1px solid #9ae6b4;border-radius:6px;color:#38a169;font-size:.875rem;padding:12px}
|
|
240
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { UserWithoutPassword } from '../../types.js';
|
|
2
|
+
interface ProfileFormProps {
|
|
3
|
+
apiEndpoint?: string;
|
|
4
|
+
updatePasswordEndpoint?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: import("vue").DefineComponent<ProfileFormProps, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
7
|
+
error: (error: string) => any;
|
|
8
|
+
success: (user: UserWithoutPassword) => any;
|
|
9
|
+
"password-error": (error: string) => any;
|
|
10
|
+
"password-updated": () => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<ProfileFormProps> & Readonly<{
|
|
12
|
+
onError?: ((error: string) => any) | undefined;
|
|
13
|
+
onSuccess?: ((user: UserWithoutPassword) => any) | undefined;
|
|
14
|
+
"onPassword-error"?: ((error: string) => any) | undefined;
|
|
15
|
+
"onPassword-updated"?: (() => any) | undefined;
|
|
16
|
+
}>, {
|
|
17
|
+
apiEndpoint: string;
|
|
18
|
+
updatePasswordEndpoint: string;
|
|
19
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
20
|
+
export default _default;
|