1+ <template >
2+ <div class =" relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800 relative w-screen h-screen"
3+ :style =" coreStore.config?.loginBackgroundImage && backgroundPosition === 'over' ? {
4+ 'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
5+ 'background-size': 'cover',
6+ 'background-position': 'center',
7+ 'background-blend-mode': 'darken'
8+ }: {}"
9+ >
10+
11+ <img v-if =" coreStore.config?.loginBackgroundImage && backgroundPosition !== 'over'"
12+ :src =" loadFile(coreStore.config?.loginBackgroundImage)"
13+ class =" position-absolute top-0 left-0 h-screen object-cover w-0"
14+ :class =" {
15+ '1/2': 'md:w-1/2',
16+ '1/3': 'md:w-1/3',
17+ '2/3': 'md:w-2/3',
18+ '3/4': 'md:w-3/4',
19+ '2/5': 'md:w-2/5',
20+ '3/5': 'md:w-3/5',
21+ }[backgroundPosition]"
22+ />
23+
24+ <!-- Main modal -->
25+ <div id =" authentication-modal" tabindex =" -1"
26+ class =" overflow-y-auto flex flex-grow
27+ overflow-x-hidden z-50 min-w-[350px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full" >
28+ <div class =" relative p-4 w-full max-h-full max-w-[400px]" >
29+ <!-- Modal content -->
30+ <div class =" relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black" >
31+ <!-- Modal header -->
32+ <div class =" flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600" >
33+ <h3 class =" text-xl font-semibold text-gray-900 dark:text-white" >
34+ {{$t('Set your password for')}} {{ coreStore.config?.brandName }}
35+ </h3 >
36+ </div >
37+ <!-- Modal body -->
38+ <div class =" p-4 md:p-5" >
39+ <!-- Success message -->
40+ <div v-if =" passwordSet" class =" flex items-center justify-center p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-50 dark:bg-green-800 dark:text-green-400" role =" alert" >
41+ <div class =" text-center" >
42+ <p class =" mb-3" >{{$t('Password set successfully!')}}</p >
43+ <Link to =" /login" class =" inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-blue-600 border border-transparent rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500" >
44+ {{$t('Go to Login')}}
45+ </Link >
46+ </div >
47+ </div >
48+
49+ <!-- Set password form -->
50+ <form v-if =" !passwordSet && tokenValid" class =" space-y-4" role =" alert" @submit.prevent >
51+ <div class =" relative" >
52+ <label for =" password" class =" block mb-2 text-sm font-medium text-gray-900 dark:text-white" >{{$t('Password')}}</label >
53+ <input
54+ :type =" unmasked ? 'text' : 'password'"
55+ name =" password" id =" password"
56+ autocomplete =" new-password"
57+ v-model =" password"
58+ @keydown.enter =" passwordConfirmationInput?.focus()"
59+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white"
60+ :placeholder =" $t('Enter your password')" required
61+ />
62+
63+ <button
64+ type =" button"
65+ @click =" unmasked = !unmasked"
66+ class =" h-6 absolute inset-y-2 top-9 right-1 flex items-center pr-2 z-index-100 focus:outline-none"
67+ >
68+ <IconEyeSolid class =" w-6 h-6 text-gray-400" v-if =" !unmasked" />
69+ <IconEyeSlashSolid class =" w-6 h-6 text-gray-400" v-else />
70+ </button >
71+ </div >
72+
73+ <div class =" relative" >
74+ <label for =" password_confirmation" class =" block mb-2 text-sm font-medium text-gray-900 dark:text-white" >{{$t('Confirm password')}}</label >
75+ <input
76+ :type =" unmasked ? 'text' : 'password'"
77+ name =" password_confirmation" id =" password_confirmation"
78+ autocomplete =" new-password"
79+ v-model =" passwordConfirmation"
80+ ref =" passwordConfirmationInput"
81+ @keydown.enter =" setPassword"
82+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white"
83+ :placeholder =" $t('Confirm your password')" required
84+ />
85+
86+ <button
87+ type =" button"
88+ @click =" unmasked = !unmasked"
89+ class =" h-6 absolute inset-y-2 top-9 right-1 flex items-center pr-2 z-index-100 focus:outline-none"
90+ >
91+ <IconEyeSolid class =" w-6 h-6 text-gray-400" v-if =" !unmasked" />
92+ <IconEyeSlashSolid class =" w-6 h-6 text-gray-400" v-else />
93+ </button >
94+ </div >
95+
96+ <div v-if =" validationError || error" class =" flex items-center p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400" role =" alert" >
97+ <svg class =" flex-shrink-0 inline w-4 h-4 me-3" aria-hidden =" true" xmlns =" http://www.w3.org/2000/svg" fill =" currentColor" viewBox =" 0 0 20 20" >
98+ <path d =" M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z" />
99+ </svg >
100+ <span class =" sr-only" >{{$t('Info')}}</span >
101+ <div >
102+ {{ validationError || error }}
103+ </div >
104+ </div >
105+
106+ <Button
107+ :disabled =" inProgress || (validationRunning && validationError)"
108+ @click =" setPassword"
109+ class =" w-full" >
110+ <svg v-if =" inProgress"
111+ aria-hidden =" true" class =" w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox =" 0 0 100 101" fill =" none" xmlns =" http://www.w3.org/2000/svg" >
112+ <path d =" M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill =" currentColor" />
113+ <path d =" M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill =" currentFill" />
114+ </svg >
115+ {{$t('Set Password')}}
116+ </Button >
117+ </form >
118+
119+ <!-- Invalid token message -->
120+ <div v-if =" !tokenValid && !loading" class =" flex items-center p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400" role =" alert" >
121+ <svg class =" flex-shrink-0 inline w-4 h-4 me-3" aria-hidden =" true" xmlns =" http://www.w3.org/2000/svg" fill =" currentColor" viewBox =" 0 0 20 20" >
122+ <path d =" M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z" />
123+ </svg >
124+ <span class =" sr-only" >{{$t('Info')}}</span >
125+ <div >
126+ <p class =" mb-2" >{{$t('This invitation link is invalid or has expired.')}}</p >
127+ <Link to =" /login" >{{$t('Go to Login')}}</Link >
128+ </div >
129+ </div >
130+
131+ <!-- Loading state -->
132+ <div v-if =" loading" class =" flex items-center justify-center p-8" >
133+ <svg aria-hidden =" true" class =" w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox =" 0 0 100 101" fill =" none" xmlns =" http://www.w3.org/2000/svg" >
134+ <path d =" M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill =" currentColor" />
135+ <path d =" M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill =" currentFill" />
136+ </svg >
137+ </div >
138+ </div >
139+ </div >
140+ </div >
141+ </div >
142+
143+ </div >
144+ </template >
145+
146+ <script setup lang="ts">
147+ import { onMounted , ref , computed , Ref } from ' vue' ;
148+ import { useCoreStore } from ' @/stores/core' ;
149+ import { callAdminForthApi , loadFile , applyRegexValidation } from ' @/utils' ;
150+ import { useRoute , useRouter } from ' vue-router' ;
151+ import { IconEyeSolid , IconEyeSlashSolid } from ' @iconify-prerendered/vue-flowbite' ;
152+ import Button from ' @/afcl/Button.vue' ;
153+ import Link from ' @/afcl/Link.vue' ;
154+
155+ const inProgress = ref (false );
156+ const loading = ref (true );
157+ const tokenValid = ref (false );
158+ const passwordSet = ref (false );
159+
160+ const coreStore = useCoreStore ();
161+
162+ const passwordConfirmationInput = ref (null );
163+ const password = ref (" " );
164+ const passwordConfirmation = ref (" " );
165+ const unmasked = ref (false );
166+
167+ const route = useRoute ();
168+ const router = useRouter ();
169+
170+ const validationRunning = ref (false );
171+ const error = ref (null );
172+
173+ const backgroundPosition = computed (() => {
174+ return coreStore .config ?.loginBackgroundPosition || ' 1/2' ;
175+ });
176+
177+ function checkPassword() {
178+ if (! password .value || ! passwordConfirmation .value ) {
179+ return ' Please enter both password and password confirmation' ;
180+ }
181+ if (password .value !== passwordConfirmation .value ) {
182+ return ' Passwords do not match' ;
183+ }
184+
185+ // Basic password validation
186+ if (password .value .length < 8 ) {
187+ return ' Password must be at least 8 characters long' ;
188+ }
189+
190+ return null ;
191+ }
192+
193+ const validationError = computed (() => {
194+ if (validationRunning .value ) {
195+ return checkPassword ();
196+ }
197+ return null ;
198+ });
199+
200+ onMounted (async () => {
201+ loading .value = true ;
202+ await coreStore .getPublicConfig ();
203+
204+ // Check if token is present and valid
205+ const token = route .query .token ;
206+ if (token ) {
207+ tokenValid .value = true ;
208+ } else {
209+ tokenValid .value = false ;
210+ }
211+
212+ loading .value = false ;
213+ });
214+
215+ async function setPassword() {
216+ error .value = null ;
217+
218+ if (checkPassword ()) {
219+ validationRunning .value = true ;
220+ return ;
221+ } else {
222+ validationRunning .value = false ;
223+ }
224+
225+ inProgress .value = true ;
226+ const resp = await callAdminForthApi ({
227+ path: ` /plugin/${route .meta .pluginInstanceId }/set-password ` ,
228+ method: ' POST' ,
229+ body: {
230+ token: route .query .token ,
231+ password: password .value ,
232+ }
233+ });
234+ inProgress .value = false ;
235+
236+ if (resp .error ) {
237+ error .value = resp .error ;
238+ if (resp .error .includes (' Invalid' ) || resp .error .includes (' expired' )) {
239+ tokenValid .value = false ;
240+ }
241+ } else {
242+ error .value = null ;
243+ passwordSet .value = true ;
244+ }
245+ }
246+ </script >
0 commit comments