Search in sources :

Example 6 with MSession

use of org.compiere.model.MSession in project adempiere by adempiere.

the class Env method exitEnv.

/**
	 *	Exit System
	 *  @param status System exit status (usually 0 for no error)
	 */
public static void exitEnv(int status) {
    //hengsin, avoid unncessary query of session when exit without log in
    if (DB.isConnected(false)) {
        //	End Session
        //	finish
        MSession session = MSession.get(Env.getCtx(), false);
        if (session != null)
            session.logout();
    }
    //
    // final cache reset
    reset(true);
    s_log.info("");
    //
    CLogMgt.shutdown();
    //
    if (Ini.isClient())
        System.exit(status);
}
Also used : MSession(org.compiere.model.MSession)

Example 7 with MSession

use of org.compiere.model.MSession in project adempiere by adempiere.

the class Env method logout.

//	close
/**
	 * Logout from the system
	 */
public static void logout() {
    //	End Session
    //	finish
    MSession session = MSession.get(Env.getCtx(), false);
    if (session != null)
        session.logout();
    //
    // final cache reset
    reset(true);
    //
    CConnection.get().setAppServerCredential(null, null);
}
Also used : MSession(org.compiere.model.MSession)

Example 8 with MSession

use of org.compiere.model.MSession 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;
}
Also used : MSession(org.compiere.model.MSession) MBPBankAccount(org.compiere.model.MBPBankAccount)

Example 9 with MSession

use of org.compiere.model.MSession in project adempiere by adempiere.

the class WWindow 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 {
    WebEnv.dump(request);
    //  Get Session Info
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null || ws == null) {
        if (wsc == null)
            WebUtil.createTimeoutPage(request, response, this, "No Context");
        else
            doGet(request, response);
        return;
    }
    //  Get Parameter: Command
    String p_cmd = WebUtil.getParameter(request, P_Command);
    String column = WebUtil.getParameter(request, P_ChangedColumn);
    log.info("Cmd=" + p_cmd + " - ChangedColumn=" + column);
    //	Changed Column
    if (column != null && column.length() > 0) {
        updateFields(request, wsc, ws);
    } else //	Exit & Commands
    {
        if (p_cmd.equals("Exit")) {
            MSession cSession = MSession.get(wsc.ctx, false);
            if (cSession != null)
                cSession.logout();
            WebUtil.createLoginPage(request, response, this, ws.ctx, "Exit");
            return;
        }
        executeCommand(request, p_cmd, wsc, ws);
    }
    /**************************************************
		 *  Build Page
		 */
    WebDoc doc = null;
    //  Create Simgle/Multi Row
    if (ws.curTab.isSingleRow())
        doc = getSR_Form(request.getRequestURI(), wsc, ws);
    else
        doc = getMR_Form(request.getRequestURI(), wsc, ws);
    //
    log.fine("Fini");
    //	log.trace(log.l6_Database, doc.toString());
    WebUtil.createResponse(request, response, this, null, doc, false);
    log.fine("Closed");
}
Also used : WebDoc(org.compiere.util.WebDoc) MSession(org.compiere.model.MSession) WebSessionCtx(org.compiere.util.WebSessionCtx)

Aggregations

MSession (org.compiere.model.MSession)9 MUser (org.compiere.model.MUser)3 ApplicationException (org.adempiere.webui.exception.ApplicationException)2 Language (org.compiere.util.Language)2 Page (org.zkoss.zk.ui.Page)2 Session (org.zkoss.zk.ui.Session)2 WrongValueException (org.zkoss.zk.ui.WrongValueException)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 ConfirmPanel (org.adempiere.webui.component.ConfirmPanel)1 Label (org.adempiere.webui.component.Label)1 IDesktop (org.adempiere.webui.desktop.IDesktop)1 TokenEvent (org.adempiere.webui.event.TokenEvent)1 MBPBankAccount (org.compiere.model.MBPBankAccount)1 MTheme (org.compiere.model.MTheme)1 KeyNamePair (org.compiere.util.KeyNamePair)1 Login (org.compiere.util.Login)1 WebDoc (org.compiere.util.WebDoc)1 WebSessionCtx (org.compiere.util.WebSessionCtx)1