From 84c041511fc3f7672c77de2b61b90c6a35ca6d37 Mon Sep 17 00:00:00 2001 From: iamareebjamal Date: Fri, 30 Oct 2020 22:18:47 +0530 Subject: [PATCH] feat: Allow users to set password while registering for order --- .../forms/orders/guest-order-form.js | 38 +++++++++++++++++-- app/controllers/public/index.js | 6 +-- .../forms/orders/guest-order-form.hbs | 19 ++++++++-- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/app/components/forms/orders/guest-order-form.js b/app/components/forms/orders/guest-order-form.js index e8385c33006..7e17a263f5f 100644 --- a/app/components/forms/orders/guest-order-form.js +++ b/app/components/forms/orders/guest-order-form.js @@ -1,8 +1,14 @@ import Component from '@ember/component'; +import { computed } from '@ember/object'; import FormMixin from 'open-event-frontend/mixins/form'; export default Component.extend(FormMixin, { - autoScrollToErrors: false, + autoScrollToErrors : false, + showPasswordForm : false, + + nextStep: computed('userExists', 'showPasswordForm', function() { + return this.userExists || this.showPasswordForm; + }), getValidationRules() { return { @@ -23,12 +29,27 @@ export default Component.extend(FormMixin, { } ] }, + password: { identifier : 'password', rules : [ { type : 'empty', prompt : this.l10n.t('Please enter your password') + }, + { + type : 'minLength[8]', + prompt : this.l10n.t('Your password must have at least {ruleValue} characters') + } + ] + }, + + passwordRepeat: { + identifier : 'password_repeat', + rules : [ + { + type : 'match[password]', + prompt : this.l10n.t('Passwords do not match') } ] } @@ -37,13 +58,24 @@ export default Component.extend(FormMixin, { }, actions: { submit() { - this.onValid(() => { + this.onValid(async() => { if (this.userExists) { this.loginExistingUser(this.email, this.password); + } else if (this.password) { + this.createNewUserViaEmail(this.email, this.password); } else { - this.createNewUserViaEmail(this.email); + const result = await this.loader.post('users/check_email', { email: this.email }); + this.set('userExists', result.exists); + if (!result.exists) { + this.set('showPasswordForm', true); + } } }); + }, + reset() { + this.set('userExists', false); + this.set('showPasswordForm', false); + this.set('password', null); } } }); diff --git a/app/controllers/public/index.js b/app/controllers/public/index.js index 6eee6124463..b58f85a646f 100644 --- a/app/controllers/public/index.js +++ b/app/controllers/public/index.js @@ -16,12 +16,12 @@ export default class IndexController extends Controller { } @action - async createNewUserViaEmail(email) { + async createNewUserViaEmail(email, password) { this.set('isLoading', true); const newUser = this.store.createRecord('user', { email, - 'password' : (Math.random() * 10).toString(16), - 'wasRegisteredWithOrder' : true + password, + 'wasRegisteredWithOrder': true }); newUser.save() .then(() => { diff --git a/app/templates/components/forms/orders/guest-order-form.hbs b/app/templates/components/forms/orders/guest-order-form.hbs index 0b27f3fd8e0..9f1f47a6b79 100644 --- a/app/templates/components/forms/orders/guest-order-form.hbs +++ b/app/templates/components/forms/orders/guest-order-form.hbs @@ -7,9 +7,9 @@

{{t 'Please enter your email address to continue.'}}

- - {{#if this.userExists}} - + + {{#if this.nextStep}} + {{/if}}
@@ -25,6 +25,19 @@ + {{else if this.showPasswordForm}} +
{{t 'Please set up a password to continue.'}}
+
+ + +
+
+ + +
+ {{else}}