Search in sources :

Example 11 with WebSessionCtx

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

the class WLogin method doPost.

//	doGet
/**
	 *	Process the HTTP Post request.
	 *  <pre>
	 *  - Optionally create Session
	 *  - Check database connection
	 *  - LoginInfo from request?
	 *      - Yes: DoLogin success ?
	 *          - Yes: return (second) preferences page
	 *          - No: return (first) user/password page
	 *      - No: User Principal ?
	 *          - Yes: DoLogin success ?
	 *              - Yes: return (second) preferences page
	 *              - No: return (first) user/password page
	 *          - No: return (first) user/password page
	 *  </pre>
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("");
    //  Create New Session
    HttpSession sess = request.getSession(true);
    sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
    //  Get Cookie Properties
    Properties cProp = WebUtil.getCookieProprties(request);
    //  Create Context
    WebSessionCtx wsc = WebSessionCtx.get(request);
    //  Page
    WebDoc doc = null;
    //  Check DB connection
    if (!DB.isConnected()) {
        String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
        if (msg.equals("WLoginNoDB"))
            msg = "No Database Connection";
        doc = WebDoc.createWindow(msg);
    } else //  Login Info from request?
    {
        //  Get Parameters:     UserName/Password
        String usr = WebUtil.getParameter(request, P_USERNAME);
        String pwd = WebUtil.getParameter(request, P_PASSWORD);
        //  Get Principle
        Principal userPrincipal = request.getUserPrincipal();
        log.info("Principal=" + userPrincipal + "; User=" + usr);
        //  Login info not from request and not pre-authorized
        if (userPrincipal == null && (usr == null || pwd == null))
            doc = createFirstPage(cProp, request, "");
        else //  Login info from request or authorized
        {
            KeyNamePair[] roles = null;
            Login login = new Login(wsc.ctx);
            //  Pre-authorized
            if (userPrincipal != null) {
                roles = login.getRoles(userPrincipal);
                usr = userPrincipal.getName();
            } else
                roles = login.getRoles(usr, pwd);
            //
            if (roles == null)
                doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
            else {
                doc = createSecondPage(request, WebUtil.convertToOption(roles, null), "");
                //	Create adempiere Session - user id in ctx
                MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
            }
            //  Can we save Cookie ?
            if (WebUtil.getParameter(request, P_STORE) == null) {
                //  erase all
                cProp.clear();
            } else //  Save Cookie Parameter
            {
                cProp.setProperty(P_USERNAME, usr);
                cProp.setProperty(P_STORE, "Y");
                //  For test only
                cProp.setProperty(P_PASSWORD, pwd);
            }
        }
    }
    WebUtil.createResponse(request, response, this, cProp, doc, false);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebDoc(org.compiere.util.WebDoc) KeyNamePair(org.compiere.util.KeyNamePair) Login(org.compiere.util.Login) Properties(java.util.Properties) WebSessionCtx(org.compiere.util.WebSessionCtx) Principal(java.security.Principal)

Example 12 with WebSessionCtx

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

the class WChat method doGet.

//  init
/**
	 * Process the HTTP Get request
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.fine("doGet");
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    //
    WebDoc doc = null;
    if (ws == null) {
        doc = WebDoc.createPopup("No Context");
        doc.addPopupClose(wsc.ctx);
    } else {
        doc = CreateChatPage(ws, wsc, doc, 0);
    }
    //
    WebUtil.createResponse(request, response, this, null, doc, false);
}
Also used : WebDoc(org.compiere.util.WebDoc) WebSessionCtx(org.compiere.util.WebSessionCtx)

Example 13 with WebSessionCtx

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

the class WAccount method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.config("WAccount.doGet");
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null || ws == null) {
        WebUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    String columnName = WebUtil.getParameter(request, "ColumnName");
    GridField mField = ws.curTab.getField(columnName);
    log.config(" ColumnName=" + columnName + ", MField=" + mField.toString());
    if (mField == null || columnName == null || columnName.equals("")) {
        WebUtil.createTimeoutPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
        return;
    }
    String target = "opener.document.WForm." + columnName;
    WebDoc doc = WebDoc.create(mField.getHeader());
    body body = doc.getBody();
    body.setOnBlur("self.focus();");
    body.addElement(fillTable(ws, mField, target));
    button reset = new button();
    reset.addElement("Reset");
    reset.setOnClick(target + "D.value='';" + target + "F.value='';window.close();");
    button cancel = new button();
    cancel.addElement("Cancel");
    cancel.setOnClick("window.close();");
    body.addElement(new p(AlignType.RIGHT).addElement(reset).addElement("&nbsp").addElement(cancel));
    WebUtil.createResponse(request, response, this, null, doc, true);
}
Also used : org.apache.ecs.xhtml.button(org.apache.ecs.xhtml.button) Lookup(org.compiere.model.Lookup) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) WebDoc(org.compiere.util.WebDoc) GridField(org.compiere.model.GridField) WebSessionCtx(org.compiere.util.WebSessionCtx) org.apache.ecs.xhtml.body(org.apache.ecs.xhtml.body)

Example 14 with WebSessionCtx

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

the class WFindAdv method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession sess = request.getSession(false);
    WWindowStatus ws = null;
    WebSessionCtx wsc = WebSessionCtx.get(request);
    if (sess != null)
        ws = WWindowStatus.get(request);
    if (wsc == null) {
        WebUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    WebDoc doc = preparePage();
    body body = doc.getBody();
    String pTab = request.getParameter(P_Tab);
    if (pTab != null && pTab.equals("FindAdv")) {
        body.addElement(createPageFindAdv(request, response, ws));
    } else {
        body.addElement(createPageFind(request, response, ws));
    }
    WebUtil.createResponse(request, response, this, null, doc, true);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebDoc(org.compiere.util.WebDoc) WebSessionCtx(org.compiere.util.WebSessionCtx) org.apache.ecs.xhtml.body(org.apache.ecs.xhtml.body)

Example 15 with WebSessionCtx

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

the class WReport method launchReport.

//	launchReport
/**
	 * 	Launch Report
	 * 	@param pf print format
	 */
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    int Record_ID = 0;
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    //Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
    File fileName = null;
    if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
        Record_ID = ((Integer) m_query.getCode(0)).intValue();
    }
    PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
    info.setDescription(m_query.getInfo());
    if (pf != null && pf.getJasperProcess_ID() > 0) {
        // It's a report using the JasperReports engine
        ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
        Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
        //	Execute Process
        WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
    } else {
        // It's a default report using the standard printing engine
        ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
        if (re == null) {
            log.info("Could not start ReportEngine");
        } else {
            try {
                File file = File.createTempFile("WProcess", ".pdf");
                boolean ok = re.createPDF(file);
                if (ok) {
                    fileName = file;
                } else {
                    log.info("Could not create Report");
                }
            } catch (Exception e) {
                log.info(e.toString());
            }
        }
    }
    return fileName;
}
Also used : ReportEngine(org.compiere.print.ReportEngine) PrintInfo(org.compiere.model.PrintInfo) ProcessInfo(org.compiere.process.ProcessInfo) Trx(org.compiere.util.Trx) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

WebSessionCtx (org.compiere.util.WebSessionCtx)38 WebDoc (org.compiere.util.WebDoc)21 File (java.io.File)13 HttpSession (javax.servlet.http.HttpSession)11 SQLException (java.sql.SQLException)8 Properties (java.util.Properties)6 MPrintFormat (org.compiere.print.MPrintFormat)6 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ServletException (javax.servlet.ServletException)4 GridField (org.compiere.model.GridField)4 org.apache.ecs.xhtml.body (org.apache.ecs.xhtml.body)3 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)3 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)3 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)3 ReportEngine (org.compiere.print.ReportEngine)3 ProcessInfo (org.compiere.process.ProcessInfo)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Trx (org.compiere.util.Trx)3