⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginevents.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (userLoginSession != null) {                session.setAttribute("userLoginSession", userLoginSession);            }        } else {            Map messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));            String errMsg = UtilProperties.getMessage(resource, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        request.setAttribute("_LOGIN_PASSED_", "TRUE");        // run the after-login events        RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());        rh.runAfterLoginEvents(request, response);        // make sure the autoUserLogin is set to the same and that the client cookie has the correct userLoginId        return autoLoginSet(request, response);    }    public static void doBasicLogin(GenericValue userLogin, HttpServletRequest request) {        HttpSession session = request.getSession();        session.setAttribute("userLogin", userLogin);        try {            GenericValue person = userLogin.getRelatedOne("Person");            GenericValue partyGroup = userLogin.getRelatedOne("PartyGroup");            if (person != null) session.setAttribute("person", person);            if (partyGroup != null) session.setAttribute("partyGroup", partyGroup);        } catch (GenericEntityException e) {            Debug.logError(e, "Error getting person/partyGroup info for session, ignoring...", module);        }        // let the visit know who the user is        VisitHandler.setUserLogin(session, userLogin, false);    }    /**     * An HTTP WebEvent handler that logs out a userLogin by clearing the session.     *     * @param request The HTTP request object for the current request.     * @param response The HTTP response object for the current request.     * @return Return a boolean which specifies whether or not the calling request     *        should generate its own content. This allows an event to override the default content.     */    public static String logout(HttpServletRequest request, HttpServletResponse response) {        // run the before-logout events        RequestHandler rh = RequestHandler.getRequestHandler(request.getSession().getServletContext());        rh.runBeforeLogoutEvents(request, response);        // invalidate the security group list cache        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");        doBasicLogout(userLogin, request);        if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {            return autoLoginCheck(request, response);        }        return "success";    }    public static void doBasicLogout(GenericValue userLogin, HttpServletRequest request) {        HttpSession session = request.getSession();        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        Security security = (Security) request.getAttribute("security");        if (security != null && userLogin != null) {            Security.userLoginSecurityGroupByUserLoginId.remove(userLogin.getString("userLoginId"));        }        // set the logged out flag        LoginWorker.setLoggedOut(userLogin.getString("userLoginId"), delegator);        // this is a setting we don't want to lose, although it would be good to have a more general solution here...        String currCatalog = (String) session.getAttribute("CURRENT_CATALOG_ID");        // also make sure the delegatorName is preserved, especially so that a new Visit can be created        String delegatorName = (String) session.getAttribute("delegatorName");        // also save the shopping cart if we have one        // DON'T save the cart, causes too many problems: security issues with things done in cart to easy to miss, especially bad on public systems; was put in here because of the "not me" link for auto-login stuff, but that is a small problem compared to what it causes        //ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");        session.invalidate();        session = request.getSession(true);        if (currCatalog != null) session.setAttribute("CURRENT_CATALOG_ID", currCatalog);        if (delegatorName != null) session.setAttribute("delegatorName", delegatorName);        // DON'T save the cart, causes too many problems: if (shoppingCart != null) session.setAttribute("shoppingCart", new WebShoppingCart(shoppingCart, session));    }    /**     * The user forgot his/her password.  This will either call showPasswordHint or emailPassword.     *     * @param request The HTTPRequest object for the current request     * @param response The HTTPResponse object for the current request     * @return String specifying the exit status of this event     */    public static String forgotPassword(HttpServletRequest request, HttpServletResponse response) {        if ((UtilValidate.isNotEmpty(request.getParameter("GET_PASSWORD_HINT"))) || (UtilValidate.isNotEmpty(request.getParameter("GET_PASSWORD_HINT.x")))) {            return showPasswordHint(request, response);        } else {            return emailPassword(request, response);        }    }    /** Show the password hint for the userLoginId specified in the request object.     *@param request The HTTPRequest object for the current request     *@param response The HTTPResponse object for the current request     *@return String specifying the exit status of this event     */    public static String showPasswordHint(HttpServletRequest request, HttpServletResponse response) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        String userLoginId = request.getParameter("USERNAME");        String errMsg = null;        if ((userLoginId != null) && ("true".equals(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {            userLoginId = userLoginId.toLowerCase();        }        if (!UtilValidate.isNotEmpty(userLoginId)) {            // the password was incomplete            errMsg = UtilProperties.getMessage(resource, "loginevents.username_was_empty_reenter", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        GenericValue supposedUserLogin = null;        try {            supposedUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userLoginId));        } catch (GenericEntityException gee) {            Debug.logWarning(gee, "", module);        }        if (supposedUserLogin == null) {            // the Username was not found            errMsg = UtilProperties.getMessage(resource, "loginevents.username_not_found_reenter", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        String passwordHint = supposedUserLogin.getString("passwordHint");        if (!UtilValidate.isNotEmpty(passwordHint)) {            // the Username was not found            errMsg = UtilProperties.getMessage(resource, "loginevents.no_password_hint_specified_try_password_emailed", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        Map messageMap = UtilMisc.toMap("passwordHint", passwordHint);        errMsg = UtilProperties.getMessage(resource, "loginevents.password_hint_is", messageMap, UtilHttp.getLocale(request));        request.setAttribute("_ERROR_MESSAGE_", errMsg);        return "success";    }    /**     *  Email the password for the userLoginId specified in the request object.     *     * @param request The HTTPRequest object for the current request     * @param response The HTTPResponse object for the current request     * @return String specifying the exit status of this event     */    public static String emailPassword(HttpServletRequest request, HttpServletResponse response) {        String defaultScreenLocation = "component://securityext/widget/EmailSecurityScreens.xml#PasswordEmail";                GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        String productStoreId = ProductStoreWorker.getProductStoreId(request);                String errMsg = null;        Map subjectData = FastMap.newInstance();        subjectData.put("productStoreId", productStoreId);        boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security.properties", "password.encrypt"));        String userLoginId = request.getParameter("USERNAME");        subjectData.put("userLoginId", userLoginId);        if ((userLoginId != null) && ("true".equals(UtilProperties.getPropertyValue("security.properties", "username.lowercase")))) {            userLoginId = userLoginId.toLowerCase();        }        if (!UtilValidate.isNotEmpty(userLoginId)) {            // the password was incomplete            errMsg = UtilProperties.getMessage(resource, "loginevents.username_was_empty_reenter", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        GenericValue supposedUserLogin = null;        String passwordToSend = null;        try {            supposedUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userLoginId));            if (supposedUserLogin == null) {                // the Username was not found                errMsg = UtilProperties.getMessage(resource, "loginevents.username_not_found_reenter", UtilHttp.getLocale(request));                request.setAttribute("_ERROR_MESSAGE_", errMsg);                return "error";            }            if (useEncryption) {                // password encrypted, can't send, generate new password and email to user                double randNum = Math.random();                // multiply by 100,000 to usually make a 5 digit number                passwordToSend = "auto" + ((long) (randNum * 100000));                supposedUserLogin.set("currentPassword", LoginServices.getPasswordHash(passwordToSend));                supposedUserLogin.set("passwordHint", "Auto-Generated Password");            } else {                passwordToSend = supposedUserLogin.getString("currentPassword");            }        } catch (GenericEntityException e) {            Debug.logWarning(e, "", module);            Map messageMap = UtilMisc.toMap("errorMessage", e.toString());            errMsg = UtilProperties.getMessage(resource, "loginevents.error_accessing_password", messageMap, UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        if (supposedUserLogin == null) {            // the Username was not found            Map messageMap = UtilMisc.toMap("userLoginId", userLoginId);            errMsg = UtilProperties.getMessage(resource, "loginevents.user_with_the_username_not_found", messageMap, UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        StringBuffer emails = new StringBuffer();        GenericValue party = null;        try {            party = supposedUserLogin.getRelatedOne("Party");        } catch (GenericEntityException e) {            Debug.logWarning(e, "", module);            party = null;        }        if (party != null) {            Iterator emailIter = UtilMisc.toIterator(ContactHelper.getContactMechByPurpose(party, "PRIMARY_EMAIL", false));            while (emailIter != null && emailIter.hasNext()) {                GenericValue email = (GenericValue) emailIter.next();                emails.append(emails.length() > 0 ? "," : "").append(email.getString("infoString"));            }        }        if (!UtilValidate.isNotEmpty(emails.toString())) {            // the Username was not found            errMsg = UtilProperties.getMessage(resource, "loginevents.no_primary_email_address_set_contact_customer_service", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        // get the ProductStore email settings

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -