IDEMPIERE-1672 create a user with name same exist user, make exist user can't log-in

This commit is contained in:
Carlos Ruiz 2016-09-04 12:08:10 +02:00
parent 9dccd57617
commit 89ba2d67e3
1 changed files with 28 additions and 14 deletions

View File

@ -887,20 +887,34 @@ public class MUser extends X_AD_User
if (newRecord || super.getValue() == null || is_ValueChanged("Value"))
setValue(super.getValue());
boolean email_login = MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false);
if (email_login && getPassword() != null && getPassword().length() > 0) {
// email is mandatory for users with password
if (getEMail() == null || getEMail().length() == 0) {
log.saveError("SaveError", Msg.getMsg(getCtx(), "FillMandatory") + Msg.getElement(getCtx(), COLUMNNAME_EMail) + " - " + toString());
return false;
}
// email with password must be unique on the same tenant
int cnt = DB.getSQLValue(get_TrxName(),
"SELECT COUNT(*) FROM AD_User WHERE Password IS NOT NULL AND EMail=? AND AD_Client_ID=? AND AD_User_ID!=?",
getEMail(), getAD_Client_ID(), getAD_User_ID());
if (cnt > 0) {
log.saveError("SaveError", Msg.getMsg(getCtx(), DBException.SAVE_ERROR_NOT_UNIQUE_MSG, true) + Msg.getElement(getCtx(), COLUMNNAME_EMail));
return false;
if (getPassword() != null && getPassword().length() > 0) {
boolean email_login = MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false);
if (email_login) {
// email is mandatory for users with password
if (getEMail() == null || getEMail().length() == 0) {
log.saveError("SaveError", Msg.getMsg(getCtx(), "FillMandatory") + Msg.getElement(getCtx(), COLUMNNAME_EMail) + " - " + toString());
return false;
}
// email with password must be unique on the same tenant
int cnt = DB.getSQLValue(get_TrxName(),
"SELECT COUNT(*) FROM AD_User WHERE Password IS NOT NULL AND EMail=? AND AD_Client_ID=? AND AD_User_ID!=?",
getEMail(), getAD_Client_ID(), getAD_User_ID());
if (cnt > 0) {
log.saveError("SaveError", Msg.getMsg(getCtx(), DBException.SAVE_ERROR_NOT_UNIQUE_MSG, true) + Msg.getElement(getCtx(), COLUMNNAME_EMail));
return false;
}
} else {
// IDEMPIERE-1672 check duplicate name in client
String nameToValidate = getLDAPUser();
if (Util.isEmpty(nameToValidate))
nameToValidate = getName();
int cnt = DB.getSQLValue(get_TrxName(),
"SELECT COUNT(*) FROM AD_User WHERE Password IS NOT NULL AND COALESCE(LDAPUser,Name)=? AND AD_Client_ID=? AND AD_User_ID!=?",
nameToValidate, getAD_Client_ID(), getAD_User_ID());
if (cnt > 0) {
log.saveError("SaveError", Msg.getMsg(getCtx(), DBException.SAVE_ERROR_NOT_UNIQUE_MSG, true) + Msg.getElement(getCtx(), COLUMNNAME_Name) + " / " + Msg.getElement(getCtx(), COLUMNNAME_LDAPUser));
return false;
}
}
}