Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow users to set password while registering for order #5431

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions app/components/forms/orders/guest-order-form.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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')
}
]
}
Expand All @@ -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);
}
}
});
6 changes: 3 additions & 3 deletions app/controllers/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
19 changes: 16 additions & 3 deletions app/templates/components/forms/orders/guest-order-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<h4 class="ui header">{{t 'Please enter your email address to continue.'}}</h4>
<div class="field">
<div class="ui icon input">
<Input @type="text" @name="email" @value={{this.email}} @disabled={{this.userExists}} placeholder={{t "Email Address"}} />
{{#if this.userExists}}
<i class="circular undo link icon" role="button" onclick={{action (mut this.userExists) false}}></i>
<Input @type="text" @name="email" @value={{this.email}} @disabled={{this.nextStep}} placeholder={{t "Email Address"}} />
{{#if this.nextStep}}
<i class="circular undo link icon" role="button" onclick={{action 'reset'}}></i>
{{/if}}
</div>
</div>
Expand All @@ -25,6 +25,19 @@
<button type="submit" class="ui blue button">
{{t 'Sign In'}}
</button>
{{else if this.showPasswordForm}}
<div class="ui text muted">{{t 'Please set up a password to continue.'}}</div>
<div class="field">
<label class="required" for="password">{{t 'Password'}}</label>
<Input @type="password" @name="password" @value={{this.password}} />
</div>
<div class="field">
<label class="required" for="password_repeat">{{t 'Confirm Password'}}</label>
<Input @type="password" @name="password_repeat" />
</div>
<button type="submit" class="ui blue button">
{{t 'Register'}}
</button>
{{else}}
<button type="submit" class="ui green button">
{{t 'Continue'}}
Expand Down