[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
This commit is contained in:
Olivier Lamy 2014-05-23 11:22:18 +10:00
parent b87e972bff
commit fd36bced75
3 changed files with 110 additions and 90 deletions

View File

@ -35,12 +35,12 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
var expires= Number(window.cookieInformation.timeout); 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.timestampAccountCreation,user.timestampLastLogin,user.timestampLastPasswordChange,user.locked,
user.passwordChangeRequired,null,user.readOnly,user.userManagerId); user.passwordChangeRequired,null,user.readOnly,user.userManagerId);
kUser.rememberme(user.rememberme()); kUser.rememberme(user.rememberme());
var userJson=ko.toJSON(kUser); var userJson=ko.toJSON(kUser);
$.log("reccordLoginCookie:"+userJson);
$.log("reccordLoginCookie:expires:"+expires+",path:"+path+",domain:"+domain+",secure:"+secure+",user:"+userJson); $.log("reccordLoginCookie:expires:"+expires+",path:"+path+",domain:"+domain+",secure:"+secure+",user:"+userJson);
var options = null; var options = null;
@ -64,12 +64,12 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
getUserFromLoginCookie=function(){ getUserFromLoginCookie=function(){
var cookieContent=$.cookie('archiva_login'); var cookieContent=$.cookie('archiva_login');
$.log("archiva_login cookie content:"+cookieContent); $.log("archiva_getUserFromLoginCookie cookie content:"+cookieContent);
var user = $.parseJSON(cookieContent); var user = $.parseJSON(cookieContent);
if(!user){ if(!user){
return null; 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.timestampAccountCreation,user.timestampLastLogin,user.timestampLastPasswordChange,user.locked,
user.passwordChangeRequired,null,user.readOnly,user.userManagerId); user.passwordChangeRequired,null,user.readOnly,user.userManagerId);
@ -82,7 +82,7 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
logout=function(){ logout=function(){
var user = getUserFromLoginCookie(); var user = window.user;//getUserFromLoginCookie();
if(user){ if(user){
user.logged=false; user.logged=false;
reccordLoginCookie(user); reccordLoginCookie(user);
@ -883,6 +883,97 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
window.sammyArchivaApplication.run(); 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){ drawQuickSearchAutocomplete=function(selector){

View File

@ -46,8 +46,15 @@ function(jquery,utils,jqueryValidate,jqueryJson,ko) {
success: function(data) { success: function(data) {
$.log("isLogged:"+data); $.log("isLogged:"+data);
var user = data ? mapUser(data):null; var user = data ? mapUser(data):null;
var cookieUser = getUserFromLoginCookie();
window.user=user; window.user=user;
if(user){ if(user){
if (cookieUser!=null){
$.log("cookieUser:"+cookieUser.password());
user.password(cookieUser.password());
user.rememberme(cookieUser.rememberme());
}
reccordLoginCookie(user); reccordLoginCookie(user);
} }
$.log("userLogged:"+(user!=null)); $.log("userLogged:"+(user!=null));

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * 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) { function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
/** /**
@ -208,7 +208,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
} else { } else {
return this.update(); return this.update();
} }
} };
this.updateAssignedRoles=function(){ this.updateAssignedRoles=function(){
$.log("user#updateAssignedRoles"); $.log("user#updateAssignedRoles");
@ -223,7 +223,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
displaySuccessMessage($.i18n.prop("user.roles.updated",curUser.username())); displaySuccessMessage($.i18n.prop("user.roles.updated",curUser.username()));
} }
}); });
} };
this.lock=function(){ this.lock=function(){
this.locked(true); this.locked(true);
@ -236,7 +236,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
curUser.modified(false); curUser.modified(false);
} }
}); });
} };
this.unlock=function(){ this.unlock=function(){
this.locked(false); this.locked(false);
@ -249,7 +249,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
curUser.modified(false); curUser.modified(false);
} }
}); });
} };
// value is boolean // value is boolean
this.changePasswordChangeRequired=function(value){ this.changePasswordChangeRequired=function(value){
@ -396,85 +396,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
passwordReset(); 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){ resetPasswordForm=function(key){
$.log("resetPasswordForm:"+key); $.log("resetPasswordForm:"+key);
@ -619,7 +541,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
complete: completeCallbackFn complete: completeCallbackFn
}); });
} };
/** /**
* *