2017-09-19 14:47:10 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
const { Controller, inject, computed } = Ember;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
|
|
|
token: inject.service(),
|
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
tokenRecord: null,
|
|
|
|
secret: computed.reads('token.secret'),
|
|
|
|
accessor: computed.reads('token.accessor'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
tokenIsValid: false,
|
|
|
|
tokenIsInvalid: false,
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
verifyToken() {
|
|
|
|
const { secret, accessor } = this.getProperties('secret', 'accessor');
|
|
|
|
|
|
|
|
this.set('token.secret', secret);
|
|
|
|
this.get('store')
|
|
|
|
.findRecord('token', accessor)
|
|
|
|
.then(
|
|
|
|
token => {
|
|
|
|
this.set('token.accessor', accessor);
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: true,
|
|
|
|
tokenIsInvalid: false,
|
|
|
|
tokenRecord: token,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.set('token.secret', null);
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsInvalid: true,
|
|
|
|
tokenIsValid: false,
|
|
|
|
tokenRecord: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|