added a xul stash loading method. forcing authtoken to come from xul stash when...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Dec 2006 16:10:12 +0000 (16:10 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Dec 2006 16:10:12 +0000 (16:10 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6673 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/RemoteRequest.js
Open-ILS/web/opac/common/js/opac_utils.js

index cd88876..e531786 100644 (file)
@@ -218,8 +218,6 @@ RemoteRequest.prototype.send = function(blocking) {
 
        if(this.cancelled) return;
 
-
-
        /* determine the xmlhttp server dynamically */
        var url = location.protocol + "//" + location.host + "/" + XML_HTTP_GATEWAY;
 
@@ -237,8 +235,6 @@ RemoteRequest.prototype.send = function(blocking) {
        var data = null;
        if( this.type == 'GET' ) url +=  "?" + this.param_string; 
 
-       if(isXUL() && this.secure ) dump('SECURE = true\n');
-
        this.url = url;
 
        try {
@@ -260,7 +256,7 @@ RemoteRequest.prototype.send = function(blocking) {
        try {
                var auth;
                try { auth = cookieManager.read(COOKIE_SES) } catch(ee) {}
-               if( !auth && isXUL() ) auth = ses();
+               if( isXUL() ) auth = fetchXULStash().session.key;
                if( auth ) 
                        this.xmlhttp.setRequestHeader('X-OILS-Authtoken', auth);
 
@@ -299,7 +295,7 @@ RemoteRequest.prototype.getResultObject = function() {
        var status = null;
        this.event(null);
 
-       /* DEBUG 
+       /*
        try {
                dump(this.url + '?' + this.param_string + '\n' +
                        'Returned with \n\tstatus = ' + this.xmlhttp.status + 
@@ -322,6 +318,8 @@ RemoteRequest.prototype.getResultObject = function() {
 
        var text = this.xmlhttp.responseText;
 
+       //try{if(getDebug()) _debug('response: ' + text + '\n')}catch(e){}
+
        if(text == "" || text == " " || text == null) {
                try { dump('dbg: Request returned no text!\n'); } catch(E) {}
                if(isXUL()) 
@@ -372,3 +370,19 @@ RemoteRequest.prototype.addParam = function(param) {
        this.param_string += "&param=" + string;
 }
 
+function fetchXULStash() {
+       if( isXUL() ) {
+               try {
+                       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+                       var __OILS = new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
+                       var data_cache = new __OILS( );
+                       return data_cache.wrappedJSObject.OpenILS.prototype.data;
+       
+               } catch(E) {
+                       _debug('Error in OpenILS.data._debug_stash(): ' + js2JSON(E) );
+               }
+       }
+       return {};
+}
+
+
index 47c9e0c..ca49b74 100644 (file)
@@ -449,6 +449,11 @@ function buildSearchLink(type, string, linknode, trunc) {
        linknode.setAttribute("href", buildOPACLink(args));
 }
 
+function setSessionCookie(ses) {
+       cookieManager.write(COOKIE_SES, ses, -1);
+}
+
+
 
 /* ----------------------------------------------------------------------- */
 /* user session handling */
@@ -459,7 +464,11 @@ function buildSearchLink(type, string, linknode, trunc) {
        if ses != G.user.session, we also force a grab */
 function grabUser(ses, force) {
 
-       if(!ses && isXUL()) ses = xulG['authtoken'];
+       if(!ses && isXUL()) {
+               stash = fetchXULStash();
+               ses = stash.session.key
+               _debug("stash auth token = " + ses);
+       }
 
        if(!ses) {
                ses = cookieManager.read(COOKIE_SES);
@@ -491,7 +500,7 @@ function grabUser(ses, force) {
        G.user = user;
        G.user.fleshed = false;
        G.user.session = ses;
-       cookieManager.write(COOKIE_SES, ses, -1);
+       setSessionCookie(ses);
 
        grabUserPrefs();
        if(G.user.prefs['opac.hits_per_page'])
@@ -541,7 +550,7 @@ function grabFleshedUser() {
        G.user.session = ses;
        G.user.fleshed = true;
 
-       cookieManager.write(COOKIE_SES, ses, '+1y'); /*  update the cookie */
+       setSessionCookie(ses);
        return G.user;
 }