diff options
author | Olivier Lamy <olamy@apache.org> | 2014-05-23 11:22:18 +1000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-05-23 11:22:18 +1000 |
commit | fd36bced753e58846152bbd38971d30afc5797a1 (patch) | |
tree | b9770e421233d7ae240644b7a393a31d99bc7322 /archiva-modules | |
parent | b87e972bff1ee0b36f72aae3a038025827ad0927 (diff) | |
download | archiva-fd36bced753e58846152bbd38971d30afc5797a1.tar.gz archiva-fd36bced753e58846152bbd38971d30afc5797a1.zip |
[MRM-1841] "Remember me" not working
restore password storage in the cookie.
if remember activated and the cookie is available with a username/password an automatic login will be try
Diffstat (limited to 'archiva-modules')
3 files changed, 110 insertions, 90 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js index 00c2189fa..3fe2545f1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js @@ -35,12 +35,12 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa var expires= Number(window.cookieInformation.timeout); - var kUser = new User(user.username, null, user.confirmPassword,user.fullName,user.email,user.permanent,user.validated, + 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()); var userJson=ko.toJSON(kUser); - + $.log("reccordLoginCookie:"+userJson); $.log("reccordLoginCookie:expires:"+expires+",path:"+path+",domain:"+domain+",secure:"+secure+",user:"+userJson); var options = null; @@ -64,12 +64,12 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa getUserFromLoginCookie=function(){ var cookieContent=$.cookie('archiva_login'); - $.log("archiva_login cookie content:"+cookieContent); + $.log("archiva_getUserFromLoginCookie cookie content:"+cookieContent); var user = $.parseJSON(cookieContent); if(!user){ return null; } - var kUser = new User(user.username, null, user.confirmPassword,user.fullName,user.email,user.permanent,user.validated, + 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); @@ -82,7 +82,7 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa logout=function(){ - var user = getUserFromLoginCookie(); + var user = window.user;//getUserFromLoginCookie(); if(user){ user.logged=false; reccordLoginCookie(user); @@ -883,6 +883,97 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa window.sammyArchivaApplication.run(); + + var user = getUserFromLoginCookie(); + + $.log("found user:"+(user==null?"null":user.username()+":"+user.password()+":"+user.rememberme())); + + // if user has details as username and passowrd and rememberme is on just try to log it + if (user!=null&&user.username()!=null&&user.password()!=null&&user.rememberme()==true){ + window.redbackModel.rememberme=user.rememberme(); + window.redbackModel.password=user.password(); + loginCall(user.username(),user.password(),user.rememberme() + ,successLoginCallbackFn,errorLoginCallbackFn,completeLoginCallbackFn); + } + + }; + + + /** + * callback success function on rest login call. + * modal close and hide/show some links (login,logout,register...) + * @param result + */ + successLoginCallbackFn=function(result){ + + var logged = false; + if (result == null) { + logged = false; + } else { + if (result.username) { + logged = true; + } + } + if (logged == true) { + var user = mapUser(result); + + if (user.passwordChangeRequired()==true){ + changePasswordBox(true,false,user); + return; + } + // not really needed as an exception is returned but "ceintures et bretelles" as we say in French :-) + if (user.locked()==true){ + $.log("user locked"); + displayErrorMessage($.i18n.prop("account.locked")); + return; + } + + + $.log("window.redbackModel.rememberme:"+window.redbackModel.rememberme); + user.rememberme(window.redbackModel.rememberme); + if(user.rememberme()){ + user.password(window.redbackModel.password); + } + $.log("user.rememberme:"+(user.rememberme())); + reccordLoginCookie(user); + window.user=user; + $("#login-link").hide(); + $("#logout-link").show(); + $("#register-link").hide(); + $("#change-password-link").show(); + if (window.modalLoginWindow){ + window.modalLoginWindow.modal('hide'); + } + clearForm("#user-login-form"); + decorateMenuWithKarma(user); + $("#login-welcome" ).show(); + $("#welcome-label" ).html( $.i18n.prop("user.login.welcome",user.username())); + return; + } + var modalLoginErrMsg=$("#modal-login-err-message"); + modalLoginErrMsg.html($.i18n.prop("incorrect.username.password")); + modalLoginErrMsg.show(); + }; + + /** + * callback error function on rest login call. display error message + * @param result + */ + errorLoginCallbackFn= function(result) { + var obj = jQuery.parseJSON(result.responseText); + displayRedbackError(obj,"modal-login-err-message"); + $("#modal-login-err-message").show(); + }; + + /** + * callback complate function on rest login call. remove spinner from modal login box + * @param result + */ + completeLoginCallbackFn=function(){ + $("#modal-login-ok").button("reset"); + $("#small-spinner").remove(); + // force current screen reload to consider user karma + window.sammyArchivaApplication.refresh(); }; drawQuickSearchAutocomplete=function(selector){ diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/redback.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/redback.js index f3d177230..63153a045 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/redback.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/redback.js @@ -46,8 +46,15 @@ function(jquery,utils,jqueryValidate,jqueryJson,ko) { success: function(data) { $.log("isLogged:"+data); var user = data ? mapUser(data):null; + var cookieUser = getUserFromLoginCookie(); + window.user=user; if(user){ + if (cookieUser!=null){ + $.log("cookieUser:"+cookieUser.password()); + user.password(cookieUser.password()); + user.rememberme(cookieUser.rememberme()); + } reccordLoginCookie(user); } $.log("userLogged:"+(user!=null)); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/user.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/user.js index b40f5282e..039129c03 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/user.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/redback/user.js @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -define("redback.user",["jquery","utils","i18n","jquery.validate","knockout","knockout.simpleGrid","purl"], +define("redback.user",["jquery","utils","i18n","jquery.validate","knockout","knockout.simpleGrid","purl","archiva.main"], function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { /** @@ -208,7 +208,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { } else { return this.update(); } - } + }; this.updateAssignedRoles=function(){ $.log("user#updateAssignedRoles"); @@ -223,7 +223,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { displaySuccessMessage($.i18n.prop("user.roles.updated",curUser.username())); } }); - } + }; this.lock=function(){ this.locked(true); @@ -236,7 +236,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { curUser.modified(false); } }); - } + }; this.unlock=function(){ this.locked(false); @@ -249,7 +249,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { curUser.modified(false); } }); - } + }; // value is boolean this.changePasswordChangeRequired=function(value){ @@ -396,85 +396,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { passwordReset(); }); - } - - - /** - * callback success function on rest login call. - * modal close and hide/show some links (login,logout,register...) - * @param result - */ - var successLoginCallbackFn=function(result){ - - var logged = false; - if (result == null) { - logged = false; - } else { - if (result.username) { - logged = true; - } - } - if (logged == true) { - var user = mapUser(result); - - if (user.passwordChangeRequired()==true){ - changePasswordBox(true,false,user); - return; - } - // not really needed as an exception is returned but "ceintures et bretelles" as we say in French :-) - if (user.locked()==true){ - $.log("user locked"); - displayErrorMessage($.i18n.prop("account.locked")); - return; - } - - // FIXME check validated - $.log("window.redbackModel.rememberme:"+window.redbackModel.rememberme); - user.rememberme(window.redbackModel.rememberme); - if(user.rememberme()){ - user.password(window.redbackModel.password); - } - $.log("user.rememberme:"+(user.rememberme())); - reccordLoginCookie(user); - window.user=user; - $("#login-link").hide(); - $("#logout-link").show(); - $("#register-link").hide(); - $("#change-password-link").show(); - if (window.modalLoginWindow){ - window.modalLoginWindow.modal('hide'); - } - clearForm("#user-login-form"); - decorateMenuWithKarma(user); - $("#login-welcome" ).show(); - $("#welcome-label" ).html( $.i18n.prop("user.login.welcome",user.username())); - return; - } - var modalLoginErrMsg=$("#modal-login-err-message"); - modalLoginErrMsg.html($.i18n.prop("incorrect.username.password")); - modalLoginErrMsg.show(); - } - - /** - * callback error function on rest login call. display error message - * @param result - */ - var errorLoginCallbackFn= function(result) { - var obj = jQuery.parseJSON(result.responseText); - displayRedbackError(obj,"modal-login-err-message"); - $("#modal-login-err-message").show(); - } - - /** - * callback complate function on rest login call. remove spinner from modal login box - * @param result - */ - var completeLoginCallbackFn=function(){ - $("#modal-login-ok").button("reset"); - $("#small-spinner").remove(); - // force current screen reload to consider user karma - window.sammyArchivaApplication.refresh(); - } + }; resetPasswordForm=function(key){ $.log("resetPasswordForm:"+key); @@ -619,7 +541,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) { complete: completeCallbackFn }); - } + }; /** * |