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

54 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 } = Ember;
2017-09-19 14:47:10 +00:00
export default Controller.extend({
token: inject.service(),
tokenRecord: null,
secret: computed.reads('token.secret'),
accessor: computed.reads('token.accessor'),
2017-09-19 14:47:10 +00:00
tokenIsValid: false,
tokenIsInvalid: false,
actions: {
2017-09-19 14:47:10 +00:00
clearTokenProperties() {
this.get('token').setProperties({
secret: undefined,
accessor: undefined,
});
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
},
},
});