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

70 lines
1.6 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { reads } from '@ember/object/computed';
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
2017-09-19 14:47:10 +00:00
export default Controller.extend({
token: service(),
system: service(),
store: service(),
2017-09-19 14:47:10 +00:00
secret: reads('token.secret'),
2017-09-19 14:47:10 +00:00
tokenIsValid: false,
tokenIsInvalid: false,
tokenRecord: null,
resetStore() {
2019-03-26 07:46:44 +00:00
this.store.unloadAll();
},
actions: {
2017-09-19 14:47:10 +00:00
clearTokenProperties() {
2019-03-26 07:46:44 +00:00
this.token.setProperties({
2017-09-19 14:47:10 +00:00
secret: undefined,
});
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: false,
tokenRecord: null,
});
this.resetStore();
},
verifyToken() {
2019-03-26 07:46:44 +00:00
const { secret } = this;
const TokenAdapter = getOwner(this).lookup('adapter:token');
this.set('token.secret', secret);
TokenAdapter.findSelf().then(
() => {
// Clear out all data to ensure only data the new token is privileged to
// see is shown
2019-03-26 07:46:44 +00:00
this.system.reset();
this.resetStore();
// Refetch the token and associated policies
this.get('token.fetchSelfTokenAndPolicies')
.perform()
.catch();
this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
tokenRecord: this.token.selfToken,
});
},
() => {
this.set('token.secret', undefined);
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: true,
tokenRecord: null,
});
}
);
2017-09-19 14:47:10 +00:00
},
},
});