Fossil SCM

minor cleanups to how FossilAjaj stores its auth info.

stephan 2011-10-09 11:09 UTC json-multitag-test
Commit fb55f2534d097615afc13bea97fb8377ad18102a
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -137,11 +137,11 @@
137137
testAnonymousLogin.description = 'Perform anonymous login.';
138138
139139
function testAnonWiki(){
140140
TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
141141
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.' );
143143
},
144144
onResponse:function(resp,req){
145145
assertResponseOK(resp);
146146
assert( (typeof [] === typeof resp.payload) && resp.payload.length,
147147
"Wiki list seems to be okay.");
148148
--- 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
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -40,21 +40,21 @@
4040
path part of the URL, e.g. /json/stat, payload is a request-specific
4141
value type (may often be null/undefined). ajajOpt is an optional object
4242
holding WhAjaj.sendRequest()-compatible options.
4343
4444
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
4646
to it.
4747
*/
4848
FossilAjaj.prototype.sendCommand = function(command, payload, ajajOpt) {
4949
var req;
5050
ajajOpt = ajajOpt || {};
51
- if(payload || this.authToken || ajajOpt.jsonp) {
51
+ if(payload || (this.auth && this.auth.authToken) || ajajOpt.jsonp) {
5252
req = {
5353
payload:payload,
5454
requestId:('function' === typeof this.generateRequestId) ? this.generateRequestId() : undefined,
55
- authToken:this.authToken || undefined,
55
+ authToken:(this.auth ? this.auth.authToken : undefined),
5656
jsonp:('string' === typeof ajajOpt.jsonp) ? ajajOpt.jsonp : undefined
5757
};
5858
}
5959
ajajOpt.method = req ? 'POST' : 'GET';
6060
// just for debuggering: ajajOpt.method = 'POST'; if(!req) req={};
@@ -66,11 +66,11 @@
6666
Sends a login request to the back-end.
6767
6868
ajajOpt is an optional configuration object suitable for passing
6969
to sendCommand().
7070
71
- After the response returns, this.authToken will be
71
+ After the response returns, this.auth will be
7272
set to the response payload.
7373
7474
If name === 'anonymous' (the default if none is passed in) then this
7575
function ignores the pw argument and must make two requests - the first
7676
one gets the captcha code and the second one submits it.
@@ -95,11 +95,10 @@
9595
var oldOnResponse = ajajOpt.onResponse;
9696
ajajOpt.onResponse = function(resp,req) {
9797
var thisOpt = this;
9898
//alert('login response:\n'+WhAjaj.stringify(resp));
9999
if( resp && resp.payload ) {
100
- /*deprecated*/self.authToken = resp.payload.authToken;
101100
//self.userName = resp.payload.name;
102101
//self.capabilities = resp.payload.capabilities;
103102
self.auth = resp.payload;
104103
}
105104
if( WhAjaj.isFunction( self.onLogin ) ){
@@ -140,20 +139,19 @@
140139
ajajOpt is an optional configuration object suitable for passing
141140
to sendCommand().
142141
143142
If this object has an onLogout() function it is called (with
144143
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.
146145
*/
147146
FossilAjaj.prototype.logout = function(ajajOpt) {
148147
var self = this;
149148
ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} );
150149
var oldOnResponse = ajajOpt.onResponse;
151150
ajajOpt.onResponse = function(resp,req) {
152151
var thisOpt = this;
153152
if( resp && !resp.payload ){
154
- delete self.authToken;
155153
delete self.auth;
156154
}
157155
if( WhAjaj.isFunction( self.onLogout ) ){
158156
try{ self.onLogout(); }
159157
catch(e){}
160158
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button