-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathforgot-password.gts
More file actions
167 lines (148 loc) · 4.71 KB
/
forgot-password.gts
File metadata and controls
167 lines (148 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { Input } from '@ember/component';
import { action } from '@ember/object';
import { LinkTo } from '@ember/routing';
import type Router from '@ember/routing/router-service';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import type CognitoService from 'ember-cognito/services/cognito';
import type Session from '../services/session.ts';
import LoadingButton from './loading-button.gts';
export default class ForgotPasswordComponent extends Component {
<template>
<div class="bg-menu p-4 rounded-sm w-full">
<div class="flex justify-between pt-4 w-full">
<h2 class="font-bold text-2xl">
{{if this.isConfirming "Reset Password" "Forgot Password"}}
</h2>
<p class="mt-2 text-menu-text text-sm">
<LinkTo
@route="settings.cloud.login"
class="font-medium text-alt hover:text-alt-hover"
>
cancel
</LinkTo>
</p>
</div>
{{#if this.errorMessage}}
<div class="bg-red-400 my-2 p-4 rounded-sm text-xs text-red-800">
{{this.errorMessage}}
</div>
{{/if}}
<p class="my-2 text-sm">
Enter your email address to reset your password.
</p>
<div class="mt-3">
<div class="mb-4">
<div>
<label for="email-address" class="sr-only">
Email address
</label>
<Input
data-test-forgot-password-input-user
autocomplete="email"
class="input py-2 rounded-xs text-sm w-full"
id="email-address"
name="email"
placeholder="Email address"
required
@type="email"
@value={{this.username}}
/>
</div>
{{#if this.isConfirming}}
<div>
<label for="confirmation-code" class="sr-only">
Confirmation code
</label>
<Input
data-test-forgot-password-input-code
autocomplete="current-password"
class="input py-2 rounded-xs text-sm w-full"
id="confirmation-code"
name="confirmation-code"
placeholder="Confirmation code"
required
@type="text"
@value={{this.code}}
/>
</div>
<div>
<label for="password" class="sr-only">
Password
</label>
<Input
data-test-forgot-password-input-password
autocomplete="current-password"
class="input py-2 rounded-xs text-sm w-full"
id="password"
name="password"
placeholder="Password"
required
@type="password"
@value={{this.password}}
/>
</div>
<div class="mt-6">
<LoadingButton
class="btn btn-primary w-full"
@loading={{this.loading}}
@onClick={{this.forgotPasswordSubmit}}
>
Reset Password
</LoadingButton>
</div>
{{else}}
<div class="mt-6">
<LoadingButton
class="btn btn-primary w-full"
@loading={{this.loading}}
@onClick={{this.forgotPassword}}
>
Send Code
</LoadingButton>
</div>
{{/if}}
</div>
</div>
</div>
</template>
@service declare cognito: CognitoService;
@service declare router: Router;
@service declare session: Session;
@tracked code?: string;
@tracked errorMessage?: string;
@tracked isConfirming = false;
@tracked loading = false;
@tracked password?: string;
@tracked username?: string;
@action
async forgotPassword(): Promise<void> {
if (this.username) {
this.loading = true;
try {
await this.cognito.forgotPassword(this.username);
this.isConfirming = true;
} catch (err: unknown) {
this.errorMessage = (err as Error)?.message;
} finally {
this.loading = false;
}
}
}
@action
async forgotPasswordSubmit(): Promise<void> {
const { username, code, password } = this;
if (username && code && password) {
this.loading = true;
try {
await this.cognito.forgotPasswordSubmit(username, code, password);
this.router.transitionTo('settings.cloud');
} catch (err: unknown) {
this.errorMessage = (err as Error)?.message;
} finally {
this.loading = false;
}
}
}
}