diff --git a/org.adempiere.base/src/org/compiere/model/MUser.java b/org.adempiere.base/src/org/compiere/model/MUser.java index fa6a3b5f47..c376f53633 100644 --- a/org.adempiere.base/src/org/compiere/model/MUser.java +++ b/org.adempiere.base/src/org/compiere/model/MUser.java @@ -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; + } } }