Skip to content

Commit

Permalink
Login/Logout action POST to Spring security check.
Browse files Browse the repository at this point in the history
  • Loading branch information
François Prunayre committed Dec 10, 2013
1 parent ea2eaa1 commit 92cc0b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,29 @@ GeoNetwork.Catalogue = Ext.extend(Ext.util.Observable, {
return false;
}
},

postToUrl: function (path, params, method) {
method = method || "post"; // Set method to post by default if not specified.

// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);

for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);

form.appendChild(hiddenField);
}
}

document.body.appendChild(form);
form.submit();
},
/** api: method[login]
* :param username: ``String`` The user name
* :param password: ``String`` The password for the user
Expand Down Expand Up @@ -1214,21 +1236,23 @@ GeoNetwork.Catalogue = Ext.extend(Ext.util.Observable, {
if (this.node) {
params.node = this.node;
}
OpenLayers.Request.POST({
url: this.services.login,
data: OpenLayers.Util.getParameterString(params),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function(response){
app.isLoggedIn(); // will get the user information and trigger after login event
},
failure: function(response){
app.identifiedUser = undefined;
app.onAfterBadLogin();
// TODO : Get Exception from GeoNetwork
}
});
params.redirectUrl = '/..' + location.pathname;
this.postToUrl(this.services.login, params, 'POST');
// OpenLayers.Request.POST({
// url: this.services.login,
// data: OpenLayers.Util.getParameterString(params),
// headers: {
// "Content-Type": "application/x-www-form-urlencoded"
// },
// success: function(response){
// app.isLoggedIn(); // will get the user information and trigger after login event
// },
// failure: function(response){
// app.identifiedUser = undefined;
// app.onAfterBadLogin();
// // TODO : Get Exception from GeoNetwork
// }
// });
}
},
/** api: method[logout]
Expand All @@ -1240,19 +1264,23 @@ GeoNetwork.Catalogue = Ext.extend(Ext.util.Observable, {
if (this.casEnabled) {
window.location = this.services.logout;
} else {
var app = this;
OpenLayers.Request.GET({
url: this.services.logout,
async: false, // logout does not seem to work when it is asynchronous request
success: function(response){
app.identifiedUser = undefined;
app.onAfterLogout();
},
failure: function(response){
app.identifiedUser = undefined;
app.onAfterBadLogout();
}
});
var params = {};
params.redirectUrl = '/..' + location.pathname;
this.postToUrl(this.services.logout, params, 'POST');

// var app = this;
// OpenLayers.Request.GET({
// url: this.services.logout,
// async: false, // logout does not seem to work when it is asynchronous request
// success: function(response){
// app.identifiedUser = undefined;
// app.onAfterLogout();
// },
// failure: function(response){
// app.identifiedUser = undefined;
// app.onAfterBadLogout();
// }
// });
}
},
/** api: method[checkError]
Expand Down
6 changes: 3 additions & 3 deletions web-ui/src/main/resources/catalog/js/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
};

$scope.nodeChangeRedirect = function(redirectTo) {
$http.get('../../j_spring_security_logout')
$http.get('../../j_spring_security_logout')
.success(function(data) {
window.location.href = redirectTo;
});
};
});
};

initForm();

Expand Down

0 comments on commit 92cc0b3

Please sign in to comment.