1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
15 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
16 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
17 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
18 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
19 | };
|
20 | import { LitElement, html, property, customElement, css, query } from 'lit-element/lit-element.js';
|
21 |
|
22 |
|
23 | import './components/kwc-auth-username.js';
|
24 | import './components/kwc-auth-password.js';
|
25 | import './components/kwc-auth-email.js';
|
26 | import './components/kwc-auth-forgot-username.js';
|
27 | import './components/kwc-auth-forgot-email.js';
|
28 | import './components/kwc-auth-forgot-password.js';
|
29 | import './components/kwc-auth-successful-signup.js';
|
30 | import './components/kwc-auth-login.js';
|
31 | import { styles } from './styles.js';
|
32 | let KwcAuth = class KwcAuth extends LitElement {
|
33 | constructor() {
|
34 | super();
|
35 | this.loading = false;
|
36 | this.hideLogin = true;
|
37 | this.view = '';
|
38 | this.locale = '';
|
39 | this.logo = 'kano';
|
40 | this.backgroundGlyph = 'shapesGlyph';
|
41 | this.allowExit = false;
|
42 | this.form = {
|
43 | username: '',
|
44 | password: '',
|
45 | email: '',
|
46 | region: '',
|
47 | };
|
48 | this.handleLoginRequested = this.handleLoginRequested.bind(this);
|
49 | }
|
50 | static get styles() {
|
51 | return [
|
52 | styles,
|
53 | css `
|
54 | kwc-auth-login,
|
55 | kwc-auth-password,
|
56 | kwc-auth-username,
|
57 | kwc-auth-successful-signup,
|
58 | kwc-auth-forgot-password,
|
59 | kwc-auth-forgot-username,
|
60 | kwc-auth-forgot-email,
|
61 | kwc-auth-email {
|
62 | background-color: white;
|
63 | border-radius: 9px;
|
64 | width: 100%;
|
65 | height: 100%;
|
66 | margin: 0 auto;
|
67 | }
|
68 |
|
69 | @media (max-width: 600px) {
|
70 | kwc-auth-login {
|
71 | border-radius: 0;
|
72 | height: 100vh;
|
73 | }
|
74 | }
|
75 | `,
|
76 | ];
|
77 | }
|
78 | connectedCallback() {
|
79 | super.connectedCallback();
|
80 | this.addEventListener('login-requested', this.handleLoginRequested);
|
81 | }
|
82 | disconnectedCallback() {
|
83 | super.disconnectedCallback();
|
84 | this.removeEventListener('login-requested', this.handleLoginRequested);
|
85 | }
|
86 | handleLoginRequested() {
|
87 | this.submit('login');
|
88 | }
|
89 |
|
90 | formTemplate(view) {
|
91 | switch (view) {
|
92 | case 'username':
|
93 | return html `
|
94 | <kwc-auth-username
|
95 | .disabled=${this.loading}
|
96 | .allowExit=${this.allowExit}
|
97 | .locale=${this.locale}
|
98 | @submit=${this.handleUsernameSubmit}
|
99 | @exit=${this.handleExit}
|
100 | ></kwc-auth-username>
|
101 | `;
|
102 | case 'update-username':
|
103 | return html `
|
104 | <kwc-auth-username
|
105 | .hideLogin=${this.hideLogin}
|
106 | .disabled=${this.loading}
|
107 | .locale=${this.locale}
|
108 | @submit=${this.handleUpdateUsername}
|
109 | ></kwc-auth-username>
|
110 | `;
|
111 | case 'password':
|
112 | return html `
|
113 | <kwc-auth-password
|
114 | .username=${this.form.username}
|
115 | .disabled=${this.loading}
|
116 | .locale=${this.locale}
|
117 | @submit=${this.handlePasswordSubmit}
|
118 | ></kwc-auth-password>
|
119 | `;
|
120 | case 'email':
|
121 | return html `
|
122 | <kwc-auth-email
|
123 | .disabled=${this.loading}
|
124 | .locale=${this.locale}
|
125 | @submit=${this.handleRegister}
|
126 | ></kwc-auth-email>
|
127 | `;
|
128 | case 'update-email':
|
129 | return html `
|
130 | <kwc-auth-email
|
131 | .hideLogin=${this.hideLogin}
|
132 | .disabled=${this.loading}
|
133 | .locale=${this.locale}
|
134 | @submit=${this.handleUpdateEmail}
|
135 | ></kwc-auth-email>
|
136 | `;
|
137 | case 'forgot-email':
|
138 | return html `
|
139 | <kwc-auth-forgot-email
|
140 | .disabled=${this.loading}
|
141 | .locale=${this.locale}
|
142 | @submit=${this.handleForgotEmail}
|
143 | ></kwc-auth-forgot-email>
|
144 | `;
|
145 | case 'forgot-password':
|
146 | return html `
|
147 | <kwc-auth-forgot-password
|
148 | .disabled=${this.loading}
|
149 | .locale=${this.locale}
|
150 | @submit=${this.handleForgotPassword}
|
151 | ></kwc-auth-forgot-password>
|
152 | `;
|
153 | case 'forgot-username':
|
154 | return html `
|
155 | <kwc-auth-forgot-username
|
156 | .disabled=${this.loading}
|
157 | .locale=${this.locale}
|
158 | @submit=${this.handleForgotUsername}
|
159 | ></kwc-auth-forgot-username>
|
160 | `;
|
161 | case 'success':
|
162 | return html `
|
163 | <kwc-auth-successful-signup
|
164 | .locale=${this.locale}
|
165 | @submit=${this.handleFinishedFlow}
|
166 | @resend-email=${this.handleResendEmail}
|
167 | ></kwc-auth-successful-signup>
|
168 | `;
|
169 | default:
|
170 | return html `
|
171 | <kwc-auth-login
|
172 | .disabled=${this.loading}
|
173 | .logo=${this.logo}
|
174 | .locale=${this.locale}
|
175 | @submit=${this.handleLogin}
|
176 | @changeView=${this.changeView}
|
177 | ></kwc-auth-login>
|
178 | `;
|
179 | }
|
180 | }
|
181 | changeView(e) {
|
182 | this.submit(e.detail.view);
|
183 | }
|
184 | handleSubmit(e) {
|
185 | this.submit(e.detail.next);
|
186 | }
|
187 | handleExit() {
|
188 | this.dispatchEvent(new CustomEvent('exit'));
|
189 | }
|
190 | render() {
|
191 | return this.formTemplate(this.view);
|
192 | }
|
193 | submit(view) {
|
194 | this.dispatchEvent(new CustomEvent('changeView', {
|
195 | detail: {
|
196 | nextView: view,
|
197 | }
|
198 | }));
|
199 | }
|
200 | handleUsernameSubmit(e) {
|
201 | this.form.username = e.detail.payload.username;
|
202 | this.dispatchEvent(new CustomEvent('submit-username', {
|
203 | detail: e.detail.payload.username,
|
204 | }));
|
205 | }
|
206 | handlePasswordSubmit(e) {
|
207 | this.form.password = e.detail.payload.password;
|
208 | this.dispatchEvent(new CustomEvent('submit-password'));
|
209 | }
|
210 | handleUpdateUsername(e) {
|
211 | this.dispatchEvent(new CustomEvent('update-username', {
|
212 | detail: e.detail.payload.username,
|
213 | }));
|
214 | }
|
215 | handleRegister(e) {
|
216 | this.form.email = e.detail.payload.email;
|
217 | this.form.region = e.detail.payload.region;
|
218 | this.dispatchEvent(new CustomEvent('register', {
|
219 | detail: {
|
220 | form: this.form,
|
221 | },
|
222 | }));
|
223 | }
|
224 | handleUpdateEmail(e) {
|
225 | this.dispatchEvent(new CustomEvent('update-email', {
|
226 | detail: e.detail.payload.email,
|
227 | }));
|
228 | }
|
229 | handleLogin(e) {
|
230 | this.dispatchEvent(new CustomEvent('login', {
|
231 | detail: e.detail,
|
232 | }));
|
233 | }
|
234 | handleForgotPassword(e) {
|
235 | this.dispatchEvent(new CustomEvent('forgot-password', {
|
236 | detail: e.detail.payload['forgot-password'],
|
237 | }));
|
238 | }
|
239 | handleForgotUsername(e) {
|
240 | this.dispatchEvent(new CustomEvent('forgot-username', {
|
241 | detail: e.detail.payload['forgot-username'],
|
242 | }));
|
243 | }
|
244 | handleForgotEmail(e) {
|
245 | this.dispatchEvent(new CustomEvent('forgot-email', {
|
246 | detail: e.detail.payload['forgot-email'],
|
247 | }));
|
248 | }
|
249 | handleFinishedFlow() {
|
250 | this.dispatchEvent(new CustomEvent('finished-flow'));
|
251 | }
|
252 | handleResendEmail() {
|
253 | this.dispatchEvent(new Event('finished-flow'));
|
254 | }
|
255 | };
|
256 | __decorate([
|
257 | property({ type: Boolean })
|
258 | ], KwcAuth.prototype, "loading", void 0);
|
259 | __decorate([
|
260 | property({ type: Boolean })
|
261 | ], KwcAuth.prototype, "hideLogin", void 0);
|
262 | __decorate([
|
263 | property({ type: String })
|
264 | ], KwcAuth.prototype, "view", void 0);
|
265 | __decorate([
|
266 | property({ type: String })
|
267 | ], KwcAuth.prototype, "locale", void 0);
|
268 | __decorate([
|
269 | property({ type: String })
|
270 | ], KwcAuth.prototype, "logo", void 0);
|
271 | __decorate([
|
272 | property({ type: String })
|
273 | ], KwcAuth.prototype, "backgroundGlyph", void 0);
|
274 | __decorate([
|
275 | property({ type: Boolean })
|
276 | ], KwcAuth.prototype, "allowExit", void 0);
|
277 | __decorate([
|
278 | property({ type: Object })
|
279 | ], KwcAuth.prototype, "form", void 0);
|
280 | __decorate([
|
281 | query('kwc-auth-username')
|
282 | ], KwcAuth.prototype, "username", void 0);
|
283 | __decorate([
|
284 | query('kwc-auth-forgot-username')
|
285 | ], KwcAuth.prototype, "forgotUsername", void 0);
|
286 | __decorate([
|
287 | query('kwc-auth-email')
|
288 | ], KwcAuth.prototype, "email", void 0);
|
289 | __decorate([
|
290 | query('kwc-auth-forgot-password')
|
291 | ], KwcAuth.prototype, "forgotPassword", void 0);
|
292 | __decorate([
|
293 | query('kwc-auth-login')
|
294 | ], KwcAuth.prototype, "login", void 0);
|
295 | KwcAuth = __decorate([
|
296 | customElement('kwc-auth')
|
297 | ], KwcAuth);
|
298 | export { KwcAuth };
|
299 |
|
\ | No newline at end of file |