-
Notifications
You must be signed in to change notification settings - Fork 2k
/
tokens.js
69 lines (59 loc) · 1.67 KB
/
tokens.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { inject as service } from '@ember/service';
import { reads } from '@ember/object/computed';
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
import { alias } from '@ember/object/computed';
import { action } from '@ember/object';
import classic from 'ember-classic-decorator';
@classic
export default class Tokens extends Controller {
@service token;
@service store;
@reads('token.secret') secret;
tokenIsValid = false;
tokenIsInvalid = false;
@alias('token.selfToken') tokenRecord;
resetStore() {
this.store.unloadAll();
}
@action
clearTokenProperties() {
this.token.setProperties({
secret: undefined,
});
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: false,
});
// Clear out all data to ensure only data the anonymous token is privileged to see is shown
this.resetStore();
this.token.reset();
}
@action
verifyToken() {
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
this.resetStore();
// Refetch the token and associated policies
this.get('token.fetchSelfTokenAndPolicies')
.perform()
.catch();
this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
});
},
() => {
this.set('token.secret', undefined);
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: true,
});
}
);
}
}