Created
June 3, 2017 10:31
-
-
Save Gowiem/97328e1c41a50dc88919210d8d45e9ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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