IDEMPIERE-2944 Preserve iDempiere session between sucessive webservice calls / fix login when using email - as reported by Pritesh Shah

This commit is contained in:
Carlos Ruiz 2018-05-15 10:23:51 +02:00
parent 83f5ee7d17
commit 72b21f1df1
2 changed files with 11 additions and 24 deletions

View File

@ -21,7 +21,6 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -237,28 +236,10 @@ public class MUser extends X_AD_User
*/ */
public static String getNameOfUser (int AD_User_ID) public static String getNameOfUser (int AD_User_ID)
{ {
String name = "?"; MUser user = get(Env.getCtx(), AD_User_ID);
// Get ID if (user.getAD_User_ID() != AD_User_ID)
String sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; return "?";
PreparedStatement pstmt = null; return user.getName();
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_User_ID);
rs = pstmt.executeQuery();
if (rs.next())
name = rs.getString(1);
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
}
return name;
} // getNameOfUser } // getNameOfUser

View File

@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletRequest;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.compiere.model.MSession; import org.compiere.model.MSession;
import org.compiere.model.MSysConfig;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -271,7 +272,12 @@ public class CompiereService {
m_AD_Role_ID = AD_Role_ID; m_AD_Role_ID = AD_Role_ID;
m_M_Warehouse_ID = M_Warehouse_ID; m_M_Warehouse_ID = M_Warehouse_ID;
m_locale = Lang; m_locale = Lang;
m_userName = MUser.getNameOfUser(m_AD_User_ID); boolean email_login = MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false);
MUser user = MUser.get(getCtx(), m_AD_User_ID);
if (email_login)
m_userName = user.getEMail();
else
m_userName = user.getName();
Env.setContext( getCtx(), "#AD_Language", Lang); Env.setContext( getCtx(), "#AD_Language", Lang);
m_language = Language.getLanguage(Lang); m_language = Language.getLanguage(Lang);