github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/controllers/settings/tokens.js (about) 1 import { inject as service } from '@ember/service'; 2 import { reads } from '@ember/object/computed'; 3 import Controller from '@ember/controller'; 4 import { getOwner } from '@ember/application'; 5 import { alias } from '@ember/object/computed'; 6 7 export default Controller.extend({ 8 token: service(), 9 system: service(), 10 store: service(), 11 12 secret: reads('token.secret'), 13 14 tokenIsValid: false, 15 tokenIsInvalid: false, 16 tokenRecord: alias('token.selfToken'), 17 18 resetStore() { 19 this.store.unloadAll(); 20 }, 21 22 actions: { 23 clearTokenProperties() { 24 this.token.setProperties({ 25 secret: undefined, 26 }); 27 this.setProperties({ 28 tokenIsValid: false, 29 tokenIsInvalid: false, 30 }); 31 this.resetStore(); 32 this.token.reset(); 33 }, 34 35 verifyToken() { 36 const { secret } = this; 37 const TokenAdapter = getOwner(this).lookup('adapter:token'); 38 39 this.set('token.secret', secret); 40 41 TokenAdapter.findSelf().then( 42 () => { 43 // Clear out all data to ensure only data the new token is privileged to 44 // see is shown 45 this.system.reset(); 46 this.resetStore(); 47 48 // Refetch the token and associated policies 49 this.get('token.fetchSelfTokenAndPolicies') 50 .perform() 51 .catch(); 52 53 this.setProperties({ 54 tokenIsValid: true, 55 tokenIsInvalid: false, 56 }); 57 }, 58 () => { 59 this.set('token.secret', undefined); 60 this.setProperties({ 61 tokenIsValid: false, 62 tokenIsInvalid: true, 63 }); 64 } 65 ); 66 }, 67 }, 68 });