github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/controllers/settings/tokens.js (about) 1 import Ember from 'ember'; 2 3 const { Controller, inject, computed, getOwner } = Ember; 4 5 export default Controller.extend({ 6 token: inject.service(), 7 store: inject.service(), 8 9 secret: computed.reads('token.secret'), 10 11 tokenIsValid: false, 12 tokenIsInvalid: false, 13 tokenRecord: null, 14 15 resetStore() { 16 this.get('store').unloadAll(); 17 }, 18 19 actions: { 20 clearTokenProperties() { 21 this.get('token').setProperties({ 22 secret: undefined, 23 }); 24 this.setProperties({ 25 tokenIsValid: false, 26 tokenIsInvalid: false, 27 tokenRecord: null, 28 }); 29 this.resetStore(); 30 }, 31 32 verifyToken() { 33 const { secret } = this.getProperties('secret', 'accessor'); 34 const TokenAdapter = getOwner(this).lookup('adapter:token'); 35 36 this.set('token.secret', secret); 37 38 TokenAdapter.findSelf().then( 39 token => { 40 // Capture the token ID before clearing the store 41 const tokenId = token.get('id'); 42 43 // Clear out all data to ensure only data the new token is privileged to 44 // see is shown 45 this.resetStore(); 46 47 // Immediately refetch the token now that the store is empty 48 const newToken = this.get('store').findRecord('token', tokenId); 49 50 this.setProperties({ 51 tokenIsValid: true, 52 tokenIsInvalid: false, 53 tokenRecord: newToken, 54 }); 55 }, 56 () => { 57 this.set('token.secret', undefined); 58 this.setProperties({ 59 tokenIsValid: false, 60 tokenIsInvalid: true, 61 tokenRecord: null, 62 }); 63 } 64 ); 65 }, 66 }, 67 });