Search in sources :

Example 1 with WebUser

use of org.compiere.util.WebUser in project adempiere by adempiere.

the class AdvertisementServlet 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("Post 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");
        if (!response.isCommitted())
            //	entry
            response.sendRedirect("loginServlet?ForwardTo=advertisement.jsp");
        return;
    }
    int W_Advertisement_ID = WebUtil.getParameterAsInt(request, P_ADVERTISEMENT_ID);
    MAdvertisement ad = new MAdvertisement(ctx, W_Advertisement_ID, null);
    if (ad.get_ID() == 0) {
        WebUtil.createForwardPage(response, "Web Advertisement Not Found", "advertisements.jsp", 0);
        return;
    }
    StringBuffer info = new StringBuffer();
    //
    String Name = WebUtil.getParameter(request, "Name");
    if (Name != null && Name.length() > 0 && !Name.equals(ad.getName())) {
        ad.setName(Name);
        info.append("Name - ");
    }
    String Description = WebUtil.getParameter(request, "Description");
    if (Description != null && Description.length() > 0 && !Description.equals(ad.getDescription())) {
        ad.setDescription(Description);
        info.append("Description - ");
    }
    String ImageURL = null;
    String AdText = WebUtil.getParameter(request, "AdText");
    if (AdText != null && AdText.length() > 0 && !AdText.equals(ad.getAdText())) {
        ad.setAdText(AdText);
        info.append("AdText - ");
    }
    String ClickTargetURL = WebUtil.getParameter(request, "ClickTargetURL");
    if (ClickTargetURL != null && ClickTargetURL.length() > 0 && !ClickTargetURL.equals(ad.getClickTargetURL())) {
        ad.setClickTargetURL(ClickTargetURL);
        info.append("ClickTargetURL - ");
    }
    if (info.length() > 0) {
        if (ad.save())
            WebUtil.createForwardPage(response, "Web Advertisement Updated: " + info.toString(), "advertisements.jsp", 0);
        else
            WebUtil.createForwardPage(response, "Web Advertisement Update Error", "advertisements.jsp", 0);
    } else
        WebUtil.createForwardPage(response, "Web Advertisement not changed", "advertisements.jsp", 0);
}
Also used : HttpSession(javax.servlet.http.HttpSession) MAdvertisement(org.compiere.model.MAdvertisement) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties)

Example 2 with WebUser

use of org.compiere.util.WebUser in project adempiere by adempiere.

the class OrderServlet 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("Post from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
    Properties ctx = JSPEnv.getCtx(request);
    HttpSession session = request.getSession(true);
    session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
    //	Web User/Basket
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    WebBasket wb = (WebBasket) session.getAttribute(WebBasket.NAME);
    MOrder order = null;
    boolean done = false;
    String url = "/paymentInfo.jsp";
    //	Not logged in
    if (wu == null || !wu.isLoggedIn()) {
        //	indicate checkout
        session.setAttribute("CheckOut", "Y");
        url = "/login.jsp";
        done = true;
    } else
        //	Order parameter
        order = getOrder(request, ctx);
    //	We have an Order
    if (!done && order != null) {
        if (processOrder(request, order))
            url = "/orders.jsp";
        else {
            WebOrder wo = new WebOrder(order);
            MPayment p = createPayment(session, ctx, wu, wo);
            if (p != null) {
                session.setAttribute(PaymentServlet.ATTR_PAYMENT, p);
                session.setAttribute(WebOrder.NAME, wo);
            } else
                url = "/orders.jsp";
        }
        done = true;
    }
    //	Nothing in basket
    if (!done && (wb == null || wb.getLineCount() == 0)) {
        url = "/basket.jsp";
        done = true;
    }
    //	Create Order & Payment Info
    if (!done) {
        WebOrder wo = new WebOrder(wu, wb, ctx);
        //	We have an order - do delete basket & checkout indicator
        if (wo.isInProgress() || wo.isCompleted()) {
            session.removeAttribute(CheckOutServlet.ATTR_CHECKOUT);
            session.removeAttribute(WebBasket.NAME);
            sendEMail(request, ctx, wo, wu);
        }
        //	If the Order is negative, don't create a payment
        if (wo.getGrandTotal().compareTo(Env.ZERO) > 0) {
            session.setAttribute(WebOrder.NAME, wo);
            MPayment p = createPayment(session, ctx, wu, wo);
            if (p == null) {
                WebUtil.createForwardPage(response, "Payment could not be created", "orders.jsp", 5);
                return;
            } else
                session.setAttribute(PaymentServlet.ATTR_PAYMENT, p);
        } else {
            url = "/orders.jsp";
        }
    }
    log.info("Forward to " + url);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
}
Also used : MOrder(org.compiere.model.MOrder) HttpSession(javax.servlet.http.HttpSession) MPayment(org.compiere.model.MPayment) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 3 with WebUser

