|
45 | 45 | let status = ''; |
46 | 46 | let isSubmitting = false; |
47 | 47 | let isRememberMe = false; |
| 48 | +
|
48 | 49 | onMount(() => { |
49 | 50 | const userName = localStorage.getItem('user_name'); |
50 | 51 | isRememberMe = userName !== null; |
|
69 | 70 | msg = 'Authentication success'; |
70 | 71 | status = 'success'; |
71 | 72 | const redirectUrl = $page.url.searchParams.get('redirect'); |
| 73 | + isSubmitting = false; |
| 74 | + resetStorage(); |
72 | 75 | if (redirectUrl) { |
73 | 76 | window.location.href = decodeURIComponent(redirectUrl); |
74 | 77 | } else { |
75 | 78 | goto('page/dashboard'); |
76 | 79 | } |
| 80 | + }, () => { |
77 | 81 | isSubmitting = false; |
78 | | - resetStorage(); |
| 82 | + isOpen = true; |
| 83 | + status = 'danger'; |
| 84 | + msg = 'Incorrect user name or password.' |
| 85 | + setTimeout(() => { |
| 86 | + isOpen = false; |
| 87 | + status = ''; |
| 88 | + msg = ''; |
| 89 | + }, 3000); |
79 | 90 | }); |
80 | 91 | isSubmitting = false; |
81 | 92 | } |
82 | 93 |
|
83 | 94 | function onPasswordToggle() { |
84 | 95 | var x = document.getElementById('user-password'); |
| 96 | + if (!x) return; |
| 97 | +
|
85 | 98 | if (x.type === 'password') { |
86 | 99 | x.type = 'text'; |
87 | 100 | var icon = document.getElementById('password-eye-icon'); |
|
147 | 160 | class="form-control" |
148 | 161 | id="username" |
149 | 162 | placeholder="Enter username" |
| 163 | + disabled={isSubmitting} |
150 | 164 | bind:value={username} |
151 | 165 | /> |
152 | 166 | </div> |
|
159 | 173 | class="form-control" |
160 | 174 | id="user-password" |
161 | 175 | placeholder="Enter password" |
| 176 | + disabled={isSubmitting} |
162 | 177 | aria-label="Password" |
163 | 178 | aria-describedby="password-addon" |
164 | 179 | bind:value={password} |
|
167 | 182 | color="light" |
168 | 183 | type="button" |
169 | 184 | id="password-addon" |
| 185 | + disabled={isSubmitting} |
170 | 186 | on:click={() => onPasswordToggle()} |
171 | 187 | > |
172 | 188 | <i id="password-eye-icon" class="mdi mdi-eye-outline" /> |
|
179 | 195 | class="form-check-input" |
180 | 196 | type="checkbox" |
181 | 197 | id="remember-check" |
| 198 | + disabled={isSubmitting} |
182 | 199 | bind:checked={isRememberMe} |
183 | 200 | /> |
184 | 201 | <Label class="form-check-label" for="remember-check">Remember me</Label> |
|
200 | 217 |
|
201 | 218 | <ul class="list-inline"> |
202 | 219 | <li class="list-inline-item"> |
203 | | - <a href="{PUBLIC_SERVICE_URL}/sso/GitHub?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" class="social-list-item bg-primary text-white border-primary"> |
| 220 | + <Link |
| 221 | + class="social-list-item bg-primary text-white border-primary" |
| 222 | + href="{PUBLIC_SERVICE_URL}/sso/GitHub?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" |
| 223 | + disabled={isSubmitting} |
| 224 | + > |
204 | 225 | <i class="mdi mdi-github" /> |
205 | | - </a> |
| 226 | + </Link> |
206 | 227 | </li> |
207 | 228 | <li class="list-inline-item"> |
208 | | - <a href="{PUBLIC_SERVICE_URL}/sso/Keycloak?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" class="social-list-item bg-primary text-white border-primary"> |
| 229 | + <Link |
| 230 | + class="social-list-item bg-primary text-white border-primary" |
| 231 | + href="{PUBLIC_SERVICE_URL}/sso/Keycloak?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" |
| 232 | + disabled={isSubmitting} |
| 233 | + > |
209 | 234 | <i class="mdi mdi-cloud" /> |
210 | | - </a> |
| 235 | + </Link> |
211 | 236 | </li> |
212 | 237 | <li class="list-inline-item"> |
213 | | - <a href="{PUBLIC_SERVICE_URL}/sso/Google?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" class="social-list-item bg-danger text-white border-danger"> |
| 238 | + <Link |
| 239 | + class="social-list-item bg-danger text-white border-danger" |
| 240 | + href="{PUBLIC_SERVICE_URL}/sso/Google?redirectUrl={PUBLIC_LIVECHAT_HOST}page/user/me" |
| 241 | + disabled={isSubmitting} |
| 242 | + > |
214 | 243 | <i class="mdi mdi-google" /> |
215 | | - </a> |
| 244 | + </Link> |
216 | 245 | </li> |
217 | 246 | </ul> |
218 | 247 | </div> |
219 | 248 | {/if} |
220 | 249 | {#if PUBLIC_AUTH_ENABLE_FIND_PWD == 'true' } |
221 | 250 | <div class="mt-4 text-center"> |
222 | | - <Link href="recoverpw" class="text-muted"> |
| 251 | + <Link href="recoverpw" class="text-muted" disabled={isSubmitting}> |
223 | 252 | <i class="mdi mdi-lock me-1" /> Forgot your password? |
224 | 253 | </Link> |
225 | 254 | </div> |
|
231 | 260 | <div class="mt-5 text-center"> |
232 | 261 | <p hidden={!(PUBLIC_ALLOW_SIGNUP === 'true')}> |
233 | 262 | Don't have an account ? |
234 | | - <Link href="register" class="fw-medium text-primary">Signup now</Link> |
| 263 | + <Link href="register" class="fw-medium text-primary" disabled={isSubmitting}>Signup now</Link> |
235 | 264 | </p> |
236 | 265 | <p> |
237 | 266 | © {new Date().getFullYear()} |
|
0 commit comments