2017-09-19 14:47:10 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2017-10-14 19:42:14 +00:00
|
|
|
const { Controller, inject, computed, getOwner } = Ember;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
|
|
|
token: inject.service(),
|
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
secret: computed.reads('token.secret'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
tokenIsValid: false,
|
|
|
|
tokenIsInvalid: false,
|
2017-10-16 20:07:18 +00:00
|
|
|
tokenRecord: null,
|
2017-10-13 22:18:05 +00:00
|
|
|
|
|
|
|
actions: {
|
2017-09-19 14:47:10 +00:00
|
|
|
clearTokenProperties() {
|
|
|
|
this.get('token').setProperties({
|
|
|
|
secret: undefined,
|
|
|
|
accessor: undefined,
|
|
|
|
});
|
2017-10-13 22:18:05 +00:00
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: false,
|
|
|
|
tokenIsInvalid: false,
|
2017-10-14 19:42:14 +00:00
|
|
|
tokenRecord: null,
|
2017-10-13 22:18:05 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
verifyToken() {
|
2017-10-14 19:42:14 +00:00
|
|
|
const { secret } = this.getProperties('secret', 'accessor');
|
|
|
|
const TokenAdapter = getOwner(this).lookup('adapter:token');
|
2017-10-13 22:18:05 +00:00
|
|
|
|
|
|
|
this.set('token.secret', secret);
|
2017-10-14 19:42:14 +00:00
|
|
|
|
|
|
|
TokenAdapter.findSelf().then(
|
|
|
|
token => {
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: true,
|
|
|
|
tokenIsInvalid: false,
|
|
|
|
tokenRecord: token,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.set('token.secret', null);
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: false,
|
2017-10-16 20:07:18 +00:00
|
|
|
tokenIsInvalid: true,
|
2017-10-14 19:42:14 +00:00
|
|
|
tokenRecord: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|