use of org.compiere.util.WebUser in project adempiere by adempiere.

the class RequestServlet 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 {
    String contentType = request.getContentType();
    log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr() + " - " + contentType);
    //  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=request.jsp");
        return;
    }
    if (contentType != null && contentType.indexOf("multipart/form-data") != -1) {
        uploadFile(request, response);
        return;
    }
    //	Addl Info
    String requestURL = request.getRequestURL().toString();
    String requestRef = request.getHeader("referer");
    String source = WebUtil.getParameter(request, P_SOURCE);
    String info = WebUtil.getParameter(request, P_INFO);
    String forwardTo = WebUtil.getParameter(request, P_FORWARDTO);
    log.fine("Referer=" + requestRef + ", Source=" + source + ", ForwardTo=" + forwardTo);
    if (requestURL == null)
        requestURL = "";
    if (//  if URL and Referrer are the same, get source
    requestURL.equals(requestRef)) {
        requestRef = source;
        source = null;
    }
    int AD_Client_ID = Env.getContextAsInt(ctx, "AD_Client_ID");
    int R_RequestType_ID = WebUtil.getParameterAsInt(request, P_REQUESTTYPE_ID);
    int C_Order_ID = WebUtil.getParameterAsInt(request, P_REF_ORDER_ID);
    int R_Request_ID = WebUtil.getParameterAsInt(request, P_REQUEST_ID);
    int SalesRep_ID = WebUtil.getParameterAsInt(request, P_SALESREP_ID);
    if (SalesRep_ID != 0 && !MUser.isSalesRep(SalesRep_ID)) {
        log.warning("Invalid (set to 0) SalesRep_ID=" + SalesRep_ID);
        SalesRep_ID = 0;
    }
    //	The text
    String Summary = WebUtil.getParameter(request, P_SUMMARY);
    if (Summary == null || Summary.length() == 0) {
        WebUtil.createErrorPage(request, response, this, "No Data Received");
        return;
    }
    boolean IsConfidential = WebUtil.getParameterAsBoolean(request, P_CONFIDENTIAL);
    boolean IsClose = WebUtil.getParameterAsBoolean(request, P_CLOSE);
    boolean IsEscalate = WebUtil.getParameterAsBoolean(request, P_ESCALATE);
    MRequest req = null;
    //	New SelfService Request
    if (R_Request_ID == 0) {
        req = new MRequest(ctx, SalesRep_ID, R_RequestType_ID, Summary, true, null);
        req.setC_BPartner_ID(wu.getC_BPartner_ID());
        req.setAD_User_ID(wu.getAD_User_ID());
        if (C_Order_ID > 0)
            req.setC_Order_ID(C_Order_ID);
        if (IsConfidential)
            req.setConfidentialType(MRequest.CONFIDENTIALTYPE_PartnerConfidential);
        //
        StringBuffer sb = new StringBuffer();
        sb.append("From:").append(request.getRemoteHost()).append("-").append(request.getRemoteAddr());
        sb.append(", Request:").append(requestURL).append("-").append(requestRef);
        if (source != null)
            sb.append("-").append(source);
        sb.append("-").append(info);
        sb.append(", User=").append(request.getHeader("accept-language")).append("-").append(request.getHeader("user-agent"));
        req.setLastResult(sb.toString());
        //
        if (!req.save()) {
            log.log(Level.SEVERE, "New Request NOT saved");
            WebUtil.createErrorPage(request, response, this, "Request Save Error. Shorten Text!");
            return;
        }
    } else //	existing Request
    {
        req = new MRequest(ctx, R_Request_ID, null);
        if (req.get_ID() == 0) {
            log.log(Level.SEVERE, "Request NOT found - R_Request_ID=" + R_Request_ID);
            WebUtil.createErrorPage(request, response, this, "Request Not found.");
            return;
        }
        //	Update Info
        if (C_Order_ID != 0 && req.getC_Order_ID() == 0)
            req.setC_Order_ID(C_Order_ID);
        if (!req.webUpdate(Summary)) {
            WebUtil.createErrorPage(request, response, this, "Request Cannot be updated.");
            return;
        }
        //	Flags
        if (IsConfidential)
            req.setConfidentialTypeEntry(MRequest.CONFIDENTIALTYPEENTRY_PartnerConfidential);
        if (IsClose)
            req.doClose();
        else if (IsEscalate) {
            boolean isUser = req.getC_BPartner_ID() == wu.getC_BPartner_ID();
            if (//	allow only user or sales rep to escalate
            isUser || wu.isSalesRep())
                req.doEscalate(isUser);
        }
        if (!req.save()) {
            log.log(Level.SEVERE, "Request Action Error");
            WebUtil.createErrorPage(request, response, this, "Request Process Error.");
            return;
        }
    }
    //	Requests
    //	Send EMail to Customer
    StringBuffer message = new StringBuffer(req.getSummary());
    String result = req.getResult();
    if (result != null && result.length() > 0)
        message.append("\n----------\n").append(req.getResult());
    JSPEnv.sendEMail(request, wu, MMailMsg.MAILMSGTYPE_Request, new Object[] { req.getDocumentNo(), wu.getName(), message, "\n---------- " + req.getMailTag() });
    //  --  Fini
    String webStoreURL = "http://" + request.getServerName() + request.getContextPath() + "/";
    if (forwardTo == null || forwardTo.length() == 0)
        forwardTo = requestRef;
    if (forwardTo != null && (forwardTo.indexOf("request.jsp") != -1 || forwardTo.indexOf("requestDetails.jsp") != -1))
        //	list of requests
        forwardTo = "requests.jsp";
    if (forwardTo == null || forwardTo.length() == 0)
        forwardTo = webStoreURL;
    if (forwardTo.indexOf("Servlet") != -1)
        forwardTo = webStoreURL;
    WebUtil.createForwardPage(response, "Web Request Received - Thanks", forwardTo, 10);
}
Also used : MRequest(org.compiere.model.MRequest) HttpSession(javax.servlet.http.HttpSession) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties)

