Skip to content

Instantly share code, notes, and snippets.

@Gowiem
Created June 3, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gowiem/97328e1c41a50dc88919210d8d45e9ea to your computer and use it in GitHub Desktop.
Save Gowiem/97328e1c41a50dc88919210d8d45e9ea to your computer and use it in GitHub Desktop.
// frontend/app/routes/accept-invitation.js
import Ember from 'ember';
import config from '../config/environment';
const { inject: { service }, isEmpty } = Ember;
export default Ember.Route.extend({
session: service('session'),
beforeModel() {
if (this.get('session.isAuthenticated')) {
this.get('session').invalidate();
}
},
model() {
return Ember.Object.create({ password: null, password_confirmation: null, invitation_token: null });
},
afterModel(model, transition) {
let invitationToken = transition.queryParams.invitation_token;
if (isEmpty(invitationToken)) {
this.transitionTo('dashboard');
} else {
model.set('invitation_token', invitationToken);
}
},
actions: {
submit(model) {
let body = { user: model.getProperties('invitation_token', 'password', 'password_confirmation') };
Ember.$.ajax({
url: `${config.APP.API_HOST}/users/invitation`,
type: 'PUT',
data: body,
}).then(() => {
this.transitionTo('login');
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment