Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
73 changes: 37 additions & 36 deletions app/controllers/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,41 @@ export default Controller.extend({
'password' : (Math.random() * 10).toString(16),
'wasRegisteredWithOrder' : true
});
newUser.save()
.then(() => {
let credentials = newUser.getProperties('email', 'password'),
authenticator = 'authenticator:jwt';
credentials.identification = newUser.email;
this.session
.authenticate(authenticator, credentials)
.then(async() => {
const tokenPayload = this.authManager.getTokenPayload();
if (tokenPayload) {
this.set('session.skipRedirectOnInvalidation', true);
this.authManager.persistCurrentUser(
await this.store.findRecord('user', tokenPayload.identity)
);
this.set('isLoginModalOpen', false);
this.send('placeOrder');
}
})
.catch(reason => {
console.warn(reason);
})
.finally(() => {
this.set('session.skipRedirectOnInvalidation', false);
});
})
.catch(error => {
if (error.errors[0]) {
if (error.errors[0].status === 409) {
this.set('userExists', true);
} else {
this.notify.error(this.l10n.t(error.errors[0].detail));
}
try {
await newUser.save();

let credentials = newUser.getProperties('email', 'password'),
authenticator = 'authenticator:jwt';
credentials.identification = newUser.email;

try {
await this.session.authenticate(authenticator, credentials);
const tokenPayload = this.authManager.getTokenPayload();
if (tokenPayload) {
this.set('session.skipRedirectOnInvalidation', true);
this.authManager.persistCurrentUser(
await this.store.findRecord('user', tokenPayload.identity)
);
this.set('isLoginModalOpen', false);
this.send('placeOrder');
}
})
.finally(() => {
this.set('isLoading', false);
});
} catch (reason) {
console.warn(reason);
} finally {
this.set('session.skipRedirectOnInvalidation', false);
}
} catch (error) {
if (error.errors[0]) {
if (error.errors[0].status === 409) {
this.set('userExists', true);
} else {
this.notify.error(this.l10n.t(error.errors[0].detail));
}
}
} finally {
this.set('isLoading', false);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the solution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be the approach then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't even fix the issue I mentioned. So the approach should be whatever which doesn't at least break the existing app

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping await calls inside try-catch which, if fail were crashing fastboot app server ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that did not fix the issue, this is called ignoring the issue, not fixing it. Besides, it is still crashing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nobody asked you to go to eventyay. Change API_HOST to https://api.eventyay.com and retest

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal Working on fastboot, Also checked on fossasia summit 2020. There was an issue in loading currentUser which was resulting into null query. Took reference from your WIP PR. It is working well now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be reverted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try catch block ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



},

Expand Down Expand Up @@ -112,6 +110,7 @@ export default Controller.extend({
this.set('isLoginModalOpen', true);
return;
}

let { order, event } = this.model;
order.tickets.forEach(ticket => {
let numberOfAttendees = ticket.orderQuantity;
Expand All @@ -136,6 +135,7 @@ export default Controller.extend({
for (const attendee of attendees ? attendees.toArray() : []) {
await attendee.save();
}

order.set('attendees', attendees);
await order.save()
.then(order => {
Expand All @@ -146,6 +146,7 @@ export default Controller.extend({
for (const attendee of attendees ? attendees.toArray() : []) {
await attendee.destroyRecord();
}

this.notify.error(this.l10n.t(e.errors[0].detail));
})
.finally(() => {
Expand Down
25 changes: 18 additions & 7 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { inject as service } from '@ember/service';
import { merge, values, isEmpty } from 'lodash-es';

export default Route.extend(ApplicationRouteMixin, {
session: service(),
session : service(),
currentUser : service(),

title(tokens) {
if (!tokens) {
tokens = [];
Expand All @@ -23,6 +25,8 @@ export default Route.extend(ApplicationRouteMixin, {
} else {
this.set('session.previousRouteName', null);
}

return this._loadCurrentUser();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this here?

},

async model() {
Expand Down Expand Up @@ -63,17 +67,25 @@ export default Route.extend(ApplicationRouteMixin, {
if (!this.get('session.skipRedirectOnInvalidation')) {
this._super(...arguments);
}

this.set('session.skipRedirectOnInvalidation', false);
},

sessionAuthenticated() {
if (this.get('session.previousRouteName')) {
this.transitionTo(this.get('session.previousRouteName'));
async sessionAuthenticated() {
let { _super } = this;
await this._loadCurrentUser();
const route = this.session.previousRouteName;
if (route) {
this.transitionTo(route);
} else {
this._super(...arguments);
_super.call(this, ...arguments);
}
},

_loadCurrentUser() {
return this.currentUser.load().catch(() => this.getsession.invalidate());
},

/**
* Merge all params into one param.
*
Expand All @@ -96,11 +108,10 @@ export default Route.extend(ApplicationRouteMixin, {
} else {
url = transition.router.generate(transition.targetName, params);
}

// Do not save the url of the transition to login route.
if (!url.includes('login') && !url.includes('reset-password')) {
this.set('session.previousRouteName', url);
} else {
this.set('session.previousRouteName', null);
}
});
}
Expand Down
20 changes: 20 additions & 0 deletions app/services/current-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { isEmpty } from '@ember/utils';
import { resolve } from 'rsvp';

export default Service.extend({
session : service(),
store : service(),

load() {
let userId = this.get('session.data.authenticated.user_id');
if (!isEmpty(userId)) {
return this.store.findRecord('user', userId).then(user => {
this.set('user', user);
});
} else {
return resolve();
}
}
});