use of org.compiere.model.MBPBankAccount in project adempiere by adempiere.
the class Generator method generateSessionEquiv.
private void generateSessionEquiv(HttpServletCM thisServlet, HttpServletRequest httpRequest, Properties ctx) {
xmlCode.append("<session>\n");
HttpSession thisSession = httpRequest.getSession(false);
if (thisSession != null) {
if (thisSession.getAttribute(WebInfo.NAME) != null) {
WebInfo wi = (WebInfo) thisSession.getAttribute(WebInfo.NAME);
xmlCode.append("<WebInfo>\n");
xmlCode.append("<Info><![CDATA[" + wi.getInfo() + "]]></Info>\n");
if (wi.getUser_ID() > 0) {
MUser thisUser = MUser.get(ctx, wi.getAD_User_ID());
xmlCode = thisUser.get_xmlString(xmlCode);
MBPartner thisBPartner = new MBPartner(ctx, wi.getC_BPartner_ID(), null);
if (thisBPartner != null)
xmlCode = thisBPartner.get_xmlString(xmlCode);
MBPartnerLocation thisBPartnerLocation = thisBPartner.getPrimaryC_BPartner_Location();
if (thisBPartnerLocation != null)
xmlCode = thisBPartnerLocation.get_xmlString(xmlCode);
MLocation thisLocation = MLocation.getBPLocation(ctx, thisBPartnerLocation.get_ID(), null);
if (thisLocation != null)
xmlCode = thisLocation.get_xmlString(xmlCode);
MBPBankAccount[] theseBPBankAccount = thisBPartner.getBankAccounts(true);
if (theseBPBankAccount != null && theseBPBankAccount.length > 0)
for (int i = 0; i < theseBPBankAccount.length; i++) xmlCode = theseBPBankAccount[i].get_xmlString(xmlCode);
if (thisSession.getAttribute("EMail") == null)
thisSession.setAttribute("EMail", thisUser.getEMail());
}
if (wi.getWebUser().getPasswordMessage() != null) {
xmlCode.append("<PasswordMessage><![CDATA[" + wi.getWebUser().getPasswordMessage() + "]]></PasswordMessage>\n");
wi.getWebUser().setPasswordMessage(null);
}
if (wi.getWebUser().getSaveErrorMessage() != null) {
xmlCode.append("<SaveErrorMessage><![CDATA[" + wi.getWebUser().getSaveErrorMessage() + "]]></SaveErrorMessage>\n");
wi.getWebUser().setSaveErrorMessage(null);
}
if (thisSession.getAttribute("hdrMessage") != null) {
xmlCode.append("<hdrMessage><![CDATA[" + thisSession.getAttribute("hdrMessage") + "]]></hdrMessage>\n");
thisSession.removeAttribute("hdrMessage");
}
xmlCode.append("<WebUser>\n");
xmlCode.append("<LoggedIn>" + wi.getWebUser().isLoggedIn() + "</LoggedIn>\n");
xmlCode.append("</WebUser>\n");
xmlCode.append("</WebInfo>\n");
}
if (thisSession.getAttribute("EMail") != null)
xmlCode.append("<EMail><![CDATA[" + thisSession.getAttribute("EMail") + "]]></EMail>\n");
}
xmlCode.append("</session>\n");
}
use of org.compiere.model.MBPBankAccount in project adempiere by adempiere.
the class WebLogin method action.
/**
* Action run functions against the Login process.
* @return true if successfull
* @throws IOException
* @throws ServletException
*/
public boolean action() throws IOException, ServletException {
// Mode
if (getMode() == null) {
String s = WebUtil.getParameter(m_request, P_Action);
setMode(s);
}
boolean deleteCookie = "deleteCookie".equals(m_mode);
if (deleteCookie) {
log.fine("** deleteCookie");
WebUtil.deleteCookieWebUser(m_request, m_response, COOKIE_NAME);
}
//
boolean logout = "logout".equals(m_mode);
if (logout || deleteCookie) {
log.fine("** logout");
if (m_session != null) {
MSession cSession = MSession.get(m_ctx, false);
if (cSession != null)
cSession.logout();
//
m_wu = (WebUser) m_session.getAttribute(WebUser.NAME);
if (m_wu != null)
m_wu.logout();
m_session.removeAttribute(WebUser.NAME);
m_session.setMaxInactiveInterval(1);
m_session.invalidate();
}
// Forward to unsecure /
WebUtil.createForwardPage(m_response, "Logout", "http://" + m_request.getServerName() + "/", 2);
} else // Send EMail *** Send Password EMail Request
if ("SendEMail".equals(m_mode)) {
log.info("** send mail");
// find it
m_wu = WebUser.get(m_ctx, m_email);
if (!m_wu.isEMailValid())
m_wu.setPasswordMessage("EMail not found in system");
else {
// set password to current
m_wu.setPassword();
//
String msg = WebUtil.sendEMail(m_request, m_wu, MMailMsg.MAILMSGTYPE_UserPassword, new Object[] { m_request.getServerName(), m_wu.getName(), WebUtil.getFrom(m_request), m_wu.getPassword() });
if (EMail.SENT_OK.equals(msg))
m_wu.setPasswordMessage("EMail sent");
else
m_wu.setPasswordMessage("Problem sending EMail: " + msg);
}
m_forward = getLogin_RelURL();
} else // Login
if ("Login".equals(m_mode)) {
log.info("** login " + m_email + "/" + m_password);
// add Cookie
WebUtil.addCookieWebUser(m_request, m_response, m_email, COOKIE_NAME);
// Always re-query
m_wu = WebUser.get(m_ctx, m_email, m_password, false);
m_wu.login(m_password);
// Password valid
if (m_wu.isLoggedIn()) {
if (m_forward == null || m_forward.equals(getLogin_RelURL()))
m_forward = "/index.jsp";
// Create Session with User ID
MSession cSession = MSession.get(m_ctx, m_request.getRemoteAddr(), m_request.getRemoteHost(), m_session.getId());
if (cSession != null)
cSession.setWebStoreSession(true);
} else {
m_forward = getLogin_RelURL();
log.fine("- PasswordMessage=" + m_wu.getPasswordMessage());
}
// If no session exists or is not loaded, load or create it
if (m_session == null)
m_session = m_request.getSession(true);
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
} else // Login New
if ("LoginNew".equals(m_mode)) {
log.info("** loginNew");
WebUtil.addCookieWebUser(m_request, m_response, "", COOKIE_NAME);
m_wu = WebUser.get(m_ctx, "");
m_forward = getLogin_RelURL();
} else // Submit - update/new Contact
if ("Submit".equals(m_mode)) {
log.info("** submit " + m_email + "/" + m_password + " - AddrConf=" + m_addressConfirm);
// we have a record for address update
if (// address update
m_wu != null && m_wu.isLoggedIn() && m_addressConfirm)
;
else
// Submit - always re-load user record
// load w/o password check direct
m_wu = WebUser.get(m_ctx, m_email, null, false);
//
if (// existing BPC
m_wu.getAD_User_ID() != 0) {
String passwordNew = WebUtil.getParameter(m_request, "PasswordNew");
if (passwordNew == null)
passwordNew = "";
boolean passwordChange = passwordNew.length() > 0 && !passwordNew.equals(m_password);
if (m_addressConfirm || m_wu.login(m_password)) {
// Create / set session
if (m_wu.isLoggedIn()) {
MSession cSession = MSession.get(m_ctx, m_request.getRemoteAddr(), m_request.getRemoteHost(), m_session.getId());
if (cSession != null)
cSession.setWebStoreSession(true);
}
//
if (passwordChange)
log.fine("- update Pwd " + m_email + ", Old=" + m_password + ", DB=" + m_wu.getPassword() + ", New=" + passwordNew);
if (WebUtil.updateFields(m_request, m_wu, passwordChange)) {
if (passwordChange)
m_session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Password changed");
} else {
m_forward = getLogin_RelURL();
log.warning(" - update not done");
}
} else {
m_forward = getLogin_RelURL();
m_session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Email/Password not correct");
log.warning(" - update not confirmed");
}
} else // new
{
log.fine("** new " + m_email + "/" + m_password);
m_wu.setEmail(m_email);
m_wu.setPassword(m_password);
if (WebUtil.updateFields(m_request, m_wu, true)) {
if (m_wu.login(m_password)) {
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
// Create / set session
MSession cSession = MSession.get(m_ctx, m_request.getRemoteAddr(), m_request.getRemoteHost(), m_session.getId());
if (cSession != null)
cSession.setWebStoreSession(true);
WebUtil.resendCode(m_request, m_wu);
} else
m_forward = getLogin_RelURL();
} else {
log.fine("- failed - " + m_wu.getSaveErrorMessage() + " - " + m_wu.getPasswordMessage());
m_forward = getLogin_RelURL();
}
}
// new
if (m_wu != null)
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
} else if ("email".equals(m_mode)) {
String email = WebUtil.getParameter(m_request, "EMail");
if (email == null)
email = "";
email = email.trim();
String emailNew = WebUtil.getParameter(m_request, "EMailNew");
if (emailNew == null)
emailNew = "";
email = email.trim();
if ((emailNew.length() == 0) || (emailNew.equals(email))) {
setMessage("New EMail invalid.");
return false;
}
if (!WebUtil.isEmailValid(emailNew)) {
setMessage("New EMail invalid.");
return false;
}
m_wu.setEmail(emailNew);
m_wu.save();
m_session.setAttribute(WebSessionCtx.HDR_MESSAGE, "EMail Address Changed");
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
} else if ("password".equals(m_mode)) {
if (m_wu == null) {
log.warning("No web user");
return false;
}
String password = WebUtil.getParameter(m_request, "Password");
if (password == null)
// null loads w/o check
password = "";
password = password.trim();
if (!m_wu.login(password)) {
setMessage("Email/Password not correct");
return false;
}
MSession cSession = MSession.get(m_ctx, m_request.getRemoteAddr(), m_request.getRemoteHost(), m_session.getId());
if (cSession != null)
cSession.setWebStoreSession(true);
String passwordNew = WebUtil.getParameter(m_request, "PasswordNew");
if (passwordNew == null)
passwordNew = "";
password = password.trim();
if ((passwordNew.length() == 0) || (passwordNew.equals(password))) {
setMessage("New Password invalid.");
return false;
}
m_wu.setPasswordMessage(null);
m_wu.setPassword(passwordNew);
if (m_wu.getPasswordMessage() != null) {
setMessage("New Password invalid.");
return false;
}
m_wu.save();
if (m_forward == null || m_forward.equals(getLogin_RelURL()))
m_forward = "/index.jsp";
m_session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Password Changed");
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
} else if ("address".equals(m_mode)) {
m_wu.setC_Country_ID(WebUtil.getParamOrNull(m_request, "C_Country_ID"));
m_wu.setC_Region_ID(WebUtil.getParamOrNull(m_request, "C_Region_ID"));
m_wu.setRegionName(WebUtil.getParamOrNull(m_request, "RegionName"));
m_wu.setName(WebUtil.getParamOrNull(m_request, "Name"));
m_wu.setCompany(WebUtil.getParamOrNull(m_request, "Company"));
m_wu.setTitle(WebUtil.getParamOrNull(m_request, "Title"));
m_wu.setAddress(WebUtil.getParamOrNull(m_request, "Address"));
m_wu.setAddress2(WebUtil.getParamOrNull(m_request, "Address2"));
m_wu.setCity(WebUtil.getParamOrNull(m_request, "City"));
m_wu.setPostal(WebUtil.getParamOrNull(m_request, "Postal"));
m_wu.setPhone(WebUtil.getParamOrNull(m_request, "Phone"));
m_wu.setFax(WebUtil.getParamOrNull(m_request, "Fax"));
m_wu.save();
m_session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Contact Information Changed");
m_session.setAttribute(WebInfo.NAME, new WebInfo(m_ctx, m_wu));
} else if ("EMailVerify".equals(m_mode)) {
if (m_wu == null) {
log.warning("No web user");
return false;
}
log.info(m_forward + " - " + m_wu.toString());
String cmd = WebUtil.getParameter(m_request, "ReSend");
if (cmd != null && cmd.length() > 1)
WebUtil.resendCode(m_request, m_wu);
else
m_wu.setEMailVerifyCode(WebUtil.getParameter(m_request, "VerifyCode"), m_request.getRemoteAddr());
} else if ("bankaccountach".equals(m_mode)) {
if (m_wu == null) {
log.warning("No web user");
return false;
}
log.info(m_forward + " - " + m_wu.toString());
MBPBankAccount thisBPBankAccount = m_wu.getBankAccount(true);
// As this sets bankaccountach
thisBPBankAccount.setIsACH(true);
thisBPBankAccount.setA_City(WebUtil.getParamOrNull(m_request, "A_City"));
thisBPBankAccount.setA_Name(WebUtil.getParamOrNull(m_request, "A_Name"));
thisBPBankAccount.setAccountNo(WebUtil.getParamOrNull(m_request, "AccountNo"));
thisBPBankAccount.setRoutingNo(WebUtil.getParamOrNull(m_request, "RoutingNo"));
thisBPBankAccount.save();
} else
log.log(Level.WARNING, "Unknown request='" + m_mode + "'");
return true;
}
use of org.compiere.model.MBPBankAccount in project adempiere by adempiere.
the class WebUser method getBankAccount.
/**************************************************************************
* Get BP Bank Account (or create it)
* @param requery Requery data
* @return Bank Account
*/
public MBPBankAccount getBankAccount(boolean requery) {
MBPBankAccount retValue = null;
// Find Bank Account for exact User
MBPBankAccount[] bas = m_bp.getBankAccounts(requery);
for (int i = 0; i < bas.length; i++) {
if (bas[i].getAD_User_ID() == getAD_User_ID() && bas[i].isActive())
retValue = bas[i];
}
// create new
if (retValue == null) {
retValue = new MBPBankAccount(m_ctx, m_bp, m_bpc, m_loc);
retValue.setAD_User_ID(getAD_User_ID());
retValue.saveEx();
}
return retValue;
}
Aggregations