open-nomad/ui/app/controllers/settings/tokens.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

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