2017-12-15 21:39:18 +00:00
|
|
|
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({
|
2017-12-15 21:39:18 +00:00
|
|
|
token: service(),
|
2018-08-04 01:14:46 +00:00
|
|
|
system: service(),
|
2017-12-15 21:39:18 +00:00
|
|
|
store: service(),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
secret: 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
|
|
|
|
2017-10-18 23:42:08 +00:00
|
|
|
resetStore() {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.store.unloadAll();
|
2017-10-18 23:42:08 +00:00
|
|
|
},
|
|
|
|
|
2017-10-13 22:18:05 +00:00
|
|
|
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,
|
|
|
|
});
|
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
|
|
|
});
|
2017-10-18 23:42:08 +00:00
|
|
|
this.resetStore();
|
2017-10-13 22:18:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
verifyToken() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const { secret } = this;
|
2017-10-14 19:42:14 +00:00
|
|
|
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(
|
2020-01-29 04:29:16 +00:00
|
|
|
() => {
|
2017-10-18 23:42:08 +00:00
|
|
|
// 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();
|
2017-10-18 23:42:08 +00:00
|
|
|
this.resetStore();
|
|
|
|
|
2020-01-29 04:29:16 +00:00
|
|
|
// Refetch the token and associated policies
|
|
|
|
this.get('token.fetchSelfTokenAndPolicies')
|
|
|
|
.perform()
|
|
|
|
.catch();
|
2017-10-18 23:42:08 +00:00
|
|
|
|
2017-10-14 19:42:14 +00:00
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: true,
|
|
|
|
tokenIsInvalid: false,
|
2020-01-29 04:29:16 +00:00
|
|
|
tokenRecord: this.token.selfToken,
|
2017-10-14 19:42:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
() => {
|
2017-10-19 17:10:01 +00:00
|
|
|
this.set('token.secret', undefined);
|
2017-10-14 19:42:14 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|