fix secure option usage for cookie

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1425003 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-21 16:26:14 +00:00
parent 4d71b675e7
commit 88979e943a
2 changed files with 45 additions and 23 deletions

View File

@ -28,34 +28,56 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
* @param user see user.js
*/
reccordLoginCookie=function(user) {
var path = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.timeout");
var path = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.path");
path = path ? path : "/";
var domain = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.domain");
var secure = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.secure");
$.cookie('archiva_login', ko.toJSON(user),
{
expires: Number(window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.timeout")),
path: path,
domain: domain,
secure: secure
}
);
var expires= Number(window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.timeout"));
var userJson=ko.toJSON(user);
$.log("reccordLoginCookie:expires:"+expires+",path:"+path+",domain:"+domain+",secure:"+secure+",user:"+userJson);
var options = null;
if (secure == 'true'){
options = {
expires: expires,
path: path,
domain: domain,
secure: secure
}
}else {
options = {
expires: expires,
path: path,
domain: domain
}
}
$.cookie('archiva_login', userJson,options);
};
getUserFromLoginCookie=function(){
var cookieContent=$.cookie('archiva_login');
$.log("archiva_login cookie content:"+cookieContent);
return $.parseJSON(cookieContent);
var user = $.parseJSON(cookieContent);
if(!user){
return null;
}
var kUser = new User(user.username, user.password, user.confirmPassword,user.fullName,user.email,user.permanent,user.validated,
user.timestampAccountCreation,user.timestampLastLogin,user.timestampLastPasswordChange,user.locked,
user.passwordChangeRequired,null,user.readOnly,user.userManagerId)
kUser.rememberme(user.rememberme);
return kUser;
};
deleteLoginCookie=function(){
$.cookie('archiva_login', null,{ expires: 7, path: '/' });
};
logout=function(doScreenChange){
//deleteLoginCookie();
var user = getUserFromLoginCookie();
if(user){
user.logged=false;
@ -719,7 +741,7 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
};
userLoggedCallbackFn=function(user){
$.log("userLoggedCallbackFn:"+ (user?user.username:null));
$.log("userLoggedCallbackFn:"+ (user?user.username():null));
var loginLink=$("#login-link");
var registerLink=$("#register-link");
var changePasswordLink=$("#change-password-link");

View File

@ -82,7 +82,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
this.userManagerId=userManagerId;
this.rememberme=false;
this.rememberme=ko.observable(false);
this.logged=false;
@ -356,10 +356,10 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
var user=getUserFromLoginCookie();
if(user){
$.log("found user in cookie rememberme:"+(user.rememberme));
if(user.rememberme){
$("#user-login-form-username" ).val(user.username);
$("#user-login-form-password" ).val(user.password);
$.log("found user in cookie rememberme:"+(user.rememberme()));
if(user.rememberme()){
$("#user-login-form-username" ).val(user.username());
$("#user-login-form-password" ).val(user.password());
$("#user-login-form-rememberme" ).attr("checked","true");
}
} else {
@ -429,11 +429,11 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
}
// FIXME check validated
user.rememberme=window.redbackModel.rememberme;
if(user.rememberme){
user.rememberme(window.redbackModel.rememberme);
if(user.rememberme()){
user.password(window.redbackModel.password);
}
$.log("user.rememberme:"+(user.rememberme));
$.log("user.rememberme:"+(user.rememberme()));
reccordLoginCookie(user);
window.user=user;
$("#login-link").hide();