Example 4 with WebUser

use of org.compiere.util.WebUser in project adempiere by adempiere.

the class LoginLinkTag method getWebUser.

//	doEndTag
/**
	 *	Get WebUser.
	 * 	@param ctx context
	 * 	@return Web User or null
	 */
private WebUser getWebUser(Properties ctx) {
    String address = pageContext.getRequest().getRemoteAddr();
    //	Get stored User
    WebUser wu = (WebUser) pageContext.getSession().getAttribute(WebUser.NAME);
    if (wu != null) {
        log.finest("(" + address + ") - SessionContext: " + wu);
    } else {
        wu = (WebUser) pageContext.getAttribute(WebUser.NAME);
        if (wu != null)
            log.finest("(" + address + ") - Context: " + wu);
    }
    if (wu != null)
        return wu;
    //	Check Cookie
    String cookieUser = JSPEnv.getCookieWebUser((HttpServletRequest) pageContext.getRequest());
    if (cookieUser == null || cookieUser.trim().length() == 0)
        log.finer("(" + address + ") - no cookie");
    else {
        //	Try to Load
        wu = WebUser.get(ctx, cookieUser);
        log.finer("(" + address + ") - Cookie: " + wu);
    }
    if (wu != null)
        return wu;
    //
    return null;
}
Also used : WebUser(org.compiere.util.WebUser)

Example 5 with WebUser

use of org.compiere.util.WebUser in project adempiere by adempiere.

the class LoginLinkTag method doStartTag.

/**
	 *  Start Tag
	 *  @return SKIP_BODY
	 * 	@throws JspException
	 */
public int doStartTag() throws JspException {
    Properties ctx = JSPEnv.getCtx((HttpServletRequest) pageContext.getRequest());
    //
    WebUser wu = getWebUser(ctx);
    if (wu == null)
        pageContext.getSession().removeAttribute(WebUser.NAME);
    else
        pageContext.getSession().setAttribute(WebUser.NAME, wu);
    //
    String serverContext = ctx.getProperty(WebSessionCtx.CTX_SERVER_CONTEXT);
    //	log.fine("doStartTag - ServerContext=" + serverContext);
    HtmlCode html = null;
    if (wu != null && wu.isValid())
        html = getWelcomeLink(serverContext, wu);
    else
        html = getLoginLink(serverContext);
    //
    JspWriter out = pageContext.getOut();
    /**
		//	Delete Cookie Call
		if (cookieUser != null && !cookieUser.equals(" "))
		{
			log.fine("- Cookie=" + cookieUser);
			html.addElement(" ");
			a a = new a("loginServlet?mode=deleteCookie");
			a.setClass("menuDetail");
			a.addElement("(Delete Cookie)");
			html.addElement(a);
		}
		**/
    html.output(out);
    //
    return (SKIP_BODY);
}
Also used : HtmlCode(org.compiere.util.HtmlCode) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

WebUser (org.compiere.util.WebUser)25 HttpSession (javax.servlet.http.HttpSession)23 Properties (java.util.Properties)22 RequestDispatcher (javax.servlet.RequestDispatcher)9 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 MAttachment (org.compiere.model.MAttachment)3 MPayment (org.compiere.model.MPayment)3 Timestamp (java.sql.Timestamp)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 JspWriter (javax.servlet.jsp.JspWriter)2 MNote (org.compiere.model.MNote)2 MRequest (org.compiere.model.MRequest)2 HtmlCode (org.compiere.util.HtmlCode)2 WebSessionCtx (org.compiere.util.WebSessionCtx)2 MWFActivity (org.compiere.wf.MWFActivity)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1