Skip to content

Orders: Make flow similar to eventyay Phase - 2 #2028

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

Merged
merged 1 commit into from
Jan 30, 2019
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
2 changes: 1 addition & 1 deletion app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default JSONAPIAdapter.extend(HasManyQueryAdapterMixin, AdapterFetch, Cac
}),

isInvalid(statusCode) {
if (statusCode !== 404 && statusCode !== 422 && statusCode !== 403) {
if (statusCode !== 404 && statusCode !== 422 && statusCode !== 403 && statusCode !== 409) {
this.get('notify').error('An unexpected error occurred.', {
closeAfter: 5000
});
Expand Down
67 changes: 55 additions & 12 deletions app/controllers/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default Controller.extend({

isLoginModalOpen: false,

userExists: false,

featuredSpeakers: filterBy('model.speakers', 'isFeatured', true),

nonFeaturedSpeakers: filterBy('model.speakers', 'isFeatured', false),
Expand All @@ -24,7 +26,8 @@ export default Controller.extend({
this.set('isLoading', true);
let newUser = this.store.createRecord('user', {
email,
'password': (Math.random() * 10).toString(16)
'password' : (Math.random() * 10).toString(16),
'wasRegisteredWithOrder' : true
});
newUser.save()
.then(() => {
Expand All @@ -45,21 +48,61 @@ export default Controller.extend({
}
})
.catch(reason => {
if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
if (reason && reason.hasOwnProperty('status_code') && reason.status_code === 401) {
this.set('errorMessage', this.get('l10n').t('Your credentials were incorrect.'));
} else {
this.set('errorMessage', this.get('l10n').t('An unexpected error occurred.'));
}
this.set('isLoading', false);
} else {
console.warn(reason);
}
console.warn(reason);
})
.finally(() => {
this.set('session.skipRedirectOnInvalidation', false);
this.set('isLoading', false);
});
})
.catch(error => {
if (error.errors[0]) {
if (error.errors[0].status === 409) {
this.set('userExists', true);
} else {
this.get('notify').error(this.get('l10n').t(error.errors[0].detail));
}
}
})
.finally(() => {
this.set('isLoading', false);
});

},

async loginExistingUser(identification, password) {
this.set('isLoading', true);
let credentials = {
identification,
password
};
let authenticator = 'authenticator:jwt';
this.get('session')
.authenticate(authenticator, credentials)
.then(async() => {
const tokenPayload = this.get('authManager').getTokenPayload();
if (tokenPayload) {
this.set('session.skipRedirectOnInvalidation', true);
this.get('authManager').persistCurrentUser(
await this.get('store').findRecord('user', tokenPayload.identity)
);
this.set('isLoginModalOpen', false);
this.send('placeOrder');
}
})
.catch(reason => {
if (!(this.get('isDestroyed') || this.get('isDestroying'))) {
if (reason && reason.hasOwnProperty('status_code') && reason.status_code === 401) {
this.set('errorMessage', this.get('l10n').t('Your credentials were incorrect.'));
} else {
this.set('errorMessage', this.get('l10n').t('An unexpected error occurred.'));
}
} else {
console.warn(reason);
}
})
.finally(() => {
this.set('session.skipRedirectOnInvalidation', false);
this.set('isLoading', false);
});

},
Expand Down
25 changes: 13 additions & 12 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ export default ModelBase.extend({

authManager: service(),

email : attr('string'),
password : attr('string'),
isVerified : attr('boolean', { readOnly: true }),
isSuperAdmin : attr('boolean', { readOnly: true }),
isAdmin : attr('boolean', { readOnly: true }),
isUserOrganizer : attr('boolean'),
isUserCoorganizer : attr('boolean'),
isUserTrackOrganizer : attr('boolean'),
isUserModerator : attr('boolean'),
isUserRegistrar : attr('boolean'),
isSalesAdmin : attr('boolean'),
isMarketer : attr('boolean'),
email : attr('string'),
password : attr('string'),
isVerified : attr('boolean', { readOnly: true }),
isSuperAdmin : attr('boolean', { readOnly: true }),
isAdmin : attr('boolean', { readOnly: true }),
isUserOrganizer : attr('boolean'),
isUserCoorganizer : attr('boolean'),
isUserTrackOrganizer : attr('boolean'),
isUserModerator : attr('boolean'),
isUserRegistrar : attr('boolean'),
isSalesAdmin : attr('boolean'),
isMarketer : attr('boolean'),
wasRegisteredWithOrder : attr('boolean'),

firstName : attr('string'),
lastName : attr('string'),
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default ApplicationSerializer.extend({
}
json.data.attributes = omit(json.data.attributes, attributesToOmit);
} else if (options && options.includeId) {
json.data.attributes = pick(json.data.attributes, ['email', 'password']);
json.data.attributes = pick(json.data.attributes, ['email', 'password', 'was-registered-with-order']);
}
return json;
}
Expand Down
47 changes: 32 additions & 15 deletions app/templates/components/modals/login-signup-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@
</div>
{{else if (eq session.currentRouteName 'public.index')}}
<i class="black close icon"></i>
<h4 class="ui header">{{t 'Please enter your Email address to continue.'}}</h4>
<div class="content">
{{t 'Have you used Open Event before? Please'}}
{{#link-to 'login' invokeAction=(action 'toggleView')}}
{{t 'Login'}}
{{/link-to}} {{t 'to continue'}}
<form class="ui {{if isLoading 'loading' }} form">
<div class="field">
<label class="required" for="email">{{t 'E-mail'}}</label>
{{input type='text' name="email" value=email placeholder=(t 'Email Address')}}
</div>
<button type="submit" class="ui green button" {{action createNewUserViaEmail email}}>
{{t 'Continue'}}
</button>
</form>
<div class="ui basic compact segment">
<div class="content">
<form class="ui {{if isLoading 'loading' }} form">
{{#if errorMessage}}
<div class="ui negative message">
<p>{{errorMessage}}</p>
</div>
{{/if}}
<h4 class="ui header">{{t 'Please enter your email address to continue.'}}</h4>
<div class="field">
{{input type='text' name="email" value=email disabled=userExists placeholder=(t 'Email Address')}}
</div>
{{#if userExists}}
<div class="ui text muted">{{t 'You have previously registered with this email address.'}}</div>
<div class="field">
<label class="required" for="password">{{t 'Please enter your password to continue.'}}</label>
{{input type='password' name="password" value=password}}
</div>
<div class="ui center aligned segment basic">
<a href="{{href-to 'reset-password'}}" class="text muted"> {{t 'Forgot your password ?'}}</a>
</div>
<button type="submit" class="ui blue button" {{action loginExistingUser email password}}>
{{t 'Sign In'}}
</button>
{{else}}
<button type="submit" class="ui green button" {{action createNewUserViaEmail email}}>
{{t 'Continue'}}
</button>
{{/if}}

</form>
</div>
</div>
{{/if}}

Expand Down
8 changes: 7 additions & 1 deletion app/templates/components/public/ticket-list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@
</div>
</form>

{{modals/login-signup-modal isOpen=isLoginModalOpen isLoading=isLoading createNewUserViaEmail=createNewUserViaEmail}}
{{modals/login-signup-modal isOpen=isLoginModalOpen
isLoading=isLoading
createNewUserViaEmail=createNewUserViaEmail
loginExistingUser=loginExistingUser
userExists=userExists
errorMessage=errorMessage
}}
3 changes: 3 additions & 0 deletions app/templates/public/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
attendees=model.attendees
code=code
createNewUserViaEmail=(action 'createNewUserViaEmail')
loginExistingUser=(action 'loginExistingUser')
isLoginModalOpen=isLoginModalOpen
placeOrder=(action 'placeOrder')
isLoading=isLoading
userExists=userExists
errorMessage=errorMessage
save='save'}}
{{else}}
<div class="ui grid">
Expand Down