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';
|
2020-01-31 00:06:35 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
2020-06-11 21:23:00 +00:00
|
|
|
import { action } from '@ember/object';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class Tokens extends Controller {
|
|
|
|
@service token;
|
|
|
|
@service store;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@reads('token.secret') secret;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
tokenIsValid = false;
|
|
|
|
tokenIsInvalid = false;
|
|
|
|
@alias('token.selfToken') tokenRecord;
|
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();
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2017-10-18 23:42:08 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
clearTokenProperties() {
|
|
|
|
this.token.setProperties({
|
|
|
|
secret: undefined,
|
|
|
|
});
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: false,
|
|
|
|
tokenIsInvalid: false,
|
|
|
|
});
|
2020-07-10 03:34:44 +00:00
|
|
|
// Clear out all data to ensure only data the anonymous token is privileged to see is shown
|
2020-06-11 21:23:00 +00:00
|
|
|
this.resetStore();
|
|
|
|
this.token.reset();
|
|
|
|
}
|
2017-10-13 22:18:05 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
verifyToken() {
|
|
|
|
const { secret } = this;
|
|
|
|
const TokenAdapter = getOwner(this).lookup('adapter:token');
|
2017-10-13 22:18:05 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
this.set('token.secret', secret);
|
2017-10-14 19:42:14 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
TokenAdapter.findSelf().then(
|
|
|
|
() => {
|
2020-07-10 03:34:44 +00:00
|
|
|
// Clear out all data to ensure only data the new token is privileged to see is shown
|
2020-06-11 21:23:00 +00:00
|
|
|
this.resetStore();
|
2017-10-18 23:42:08 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
// Refetch the token and associated policies
|
2021-12-28 14:45:20 +00:00
|
|
|
this.get('token.fetchSelfTokenAndPolicies').perform().catch();
|
2017-10-18 23:42:08 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: true,
|
|
|
|
tokenIsInvalid: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.set('token.secret', undefined);
|
|
|
|
this.setProperties({
|
|
|
|
tokenIsValid: false,
|
|
|
|
tokenIsInvalid: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|