use of org.compiere.util.WebUser in project adempiere by adempiere.
the class RegistrationServlet method doPost.
// sendAnswer
/**************************************************************************
* Process the HTTP Post request
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
// Get Session attributes
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
//
Properties ctx = JSPEnv.getCtx(request);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu == null) {
log.warning("No web user");
// entry
response.sendRedirect("loginServlet?ForwardTo=registration.jsp");
return;
}
int A_Registration_ID = WebUtil.getParameterAsInt(request, P_REGISTRATION_ID);
MRegistration reg = null;
if (A_Registration_ID > 0)
reg = new MRegistration(ctx, A_Registration_ID, null);
if (reg == null) {
reg = new MRegistration(ctx, 0, null);
A_Registration_ID = 0;
}
//
String name = WebUtil.getParameter(request, "Name");
if (name == null || name.length() == 0) {
WebUtil.createForwardPage(response, "Name is Mandatory", "registrations.jsp", 4);
return;
}
reg.setC_BPartner_ID(wu.getBpartnerID());
reg.setName(name);
String description = WebUtil.getParameter(request, "Description");
if (description != null && description.length() > 0)
reg.setDescription(description);
boolean isInProduction = WebUtil.getParameterAsBoolean(request, "IsInProduction");
reg.setIsInProduction(isInProduction);
Timestamp assetServiceDate = WebUtil.getParameterAsDate(request, "AssetServiceDate");
if (assetServiceDate == null)
assetServiceDate = new Timestamp(System.currentTimeMillis());
reg.setAssetServiceDate(assetServiceDate);
boolean isAllowPublish = WebUtil.getParameterAsBoolean(request, "IsAllowPublish");
reg.setIsAllowPublish(isAllowPublish);
if (reg.save()) {
if (A_Registration_ID == 0)
// new
reg.loadAttributeValues(request);
else
// existing
reg.updateAttributeValues(request);
WebUtil.createForwardPage(response, THANKS, "registrations.jsp", 3);
} else {
log.log(Level.SEVERE, "Registration not saved");
WebUtil.createForwardPage(response, PROBLEM, "registrations.jsp", 3);
}
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class JSPEnv method getCtx.
/**
* Get Context from Session
* @param request request
* @return properties
*/
public static Properties getCtx(HttpServletRequest request) {
WebSessionCtx wsc = WebSessionCtx.get(request);
HttpSession session = request.getSession(true);
// Add/set current user
WebUser wu = WebUser.get(request);
if (wu != null) {
int AD_User_ID = wu.getAD_User_ID();
// security
Env.setContext(wsc.ctx, "#AD_User_ID", AD_User_ID);
}
// Finish
// 30 Min HARDCODED
session.setMaxInactiveInterval(1800);
String info = (String) wsc.ctx.get(WebSessionCtx.HDR_INFO);
if (info != null)
session.setAttribute(WebSessionCtx.HDR_INFO, info);
return wsc.ctx;
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class LoginServlet method doPost.
// doGet
/**
* Process the HTTP Post request
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
Properties ctx = JSPEnv.getCtx(request);
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
// WEnv.dump(session);
// WEnv.dump(request);
org.compiere.util.WebLogin thisLogin = new org.compiere.util.WebLogin(request, response, ctx);
thisLogin.init();
// Forward URL
String url = thisLogin.getForward();
// get SalesRep from request
String salesRep = thisLogin.getSalesRep_ID();
if (salesRep != null)
session.setAttribute(thisLogin.getP_SalesRep_ID(), salesRep);
boolean checkOut = "Y".equals(session.getAttribute(CheckOutServlet.ATTR_CHECKOUT));
// Set in login.jsp & addressInfo.jsp
boolean addressConfirm = "Y".equals(WebUtil.getParameter(request, "AddressConfirm"));
if (checkOut) {
if (addressConfirm)
url = "/orderServlet";
else
url = "/addressInfo.jsp";
} else
addressConfirm = false;
if (url == null || url.length() == 0) {
// get from session
url = (String) session.getAttribute(thisLogin.getP_ForwardTo());
if (url == null || url.length() == 0)
url = "/index.jsp";
} else {
if (!url.startsWith("/"))
url = "/" + url;
// save for log in issues
session.setAttribute(thisLogin.getP_ForwardTo(), url);
}
// SalesRep Parameter
// get SalesRep from session
salesRep = (String) session.getAttribute(thisLogin.getP_SalesRep_ID());
if (salesRep != null)
url += "?SalesRep_ID=" + salesRep;
//
//String mode = WebUtil.getParameter (request, "Mode");
// + " - mode=" + mode);
log.fine("- targeting url=" + url);
// Web User
WebUser wu = WebUser.get(request);
// Handover Loginprodcess to general WebLogin Handler
// Frst set the URL from our current situation
thisLogin.setForward(url);
// Also handover adressConfirm
thisLogin.setAddressConfirm(addressConfirm);
// Since Mode Usage is not consequent we will try to figure it out.
if (WebUtil.getParameter(request, "Mode") == null)
if (WebUtil.getParameter(request, "mode") != null)
thisLogin.setP_Action("mode");
// Start the process
thisLogin.action();
// getback the URL
url = thisLogin.getForward();
wu = thisLogin.getWebUser();
session.setAttribute(WebUser.NAME, wu);
if (!url.startsWith("/"))
url = "/" + url;
log.info("doPost - Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class NoteServlet method doPost.
// streamAttachment
/**************************************************************************
* Process the HTTP Post request.
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
String url = "/notes.jsp";
// Get Session attributes
HttpSession session = request.getSession(true);
session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
//
Properties ctx = JSPEnv.getCtx(request);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu == null) {
log.warning("No web user");
if (!response.isCommitted())
// entry
response.sendRedirect("loginServlet?ForwardTo=notes.jsp");
return;
}
WebEnv.dump(request);
int AD_Note_ID = WebUtil.getParameterAsInt(request, P_Note_ID);
String processed = WebUtil.getParameter(request, "Processed");
boolean prc = processed != null && processed.length() > 0;
if (prc) {
MNote note = new MNote(ctx, AD_Note_ID, null);
if (note.get_ID() == AD_Note_ID) {
note.setProcessed(true);
note.saveEx();
log.fine("doPost - " + note);
}
}
// Redisplay
log.info("Forward to " + url);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
use of org.compiere.util.WebUser in project adempiere by adempiere.
the class Click method saveClick.
// getTargetURL
/**
* Save Click
*/
private boolean saveClick(HttpServletRequest request, String url) {
Properties ctx = JSPEnv.getCtx(request);
//
MClick mc = new MClick(ctx, url, null);
mc.setRemote_Addr(request.getRemoteAddr());
mc.setRemote_Host(request.getRemoteHost());
String ref = request.getHeader("referer");
if (ref == null || ref.length() == 0)
ref = request.getRequestURL().toString();
mc.setReferrer(ref);
//
mc.setAcceptLanguage(request.getHeader("accept-language"));
mc.setUserAgent(request.getHeader("user-agent"));
//
HttpSession session = request.getSession(false);
if (session != null) {
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu != null) {
mc.setEMail(wu.getEmail());
mc.setAD_User_ID(wu.getAD_User_ID());
}
}
return mc.save();
}
Aggregations