@forgewp/compiler 0.4.2 → 0.4.3
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/README.md +11 -3
- package/bin/add.js +15 -6
- package/bin/analyze.js +66 -1
- package/bin/cli.js +16 -12
- package/bin/fresh.js +1 -1
- package/bin/make-block.js +11 -0
- package/bin/make-island.js +11 -0
- package/bin/{make-template.js → make-loop.js} +24 -19
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +11 -0
- package/bin/make-sandbox.js +558 -0
- package/lib/adapters/html-adapter.js +8 -3
- package/lib/adapters/stub-adapter.js +6 -2
- package/lib/asset-loader.js +22 -0
- package/lib/blueprints.js +133 -1
- package/lib/functions-builder.js +929 -3
- package/lib/generate-theme.js +219 -23
- package/lib/hydration-scanner.js +69 -57
- package/lib/index.d.ts +38 -1
- package/lib/index.js +1 -1
- package/lib/load-config.js +98 -0
- package/lib/markup-processor.js +105 -0
- package/lib/page-config-plugin.js +40 -0
- package/lib/php-builders.js +4 -2
- package/lib/react-adapter.js +82 -23
- package/lib/render-theme.mts +97 -24
- package/lib/validate-export.js +49 -0
- package/package.json +2 -1
- package/templates/PresetsStyle.tsx +1 -1
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +133 -0
- package/templates/auth/components/login-form-wrapper.tsx +203 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +182 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +15 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +14 -0
- package/templates/auth/pages/LoginPage.tsx +14 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +14 -0
- package/templates/auth/pages/SignUpPage.tsx +14 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +14 -0
- package/templates/forgewp-config.ts +70 -3
- package/templates/mock-data.json +122 -433
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +34 -0
- package/templates/wordpress.tsx +1390 -1297
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWpUser, useWpAuth } from '@forgewp/auth';
|
|
3
|
+
import { LogOut, User, Mail, Shield, CheckCircle2, XCircle, Code, Key } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
export default function DashboardViewWrapper() {
|
|
6
|
+
const user = useWpUser();
|
|
7
|
+
const { logout, initializing } = useWpAuth();
|
|
8
|
+
const [showRawJson, setShowRawJson] = React.useState(false);
|
|
9
|
+
|
|
10
|
+
if (initializing || !user) {
|
|
11
|
+
return (
|
|
12
|
+
<div className='min-h-screen bg-[#fafafa] flex items-center justify-center font-sans'>
|
|
13
|
+
<div className='flex flex-col items-center gap-4'>
|
|
14
|
+
<div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
|
|
15
|
+
<p className='text-slate-500 font-mono text-sm'>
|
|
16
|
+
Loading your account...
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const capabilities = user.capabilities || [];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<main className='min-h-screen bg-[#fafafa] text-slate-900 font-sans py-12 px-6 flex items-center justify-center'>
|
|
27
|
+
<div className='w-full max-w-2xl bg-white border border-slate-200/80 shadow-xs p-8 sm:p-12 relative'>
|
|
28
|
+
|
|
29
|
+
{/* Header Profile Info */}
|
|
30
|
+
<div className='flex flex-col items-center text-center pb-8 border-b border-slate-100'>
|
|
31
|
+
<div className='relative mb-4'>
|
|
32
|
+
<img
|
|
33
|
+
src={user.avatarUrl || `https://picsum.photos/seed/${user.username}/150/150`}
|
|
34
|
+
alt={user.displayName}
|
|
35
|
+
className='w-24 h-24 rounded-full border-4 border-slate-100 object-cover shadow-xs'
|
|
36
|
+
/>
|
|
37
|
+
<div className='absolute bottom-0 right-0 bg-primary border-2 border-white p-1.5 rounded-full text-white shadow-md'>
|
|
38
|
+
<User className='w-3.5 h-3.5' />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
<h1 className='text-2xl font-heading font-black tracking-tight uppercase text-slate-900'>
|
|
42
|
+
{user.displayName}
|
|
43
|
+
</h1>
|
|
44
|
+
<p className='text-slate-400 font-mono text-xs mt-0.5'>
|
|
45
|
+
@{user.username}
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<div className='flex flex-wrap justify-center gap-1.5 mt-3'>
|
|
49
|
+
{user.roles.map((role) => (
|
|
50
|
+
<span
|
|
51
|
+
key={role}
|
|
52
|
+
className='bg-primary/5 text-primary border border-primary/10 text-[10px] font-mono font-bold uppercase tracking-wider px-2 py-0.5 rounded-sm'
|
|
53
|
+
>
|
|
54
|
+
{role}
|
|
55
|
+
</span>
|
|
56
|
+
))}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
{/* Detailed Account Grid */}
|
|
61
|
+
<div className='py-8 border-b border-slate-100 grid grid-cols-1 sm:grid-cols-2 gap-6'>
|
|
62
|
+
<div className='flex items-start gap-3'>
|
|
63
|
+
<Shield className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
64
|
+
<div>
|
|
65
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
66
|
+
User ID (WordPress)
|
|
67
|
+
</p>
|
|
68
|
+
<p className='text-sm font-mono text-slate-700 font-semibold mt-0.5'>
|
|
69
|
+
#{user.id}
|
|
70
|
+
</p>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<div className='flex items-start gap-3'>
|
|
75
|
+
<Mail className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
76
|
+
<div className='overflow-hidden'>
|
|
77
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
78
|
+
Email Address
|
|
79
|
+
</p>
|
|
80
|
+
<p className='text-sm font-semibold text-slate-700 truncate mt-0.5'>
|
|
81
|
+
{user.email}
|
|
82
|
+
</p>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div className='flex items-start gap-3'>
|
|
87
|
+
{user.emailVerified ? (
|
|
88
|
+
<CheckCircle2 className='w-4.5 h-4.5 text-emerald-500 shrink-0 mt-0.5' />
|
|
89
|
+
) : (
|
|
90
|
+
<XCircle className='w-4.5 h-4.5 text-amber-500 shrink-0 mt-0.5' />
|
|
91
|
+
)}
|
|
92
|
+
<div>
|
|
93
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
94
|
+
Verification Status
|
|
95
|
+
</p>
|
|
96
|
+
<p className={`text-sm font-semibold mt-0.5 ${user.emailVerified ? 'text-emerald-600' : 'text-amber-600'}`}>
|
|
97
|
+
{user.emailVerified ? 'Verified Account' : 'Unverified Account'}
|
|
98
|
+
</p>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div className='flex items-start gap-3'>
|
|
103
|
+
<Key className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
|
|
104
|
+
<div>
|
|
105
|
+
<p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
|
|
106
|
+
Session State
|
|
107
|
+
</p>
|
|
108
|
+
<p className='text-sm font-semibold text-slate-700 mt-0.5'>
|
|
109
|
+
Active
|
|
110
|
+
</p>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
{/* Capabilities Section */}
|
|
116
|
+
{capabilities.length > 0 && (
|
|
117
|
+
<div className='py-8 border-b border-slate-100'>
|
|
118
|
+
<h2 className='text-xs font-mono font-bold uppercase text-slate-400 tracking-wider mb-3'>
|
|
119
|
+
Granted Session Capabilities
|
|
120
|
+
</h2>
|
|
121
|
+
<div className='flex flex-wrap gap-1.5'>
|
|
122
|
+
{capabilities.map((cap) => (
|
|
123
|
+
<span
|
|
124
|
+
key={cap}
|
|
125
|
+
className='bg-slate-50 border border-slate-150 text-slate-600 font-mono text-[11px] px-2.5 py-1 rounded-sm'
|
|
126
|
+
>
|
|
127
|
+
{cap}
|
|
128
|
+
</span>
|
|
129
|
+
))}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
{/* Toggleable Raw User JSON explorer */}
|
|
135
|
+
<div className='py-8'>
|
|
136
|
+
<button
|
|
137
|
+
onClick={() => setShowRawJson(!showRawJson)}
|
|
138
|
+
className='flex items-center gap-2 text-slate-500 hover:text-slate-900 text-xs font-mono font-bold uppercase tracking-wider cursor-pointer'
|
|
139
|
+
>
|
|
140
|
+
<Code className='w-4 h-4' />
|
|
141
|
+
{showRawJson ? 'Hide Raw User Object' : 'Show Raw User Object'}
|
|
142
|
+
</button>
|
|
143
|
+
|
|
144
|
+
{showRawJson && (
|
|
145
|
+
<div className='mt-4 bg-slate-50 border border-slate-200 p-4 font-mono text-xs text-slate-600 overflow-x-auto max-h-60 rounded-none leading-relaxed'>
|
|
146
|
+
<pre>{JSON.stringify(user, null, 2)}</pre>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
{/* Footer actions */}
|
|
152
|
+
<div className='pt-6 border-t border-slate-100 flex flex-col sm:flex-row gap-4 items-center justify-between'>
|
|
153
|
+
<p className='text-[11px] text-slate-400 font-mono'>
|
|
154
|
+
Note: Avatars are fetched natively via Gravatar in production.
|
|
155
|
+
</p>
|
|
156
|
+
<button
|
|
157
|
+
onClick={() => logout()}
|
|
158
|
+
className='group inline-flex items-center justify-center bg-white text-slate-900 border border-slate-200 hover:bg-red-50 hover:text-red-600 hover:border-red-200 font-mono font-bold text-xs uppercase tracking-widest px-5 py-3 transition-all duration-200 rounded-none cursor-pointer w-full sm:w-auto'
|
|
159
|
+
>
|
|
160
|
+
<LogOut className='w-4 h-4 mr-2 group-hover:-translate-x-0.5 transition-transform' />
|
|
161
|
+
Log Out
|
|
162
|
+
</button>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
</div>
|
|
166
|
+
</main>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWpAuth } from '@forgewp/auth';
|
|
3
|
+
import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import {
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
CardFooter,
|
|
12
|
+
} from '@/components/ui/card';
|
|
13
|
+
import {
|
|
14
|
+
Field,
|
|
15
|
+
FieldGroup,
|
|
16
|
+
FieldLabel,
|
|
17
|
+
} from '@/components/ui/field';
|
|
18
|
+
import { Input } from '@/components/ui/input';
|
|
19
|
+
import { AlertTriangleIcon, ArrowLeftIcon } from 'lucide-react';
|
|
20
|
+
|
|
21
|
+
export default function ForgotPasswordFormWrapper() {
|
|
22
|
+
const { forgotPassword, error, initializing } = useWpAuth();
|
|
23
|
+
const [_, setLocation] = useLocation();
|
|
24
|
+
const [emailOrUsername, setEmailOrUsername] = React.useState('');
|
|
25
|
+
const loginUrl = useWpPageLink('login-page', '/login');
|
|
26
|
+
const [success, setSuccess] = React.useState(false);
|
|
27
|
+
const [localError, setLocalError] = React.useState<string | null>(null);
|
|
28
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
29
|
+
|
|
30
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
setLocalError(null);
|
|
33
|
+
const input = emailOrUsername.trim();
|
|
34
|
+
if (!input) {
|
|
35
|
+
setLocalError('Please enter your username or email address.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setSubmitting(true);
|
|
40
|
+
try {
|
|
41
|
+
const ok = await forgotPassword(input);
|
|
42
|
+
if (ok) {
|
|
43
|
+
setSuccess(true);
|
|
44
|
+
}
|
|
45
|
+
} catch (err: any) {
|
|
46
|
+
setLocalError(err.message || 'An unexpected error occurred.');
|
|
47
|
+
} finally {
|
|
48
|
+
setSubmitting(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (initializing) {
|
|
53
|
+
return (
|
|
54
|
+
<div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
|
|
55
|
+
<div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
|
|
56
|
+
<p className='text-slate-500 font-mono text-sm mt-4'>
|
|
57
|
+
Checking session...
|
|
58
|
+
</p>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Card>
|
|
65
|
+
<CardHeader>
|
|
66
|
+
<CardTitle>{success ? 'Check Your Email' : 'Forgot Password?'}</CardTitle>
|
|
67
|
+
<CardDescription>
|
|
68
|
+
{success
|
|
69
|
+
? "If the account exists, we have sent a reset password link."
|
|
70
|
+
: "Enter your username or email address below and we'll send you a link to reset your password."}
|
|
71
|
+
</CardDescription>
|
|
72
|
+
</CardHeader>
|
|
73
|
+
|
|
74
|
+
<CardContent className="px-8 py-4">
|
|
75
|
+
{success ? (
|
|
76
|
+
<div className="text-zinc-600 text-sm leading-relaxed text-center">
|
|
77
|
+
<p className="mb-4">
|
|
78
|
+
We have sent instructions to reset your password.
|
|
79
|
+
</p>
|
|
80
|
+
<div className="bg-zinc-50 border border-zinc-100 rounded-lg p-3 text-xs text-zinc-500 text-left font-mono mb-4">
|
|
81
|
+
<strong>Dev Notice:</strong> Look for the simulated email in <code className="bg-zinc-200 px-1 rounded">cms/email-logs.json</code> to click the recovery link.
|
|
82
|
+
</div>
|
|
83
|
+
<button
|
|
84
|
+
onClick={() => setSuccess(false)}
|
|
85
|
+
className="text-primary hover:underline text-sm font-medium cursor-pointer"
|
|
86
|
+
>
|
|
87
|
+
Didn't receive the email? Try again
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
90
|
+
) : (
|
|
91
|
+
<form onSubmit={handleSubmit}>
|
|
92
|
+
<FieldGroup>
|
|
93
|
+
{(localError || error) && (
|
|
94
|
+
<div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex items-start gap-2">
|
|
95
|
+
<AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
|
|
96
|
+
<span>{localError || error}</span>
|
|
97
|
+
</div>
|
|
98
|
+
)}
|
|
99
|
+
<Field>
|
|
100
|
+
<FieldLabel htmlFor="emailOrUsername">Username or Email Address</FieldLabel>
|
|
101
|
+
<Input
|
|
102
|
+
id="emailOrUsername"
|
|
103
|
+
type="text"
|
|
104
|
+
placeholder="Enter username or email"
|
|
105
|
+
value={emailOrUsername}
|
|
106
|
+
onChange={(e) => setEmailOrUsername(e.target.value)}
|
|
107
|
+
disabled={submitting}
|
|
108
|
+
required
|
|
109
|
+
/>
|
|
110
|
+
</Field>
|
|
111
|
+
<Field>
|
|
112
|
+
<Button type="submit" disabled={submitting} className="w-full cursor-pointer">
|
|
113
|
+
{submitting ? 'Sending link...' : 'Send Reset Link'}
|
|
114
|
+
</Button>
|
|
115
|
+
</Field>
|
|
116
|
+
</FieldGroup>
|
|
117
|
+
</form>
|
|
118
|
+
)}
|
|
119
|
+
</CardContent>
|
|
120
|
+
|
|
121
|
+
<CardFooter className="px-8 pb-8 pt-4 flex flex-col gap-2">
|
|
122
|
+
<Button
|
|
123
|
+
variant="outline"
|
|
124
|
+
className="w-full cursor-pointer hover:bg-zinc-50 border-zinc-200 flex items-center justify-center gap-2"
|
|
125
|
+
onClick={() => setLocation(loginUrl)}
|
|
126
|
+
>
|
|
127
|
+
<ArrowLeftIcon className="h-4 w-4" />
|
|
128
|
+
Return to Sign In
|
|
129
|
+
</Button>
|
|
130
|
+
</CardFooter>
|
|
131
|
+
</Card>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWpAuth, useWpUser } from '@forgewp/auth';
|
|
3
|
+
import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle,
|
|
12
|
+
} from '@/components/ui/card';
|
|
13
|
+
import {
|
|
14
|
+
Field,
|
|
15
|
+
FieldGroup,
|
|
16
|
+
FieldLabel,
|
|
17
|
+
FieldDescription,
|
|
18
|
+
} from '@/components/ui/field';
|
|
19
|
+
import { Input } from '@/components/ui/input';
|
|
20
|
+
import { AlertTriangleIcon } from 'lucide-react';
|
|
21
|
+
|
|
22
|
+
export default function LoginFormWrapper({
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: React.ComponentProps<'div'>) {
|
|
26
|
+
const { login, error, loginField, initializing, resendVerificationEmail } = useWpAuth();
|
|
27
|
+
const user = useWpUser();
|
|
28
|
+
const [_, setLocation] = useLocation();
|
|
29
|
+
|
|
30
|
+
const [username, setUsername] = React.useState('');
|
|
31
|
+
const [password, setPassword] = React.useState('');
|
|
32
|
+
const [localError, setLocalError] = React.useState<string | null>(null);
|
|
33
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
34
|
+
|
|
35
|
+
const [resendStatus, setResendStatus] = React.useState<'idle' | 'sending' | 'success' | 'failed'>('idle');
|
|
36
|
+
const [resendErrorMessage, setResendErrorMessage] = React.useState<string | null>(null);
|
|
37
|
+
|
|
38
|
+
const forgotPasswordUrl = useWpPageLink('forgot-password-page', '/forgot-password');
|
|
39
|
+
const signUpUrl = useWpPageLink('sign-up-page', '/signup');
|
|
40
|
+
const dashboardUrl = useWpPageLink('dashboard-page', '/dashboard');
|
|
41
|
+
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (user) {
|
|
44
|
+
setLocation(dashboardUrl);
|
|
45
|
+
}
|
|
46
|
+
}, [user, setLocation, dashboardUrl]);
|
|
47
|
+
|
|
48
|
+
const handleResendVerification = async () => {
|
|
49
|
+
const input = username.trim();
|
|
50
|
+
if (!input) {
|
|
51
|
+
setResendErrorMessage('Please enter your username or email in the login field first.');
|
|
52
|
+
setResendStatus('failed');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setResendStatus('sending');
|
|
57
|
+
setResendErrorMessage(null);
|
|
58
|
+
try {
|
|
59
|
+
const ok = await resendVerificationEmail(input);
|
|
60
|
+
if (ok) {
|
|
61
|
+
setResendStatus('success');
|
|
62
|
+
} else {
|
|
63
|
+
setResendStatus('failed');
|
|
64
|
+
setResendErrorMessage(error || 'Failed to resend verification email.');
|
|
65
|
+
}
|
|
66
|
+
} catch (err: any) {
|
|
67
|
+
setResendStatus('failed');
|
|
68
|
+
setResendErrorMessage(err.message || 'An unexpected error occurred.');
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
setLocalError(null);
|
|
75
|
+
setResendStatus('idle');
|
|
76
|
+
setResendErrorMessage(null);
|
|
77
|
+
|
|
78
|
+
const trimmedUsername = username.trim();
|
|
79
|
+
const trimmedPassword = password.trim();
|
|
80
|
+
|
|
81
|
+
if (!trimmedUsername || !trimmedPassword) {
|
|
82
|
+
setLocalError('Please enter both username/email and password.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setSubmitting(true);
|
|
87
|
+
try {
|
|
88
|
+
await login(trimmedUsername, trimmedPassword, dashboardUrl);
|
|
89
|
+
} catch (err: any) {
|
|
90
|
+
setLocalError(err.message || 'Login failed. Please try again.');
|
|
91
|
+
} finally {
|
|
92
|
+
setSubmitting(false);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (initializing || user) {
|
|
97
|
+
return (
|
|
98
|
+
<div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
|
|
99
|
+
<div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
|
|
100
|
+
<p className='text-slate-500 font-mono text-sm mt-4'>
|
|
101
|
+
Checking session...
|
|
102
|
+
</p>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div
|
|
109
|
+
className={cn('flex flex-col gap-6', className)}
|
|
110
|
+
{...props}
|
|
111
|
+
>
|
|
112
|
+
<Card>
|
|
113
|
+
<CardHeader>
|
|
114
|
+
<CardTitle>Login to your account</CardTitle>
|
|
115
|
+
<CardDescription>
|
|
116
|
+
Enter your username or email below to login to your account
|
|
117
|
+
</CardDescription>
|
|
118
|
+
</CardHeader>
|
|
119
|
+
<CardContent>
|
|
120
|
+
<form onSubmit={handleSubmit}>
|
|
121
|
+
<FieldGroup>
|
|
122
|
+
{(localError || error) && (
|
|
123
|
+
<div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex flex-col gap-2">
|
|
124
|
+
<div className="flex items-start gap-2">
|
|
125
|
+
<AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
|
|
126
|
+
<span>{localError || error}</span>
|
|
127
|
+
</div>
|
|
128
|
+
{((localError || error) as string).includes('not been verified yet') && (
|
|
129
|
+
<div className="mt-1 pt-2 border-t border-red-100 flex flex-col gap-2">
|
|
130
|
+
{resendStatus === 'success' ? (
|
|
131
|
+
<span className="text-green-600 text-xs font-semibold">
|
|
132
|
+
Verification email successfully resent!
|
|
133
|
+
</span>
|
|
134
|
+
) : (
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
disabled={resendStatus === 'sending'}
|
|
138
|
+
onClick={handleResendVerification}
|
|
139
|
+
className="text-red-700 hover:underline text-xs font-semibold text-left cursor-pointer disabled:opacity-50"
|
|
140
|
+
>
|
|
141
|
+
{resendStatus === 'sending' ? 'Resending...' : "Didn't get the email? Click here to resend."}
|
|
142
|
+
</button>
|
|
143
|
+
)}
|
|
144
|
+
{resendStatus === 'failed' && resendErrorMessage && (
|
|
145
|
+
<span className="text-red-500 text-xs font-normal">
|
|
146
|
+
{resendErrorMessage}
|
|
147
|
+
</span>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
<Field>
|
|
154
|
+
<FieldLabel htmlFor='username'>
|
|
155
|
+
{loginField === 'usernameOnly' ? 'Username' : loginField === 'emailOnly' ? 'Email Address' : 'Username or Email'}
|
|
156
|
+
</FieldLabel>
|
|
157
|
+
<Input
|
|
158
|
+
id='username'
|
|
159
|
+
type='text'
|
|
160
|
+
placeholder={loginField === 'usernameOnly' ? 'username' : loginField === 'emailOnly' ? 'user@example.com' : 'admin / subscriber'}
|
|
161
|
+
value={username}
|
|
162
|
+
onChange={(e) => setUsername(e.target.value)}
|
|
163
|
+
disabled={submitting}
|
|
164
|
+
required
|
|
165
|
+
autoComplete="username"
|
|
166
|
+
/>
|
|
167
|
+
</Field>
|
|
168
|
+
<Field>
|
|
169
|
+
<div className='flex items-center'>
|
|
170
|
+
<FieldLabel htmlFor='password'>Password</FieldLabel>
|
|
171
|
+
<a
|
|
172
|
+
href={forgotPasswordUrl}
|
|
173
|
+
className='ml-auto inline-block text-sm underline-offset-4 hover:underline'
|
|
174
|
+
>
|
|
175
|
+
Forgot your password?
|
|
176
|
+
</a>
|
|
177
|
+
</div>
|
|
178
|
+
<Input
|
|
179
|
+
id='password'
|
|
180
|
+
type='password'
|
|
181
|
+
placeholder='••••••••'
|
|
182
|
+
value={password}
|
|
183
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
184
|
+
disabled={submitting}
|
|
185
|
+
required
|
|
186
|
+
autoComplete="current-password"
|
|
187
|
+
/>
|
|
188
|
+
</Field>
|
|
189
|
+
<Field>
|
|
190
|
+
<Button type='submit' disabled={submitting} className="w-full cursor-pointer">
|
|
191
|
+
{submitting ? 'Logging in...' : 'Login'}
|
|
192
|
+
</Button>
|
|
193
|
+
<FieldDescription className='text-center'>
|
|
194
|
+
Don't have an account? <a href={signUpUrl} className="underline">Sign up</a>
|
|
195
|
+
</FieldDescription>
|
|
196
|
+
</Field>
|
|
197
|
+
</FieldGroup>
|
|
198
|
+
</form>
|
|
199
|
+
</CardContent>
|
|
200
|
+
</Card>
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useWpAuth } from '@forgewp/auth';
|
|
3
|
+
import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import {
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
CardFooter,
|
|
12
|
+
} from '@/components/ui/card';
|
|
13
|
+
import {
|
|
14
|
+
Field,
|
|
15
|
+
FieldGroup,
|
|
16
|
+
FieldLabel,
|
|
17
|
+
} from '@/components/ui/field';
|
|
18
|
+
import { Input } from '@/components/ui/input';
|
|
19
|
+
import { AlertTriangleIcon, ArrowLeftIcon } from 'lucide-react';
|
|
20
|
+
|
|
21
|
+
export default function ResetPasswordFormWrapper() {
|
|
22
|
+
const { resetPassword, error, initializing } = useWpAuth();
|
|
23
|
+
const [_, setLocation] = useLocation();
|
|
24
|
+
const loginUrl = useWpPageLink('login-page', '/login');
|
|
25
|
+
|
|
26
|
+
const [key, setKey] = React.useState('');
|
|
27
|
+
const [login, setLogin] = React.useState('');
|
|
28
|
+
const [password, setPassword] = React.useState('');
|
|
29
|
+
const [confirmPassword, setConfirmPassword] = React.useState('');
|
|
30
|
+
const [success, setSuccess] = React.useState(false);
|
|
31
|
+
const [localError, setLocalError] = React.useState<string | null>(null);
|
|
32
|
+
const [missingParams, setMissingParams] = React.useState(false);
|
|
33
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
37
|
+
const keyParam = searchParams.get('key');
|
|
38
|
+
const loginParam = searchParams.get('login');
|
|
39
|
+
|
|
40
|
+
if (!keyParam || !loginParam) {
|
|
41
|
+
setMissingParams(true);
|
|
42
|
+
} else {
|
|
43
|
+
setKey(keyParam);
|
|
44
|
+
setLogin(loginParam);
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
setLocalError(null);
|
|
51
|
+
|
|
52
|
+
const trimmedPassword = password.trim();
|
|
53
|
+
const trimmedConfirmPassword = confirmPassword.trim();
|
|
54
|
+
|
|
55
|
+
if (!trimmedPassword) {
|
|
56
|
+
setLocalError('Please enter a new password.');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (trimmedPassword !== trimmedConfirmPassword) {
|
|
61
|
+
setLocalError('Passwords do not match.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (trimmedPassword.length < 6) {
|
|
66
|
+
setLocalError('Password must be at least 6 characters long.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setSubmitting(true);
|
|
71
|
+
try {
|
|
72
|
+
const ok = await resetPassword(login, key, trimmedPassword);
|
|
73
|
+
if (ok) {
|
|
74
|
+
setSuccess(true);
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
setLocation(loginUrl);
|
|
77
|
+
}, 3000);
|
|
78
|
+
}
|
|
79
|
+
} catch (err: any) {
|
|
80
|
+
setLocalError(err.message || 'An unexpected error occurred.');
|
|
81
|
+
} finally {
|
|
82
|
+
setSubmitting(false);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (initializing) {
|
|
87
|
+
return (
|
|
88
|
+
<div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
|
|
89
|
+
<div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
|
|
90
|
+
<p className='text-slate-500 font-mono text-sm mt-4'>
|
|
91
|
+
Checking session...
|
|
92
|
+
</p>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Card>
|
|
99
|
+
<CardHeader>
|
|
100
|
+
<CardTitle>
|
|
101
|
+
{success
|
|
102
|
+
? 'Password Reset Complete'
|
|
103
|
+
: missingParams
|
|
104
|
+
? 'Invalid Reset Link'
|
|
105
|
+
: 'Reset Your Password'}
|
|
106
|
+
</CardTitle>
|
|
107
|
+
<CardDescription>
|
|
108
|
+
{success
|
|
109
|
+
? 'Your password has been successfully updated.'
|
|
110
|
+
: missingParams
|
|
111
|
+
? 'This password reset link is invalid or incomplete.'
|
|
112
|
+
: `Choose a new secure password for ${login}.`}
|
|
113
|
+
</CardDescription>
|
|
114
|
+
</CardHeader>
|
|
115
|
+
|
|
116
|
+
<CardContent className="px-8 py-4">
|
|
117
|
+
{success ? (
|
|
118
|
+
<p className="text-green-600 font-medium text-center text-sm leading-relaxed">
|
|
119
|
+
Redirecting you to the sign in page in 3 seconds...
|
|
120
|
+
</p>
|
|
121
|
+
) : missingParams ? (
|
|
122
|
+
<div className="text-zinc-600 text-sm leading-relaxed text-center">
|
|
123
|
+
<p className="mb-4">
|
|
124
|
+
The password reset link is missing required verification parameters. Please request a new link.
|
|
125
|
+
</p>
|
|
126
|
+
</div>
|
|
127
|
+
) : (
|
|
128
|
+
<form onSubmit={handleSubmit}>
|
|
129
|
+
<FieldGroup>
|
|
130
|
+
{(localError || error) && (
|
|
131
|
+
<div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex items-start gap-2">
|
|
132
|
+
<AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
|
|
133
|
+
<span>{localError || error}</span>
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
<Field>
|
|
137
|
+
<FieldLabel htmlFor="password">New Password</FieldLabel>
|
|
138
|
+
<Input
|
|
139
|
+
id="password"
|
|
140
|
+
type="password"
|
|
141
|
+
placeholder="••••••••"
|
|
142
|
+
value={password}
|
|
143
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
144
|
+
disabled={submitting}
|
|
145
|
+
required
|
|
146
|
+
/>
|
|
147
|
+
</Field>
|
|
148
|
+
<Field>
|
|
149
|
+
<FieldLabel htmlFor="confirmPassword">Confirm Password</FieldLabel>
|
|
150
|
+
<Input
|
|
151
|
+
id="confirmPassword"
|
|
152
|
+
type="password"
|
|
153
|
+
placeholder="••••••••"
|
|
154
|
+
value={confirmPassword}
|
|
155
|
+
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
156
|
+
disabled={submitting}
|
|
157
|
+
required
|
|
158
|
+
/>
|
|
159
|
+
</Field>
|
|
160
|
+
<Field>
|
|
161
|
+
<Button type="submit" disabled={submitting} className="w-full cursor-pointer">
|
|
162
|
+
{submitting ? 'Resetting password...' : 'Update Password'}
|
|
163
|
+
</Button>
|
|
164
|
+
</Field>
|
|
165
|
+
</FieldGroup>
|
|
166
|
+
</form>
|
|
167
|
+
)}
|
|
168
|
+
</CardContent>
|
|
169
|
+
|
|
170
|
+
<CardFooter className="px-8 pb-8 pt-4 flex flex-col gap-2">
|
|
171
|
+
<Button
|
|
172
|
+
variant="outline"
|
|
173
|
+
className="w-full cursor-pointer hover:bg-zinc-50 border-zinc-200 flex items-center justify-center gap-2"
|
|
174
|
+
onClick={() => setLocation(loginUrl)}
|
|
175
|
+
>
|
|
176
|
+
<ArrowLeftIcon className="h-4 w-4" />
|
|
177
|
+
Return to Sign In
|
|
178
|
+
</Button>
|
|
179
|
+
</CardFooter>
|
|
180
|
+
</Card>
|
|
181
|
+
);
|
|
182
|
+
}
|