IDEMPIERE-358 Login- how to make unique and safe / make it work with Select Role

This commit is contained in:
Carlos Ruiz 2012-08-13 18:56:28 -05:00
parent 85abedd47f
commit b92a635945
1 changed files with 32 additions and 20 deletions

View File

@ -26,6 +26,7 @@ package org.adempiere.webui.panel;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -53,6 +54,7 @@ import org.compiere.model.MSession;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.MSystem; import org.compiere.model.MSystem;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.model.Query;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -255,7 +257,7 @@ public class LoginPanel extends Window implements EventListener
txtUserId.setValue(user.getName()); txtUserId.setValue(user.getName());
} }
} }
onUserIdChange(); onUserIdChange(AD_User_ID);
chkRememberMe.setChecked(true); chkRememberMe.setChecked(true);
} }
if (MSystem.isZKRememberPasswordAllowed()) { if (MSystem.isZKRememberPasswordAllowed()) {
@ -365,7 +367,7 @@ public class LoginPanel extends Window implements EventListener
{ {
if(eventComp.getId().equals(txtUserId.getId())) if(eventComp.getId().equals(txtUserId.getId()))
{ {
onUserIdChange(); onUserIdChange(-1);
} }
} }
else if (event.getName().equals(ON_LOAD_TOKEN)) else if (event.getName().equals(ON_LOAD_TOKEN))
@ -382,26 +384,36 @@ public class LoginPanel extends Window implements EventListener
// //
} }
private void onUserIdChange() { private void onUserIdChange(int AD_User_ID) {
String userId = txtUserId.getValue(); String userName = txtUserId.getValue();
if(userId != null && userId.length() > 0) if (userName != null && userName.length() > 0 && AD_User_ID < 0)
{ {
int AD_User_ID = DB.getSQLValue(null, "SELECT AD_User_ID FROM AD_User WHERE Name = ?", userId); String column;
if(AD_User_ID > 0) if (email_login)
column = "EMail";
else
column = "COALESCE(LDAPUser,Name)";
List<MUser> users = new Query(Env.getCtx(), MUser.Table_Name, "Password IS NOT NULL AND IsActive='Y' AND " + column + "=?", null)
.setParameters(userName)
.list();
if (users.size() == 1) {
AD_User_ID = users.get(0).getAD_User_ID();
}
}
if (AD_User_ID >= 0)
{
// Elaine 2009/02/06 Load preference from AD_Preference
UserPreference userPreference = SessionManager.getSessionApplication().loadUserPreference(AD_User_ID);
String initDefault = userPreference.getProperty(UserPreference.P_LANGUAGE);
for(int i = 0; i < lstLanguage.getItemCount(); i++)
{ {
// Elaine 2009/02/06 Load preference from AD_Preference Comboitem li = lstLanguage.getItemAtIndex(i);
UserPreference userPreference = SessionManager.getSessionApplication().loadUserPreference(AD_User_ID); if(li.getLabel().equals(initDefault))
String initDefault = userPreference.getProperty(UserPreference.P_LANGUAGE); {
for(int i = 0; i < lstLanguage.getItemCount(); i++) lstLanguage.setSelectedIndex(i);
{ languageChanged(li.getLabel()); // Elaine 2009/04/17 language changed
Comboitem li = lstLanguage.getItemAtIndex(i); break;
if(li.getLabel().equals(initDefault)) }
{
lstLanguage.setSelectedIndex(i);
languageChanged(li.getLabel()); // Elaine 2009/04/17 language changed
break;
}
}
} }
} }
} }