Fossil SCM
minor cleanups to how FossilAjaj stores its auth info.
Commit
fb55f2534d097615afc13bea97fb8377ad18102a
Parent
770f9da54a217d3…
2 files changed
+1
-1
+5
-7
+1
-1
| --- ajax/i-test/rhino-test.js | ||
| +++ ajax/i-test/rhino-test.js | ||
| @@ -137,11 +137,11 @@ | ||
| 137 | 137 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 138 | 138 | |
| 139 | 139 | function testAnonWiki(){ |
| 140 | 140 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 141 | 141 | beforeSend:function(req,opt){ |
| 142 | - assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.' ); | |
| 142 | + assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' ); | |
| 143 | 143 | }, |
| 144 | 144 | onResponse:function(resp,req){ |
| 145 | 145 | assertResponseOK(resp); |
| 146 | 146 | assert( (typeof [] === typeof resp.payload) && resp.payload.length, |
| 147 | 147 | "Wiki list seems to be okay."); |
| 148 | 148 |
| --- ajax/i-test/rhino-test.js | |
| +++ ajax/i-test/rhino-test.js | |
| @@ -137,11 +137,11 @@ | |
| 137 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 138 | |
| 139 | function testAnonWiki(){ |
| 140 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 141 | beforeSend:function(req,opt){ |
| 142 | assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.' ); |
| 143 | }, |
| 144 | onResponse:function(resp,req){ |
| 145 | assertResponseOK(resp); |
| 146 | assert( (typeof [] === typeof resp.payload) && resp.payload.length, |
| 147 | "Wiki list seems to be okay."); |
| 148 |
| --- ajax/i-test/rhino-test.js | |
| +++ ajax/i-test/rhino-test.js | |
| @@ -137,11 +137,11 @@ | |
| 137 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 138 | |
| 139 | function testAnonWiki(){ |
| 140 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 141 | beforeSend:function(req,opt){ |
| 142 | assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' ); |
| 143 | }, |
| 144 | onResponse:function(resp,req){ |
| 145 | assertResponseOK(resp); |
| 146 | assert( (typeof [] === typeof resp.payload) && resp.payload.length, |
| 147 | "Wiki list seems to be okay."); |
| 148 |
+5
-7
| --- ajax/js/fossil-ajaj.js | ||
| +++ ajax/js/fossil-ajaj.js | ||
| @@ -40,21 +40,21 @@ | ||
| 40 | 40 | path part of the URL, e.g. /json/stat, payload is a request-specific |
| 41 | 41 | value type (may often be null/undefined). ajajOpt is an optional object |
| 42 | 42 | holding WhAjaj.sendRequest()-compatible options. |
| 43 | 43 | |
| 44 | 44 | This function constructs a Fossil/JSON request envelope based |
| 45 | - on the given arguments and adds this.authToken and a requestId | |
| 45 | + on the given arguments and adds this.auth.authToken and a requestId | |
| 46 | 46 | to it. |
| 47 | 47 | */ |
| 48 | 48 | FossilAjaj.prototype.sendCommand = function(command, payload, ajajOpt) { |
| 49 | 49 | var req; |
| 50 | 50 | ajajOpt = ajajOpt || {}; |
| 51 | - if(payload || this.authToken || ajajOpt.jsonp) { | |
| 51 | + if(payload || (this.auth && this.auth.authToken) || ajajOpt.jsonp) { | |
| 52 | 52 | req = { |
| 53 | 53 | payload:payload, |
| 54 | 54 | requestId:('function' === typeof this.generateRequestId) ? this.generateRequestId() : undefined, |
| 55 | - authToken:this.authToken || undefined, | |
| 55 | + authToken:(this.auth ? this.auth.authToken : undefined), | |
| 56 | 56 | jsonp:('string' === typeof ajajOpt.jsonp) ? ajajOpt.jsonp : undefined |
| 57 | 57 | }; |
| 58 | 58 | } |
| 59 | 59 | ajajOpt.method = req ? 'POST' : 'GET'; |
| 60 | 60 | // just for debuggering: ajajOpt.method = 'POST'; if(!req) req={}; |
| @@ -66,11 +66,11 @@ | ||
| 66 | 66 | Sends a login request to the back-end. |
| 67 | 67 | |
| 68 | 68 | ajajOpt is an optional configuration object suitable for passing |
| 69 | 69 | to sendCommand(). |
| 70 | 70 | |
| 71 | - After the response returns, this.authToken will be | |
| 71 | + After the response returns, this.auth will be | |
| 72 | 72 | set to the response payload. |
| 73 | 73 | |
| 74 | 74 | If name === 'anonymous' (the default if none is passed in) then this |
| 75 | 75 | function ignores the pw argument and must make two requests - the first |
| 76 | 76 | one gets the captcha code and the second one submits it. |
| @@ -95,11 +95,10 @@ | ||
| 95 | 95 | var oldOnResponse = ajajOpt.onResponse; |
| 96 | 96 | ajajOpt.onResponse = function(resp,req) { |
| 97 | 97 | var thisOpt = this; |
| 98 | 98 | //alert('login response:\n'+WhAjaj.stringify(resp)); |
| 99 | 99 | if( resp && resp.payload ) { |
| 100 | - /*deprecated*/self.authToken = resp.payload.authToken; | |
| 101 | 100 | //self.userName = resp.payload.name; |
| 102 | 101 | //self.capabilities = resp.payload.capabilities; |
| 103 | 102 | self.auth = resp.payload; |
| 104 | 103 | } |
| 105 | 104 | if( WhAjaj.isFunction( self.onLogin ) ){ |
| @@ -140,20 +139,19 @@ | ||
| 140 | 139 | ajajOpt is an optional configuration object suitable for passing |
| 141 | 140 | to sendCommand(). |
| 142 | 141 | |
| 143 | 142 | If this object has an onLogout() function it is called (with |
| 144 | 143 | no arguments) before the onResponse() handler is called. |
| 145 | - IFF the response succeeds then this.authToken is unset. | |
| 144 | + IFF the response succeeds then this.auth is unset. | |
| 146 | 145 | */ |
| 147 | 146 | FossilAjaj.prototype.logout = function(ajajOpt) { |
| 148 | 147 | var self = this; |
| 149 | 148 | ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} ); |
| 150 | 149 | var oldOnResponse = ajajOpt.onResponse; |
| 151 | 150 | ajajOpt.onResponse = function(resp,req) { |
| 152 | 151 | var thisOpt = this; |
| 153 | 152 | if( resp && !resp.payload ){ |
| 154 | - delete self.authToken; | |
| 155 | 153 | delete self.auth; |
| 156 | 154 | } |
| 157 | 155 | if( WhAjaj.isFunction( self.onLogout ) ){ |
| 158 | 156 | try{ self.onLogout(); } |
| 159 | 157 | catch(e){} |
| 160 | 158 |
| --- ajax/js/fossil-ajaj.js | |
| +++ ajax/js/fossil-ajaj.js | |
| @@ -40,21 +40,21 @@ | |
| 40 | path part of the URL, e.g. /json/stat, payload is a request-specific |
| 41 | value type (may often be null/undefined). ajajOpt is an optional object |
| 42 | holding WhAjaj.sendRequest()-compatible options. |
| 43 | |
| 44 | This function constructs a Fossil/JSON request envelope based |
| 45 | on the given arguments and adds this.authToken and a requestId |
| 46 | to it. |
| 47 | */ |
| 48 | FossilAjaj.prototype.sendCommand = function(command, payload, ajajOpt) { |
| 49 | var req; |
| 50 | ajajOpt = ajajOpt || {}; |
| 51 | if(payload || this.authToken || ajajOpt.jsonp) { |
| 52 | req = { |
| 53 | payload:payload, |
| 54 | requestId:('function' === typeof this.generateRequestId) ? this.generateRequestId() : undefined, |
| 55 | authToken:this.authToken || undefined, |
| 56 | jsonp:('string' === typeof ajajOpt.jsonp) ? ajajOpt.jsonp : undefined |
| 57 | }; |
| 58 | } |
| 59 | ajajOpt.method = req ? 'POST' : 'GET'; |
| 60 | // just for debuggering: ajajOpt.method = 'POST'; if(!req) req={}; |
| @@ -66,11 +66,11 @@ | |
| 66 | Sends a login request to the back-end. |
| 67 | |
| 68 | ajajOpt is an optional configuration object suitable for passing |
| 69 | to sendCommand(). |
| 70 | |
| 71 | After the response returns, this.authToken will be |
| 72 | set to the response payload. |
| 73 | |
| 74 | If name === 'anonymous' (the default if none is passed in) then this |
| 75 | function ignores the pw argument and must make two requests - the first |
| 76 | one gets the captcha code and the second one submits it. |
| @@ -95,11 +95,10 @@ | |
| 95 | var oldOnResponse = ajajOpt.onResponse; |
| 96 | ajajOpt.onResponse = function(resp,req) { |
| 97 | var thisOpt = this; |
| 98 | //alert('login response:\n'+WhAjaj.stringify(resp)); |
| 99 | if( resp && resp.payload ) { |
| 100 | /*deprecated*/self.authToken = resp.payload.authToken; |
| 101 | //self.userName = resp.payload.name; |
| 102 | //self.capabilities = resp.payload.capabilities; |
| 103 | self.auth = resp.payload; |
| 104 | } |
| 105 | if( WhAjaj.isFunction( self.onLogin ) ){ |
| @@ -140,20 +139,19 @@ | |
| 140 | ajajOpt is an optional configuration object suitable for passing |
| 141 | to sendCommand(). |
| 142 | |
| 143 | If this object has an onLogout() function it is called (with |
| 144 | no arguments) before the onResponse() handler is called. |
| 145 | IFF the response succeeds then this.authToken is unset. |
| 146 | */ |
| 147 | FossilAjaj.prototype.logout = function(ajajOpt) { |
| 148 | var self = this; |
| 149 | ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} ); |
| 150 | var oldOnResponse = ajajOpt.onResponse; |
| 151 | ajajOpt.onResponse = function(resp,req) { |
| 152 | var thisOpt = this; |
| 153 | if( resp && !resp.payload ){ |
| 154 | delete self.authToken; |
| 155 | delete self.auth; |
| 156 | } |
| 157 | if( WhAjaj.isFunction( self.onLogout ) ){ |
| 158 | try{ self.onLogout(); } |
| 159 | catch(e){} |
| 160 |
| --- ajax/js/fossil-ajaj.js | |
| +++ ajax/js/fossil-ajaj.js | |
| @@ -40,21 +40,21 @@ | |
| 40 | path part of the URL, e.g. /json/stat, payload is a request-specific |
| 41 | value type (may often be null/undefined). ajajOpt is an optional object |
| 42 | holding WhAjaj.sendRequest()-compatible options. |
| 43 | |
| 44 | This function constructs a Fossil/JSON request envelope based |
| 45 | on the given arguments and adds this.auth.authToken and a requestId |
| 46 | to it. |
| 47 | */ |
| 48 | FossilAjaj.prototype.sendCommand = function(command, payload, ajajOpt) { |
| 49 | var req; |
| 50 | ajajOpt = ajajOpt || {}; |
| 51 | if(payload || (this.auth && this.auth.authToken) || ajajOpt.jsonp) { |
| 52 | req = { |
| 53 | payload:payload, |
| 54 | requestId:('function' === typeof this.generateRequestId) ? this.generateRequestId() : undefined, |
| 55 | authToken:(this.auth ? this.auth.authToken : undefined), |
| 56 | jsonp:('string' === typeof ajajOpt.jsonp) ? ajajOpt.jsonp : undefined |
| 57 | }; |
| 58 | } |
| 59 | ajajOpt.method = req ? 'POST' : 'GET'; |
| 60 | // just for debuggering: ajajOpt.method = 'POST'; if(!req) req={}; |
| @@ -66,11 +66,11 @@ | |
| 66 | Sends a login request to the back-end. |
| 67 | |
| 68 | ajajOpt is an optional configuration object suitable for passing |
| 69 | to sendCommand(). |
| 70 | |
| 71 | After the response returns, this.auth will be |
| 72 | set to the response payload. |
| 73 | |
| 74 | If name === 'anonymous' (the default if none is passed in) then this |
| 75 | function ignores the pw argument and must make two requests - the first |
| 76 | one gets the captcha code and the second one submits it. |
| @@ -95,11 +95,10 @@ | |
| 95 | var oldOnResponse = ajajOpt.onResponse; |
| 96 | ajajOpt.onResponse = function(resp,req) { |
| 97 | var thisOpt = this; |
| 98 | //alert('login response:\n'+WhAjaj.stringify(resp)); |
| 99 | if( resp && resp.payload ) { |
| 100 | //self.userName = resp.payload.name; |
| 101 | //self.capabilities = resp.payload.capabilities; |
| 102 | self.auth = resp.payload; |
| 103 | } |
| 104 | if( WhAjaj.isFunction( self.onLogin ) ){ |
| @@ -140,20 +139,19 @@ | |
| 139 | ajajOpt is an optional configuration object suitable for passing |
| 140 | to sendCommand(). |
| 141 | |
| 142 | If this object has an onLogout() function it is called (with |
| 143 | no arguments) before the onResponse() handler is called. |
| 144 | IFF the response succeeds then this.auth is unset. |
| 145 | */ |
| 146 | FossilAjaj.prototype.logout = function(ajajOpt) { |
| 147 | var self = this; |
| 148 | ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} ); |
| 149 | var oldOnResponse = ajajOpt.onResponse; |
| 150 | ajajOpt.onResponse = function(resp,req) { |
| 151 | var thisOpt = this; |
| 152 | if( resp && !resp.payload ){ |
| 153 | delete self.auth; |
| 154 | } |
| 155 | if( WhAjaj.isFunction( self.onLogout ) ){ |
| 156 | try{ self.onLogout(); } |
| 157 | catch(e){} |
| 158 |