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

📄 loginevents.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        GenericValue productStoreEmail = null;        try {            productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", productStoreId, "emailType", "PRDS_PWD_RETRIEVE"));        } catch (GenericEntityException e) {            Debug.logError(e, "Problem getting ProductStoreEmailSetting", module);        }        if (productStoreEmail == null) {            errMsg = UtilProperties.getMessage(resource, "loginevents.problems_with_configuration_contact_customer_service", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");        if (UtilValidate.isEmpty(bodyScreenLocation)) {            bodyScreenLocation = defaultScreenLocation;        }                // set the needed variables in new context        Map bodyParameters = FastMap.newInstance();        bodyParameters.put("useEncryption", new Boolean(useEncryption));        bodyParameters.put("password", UtilFormatOut.checkNull(passwordToSend));        bodyParameters.put("locale", UtilHttp.getLocale(request));        bodyParameters.put("userLogin", supposedUserLogin);        Map serviceContext = FastMap.newInstance();        serviceContext.put("bodyScreenUri", bodyScreenLocation);        serviceContext.put("bodyParameters", bodyParameters);        serviceContext.put("subject", productStoreEmail.getString("subject"));        serviceContext.put("sendFrom", productStoreEmail.get("fromAddress"));        serviceContext.put("sendCc", productStoreEmail.get("ccAddress"));        serviceContext.put("sendBcc", productStoreEmail.get("bccAddress"));        serviceContext.put("contentType", productStoreEmail.get("contentType"));        serviceContext.put("sendTo", emails.toString());        try {            Map result = dispatcher.runSync("sendMailFromScreen", serviceContext);            if (ModelService.RESPOND_ERROR.equals((String) result.get(ModelService.RESPONSE_MESSAGE))) {                Map messageMap = UtilMisc.toMap("errorMessage", result.get(ModelService.ERROR_MESSAGE));                errMsg = UtilProperties.getMessage(resource, "loginevents.error_unable_email_password_contact_customer_service_errorwas", messageMap, UtilHttp.getLocale(request));                request.setAttribute("_ERROR_MESSAGE_", errMsg);                return "error";            }        } catch (GenericServiceException e) {            Debug.logWarning(e, "", module);            errMsg = UtilProperties.getMessage(resource, "loginevents.error_unable_email_password_contact_customer_service", UtilHttp.getLocale(request));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        // don't save password until after it has been sent        if (useEncryption) {            try {                supposedUserLogin.store();            } catch (GenericEntityException e) {                Debug.logWarning(e, "", module);                Map messageMap = UtilMisc.toMap("errorMessage", e.toString());                errMsg = UtilProperties.getMessage(resource, "loginevents.error_saving_new_password_email_not_correct_password", messageMap, UtilHttp.getLocale(request));                request.setAttribute("_ERROR_MESSAGE_", errMsg);                return "error";            }        }        if (useEncryption) {            errMsg = UtilProperties.getMessage(resource, "loginevents.new_password_createdandsent_check_email", UtilHttp.getLocale(request));            request.setAttribute("_EVENT_MESSAGE_", errMsg);        } else {            errMsg = UtilProperties.getMessage(resource, "loginevents.new_password_sent_check_email", UtilHttp.getLocale(request));            request.setAttribute("_EVENT_MESSAGE_", errMsg);        }        return "success";    }    protected static String getAutoLoginCookieName(HttpServletRequest request) {        return UtilHttp.getApplicationName(request) + ".autoUserLoginId";    }    public static String getAutoUserLoginId(HttpServletRequest request) {        String autoUserLoginId = null;        Cookie[] cookies = request.getCookies();        if (Debug.verboseOn()) Debug.logVerbose("Cookies:" + cookies, module);        if (cookies != null) {            for (int i = 0; i < cookies.length; i++) {                if (cookies[i].getName().equals(getAutoLoginCookieName(request))) {                    autoUserLoginId = cookies[i].getValue();                    break;                }            }        }        return autoUserLoginId;    }    public static String autoLoginCheck(HttpServletRequest request, HttpServletResponse response) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        HttpSession session = request.getSession();        return autoLoginCheck(delegator, session, getAutoUserLoginId(request));    }    private static String autoLoginCheck(GenericDelegator delegator, HttpSession session, String autoUserLoginId) {        if (autoUserLoginId != null) {            Debug.logInfo("Running autoLogin check.", module);            try {                GenericValue autoUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", autoUserLoginId));                GenericValue person = null;                GenericValue group = null;                if (autoUserLogin != null) {                    person = delegator.findByPrimaryKey("Person", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));                    group = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", autoUserLogin.getString("partyId")));                    session.setAttribute("autoUserLogin", autoUserLogin);                }                if (person != null) {                    session.setAttribute("autoName", person.getString("firstName") + " " + person.getString("lastName"));                } else if (group != null) {                    session.setAttribute("autoName", group.getString("groupName"));                }            } catch (GenericEntityException e) {                Debug.logError(e, "Cannot get autoUserLogin information: " + e.getMessage(), module);            }        }        return "success";    }    public static String autoLoginSet(HttpServletRequest request, HttpServletResponse response) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        HttpSession session = request.getSession();        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");        if (userLogin != null) {            Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));            autoLoginCookie.setMaxAge(60 * 60 * 24 * 365);            autoLoginCookie.setPath("/");            response.addCookie(autoLoginCookie);            return autoLoginCheck(delegator, session, userLogin.getString("userLoginId"));        } else {            return "success";        }    }    public static String autoLoginRemove(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        GenericValue userLogin = (GenericValue) session.getAttribute("autoUserLogin");        // remove the cookie        if (userLogin != null) {            Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId"));            autoLoginCookie.setMaxAge(0);            autoLoginCookie.setPath("/");            response.addCookie(autoLoginCookie);        }        // remove the session attributes        session.removeAttribute("autoUserLogin");        session.removeAttribute("autoName");        // logout the user if logged in.        if (session.getAttribute("userLogin") != null) {            request.setAttribute("_AUTO_LOGIN_LOGOUT_", new Boolean(true));            return logout(request, response);        }        return "success";    }    public static String checkExternalLoginKey(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        String externalKey = request.getParameter(LoginWorker.EXTERNAL_LOGIN_KEY_ATTR);        if (externalKey == null) return "success";        GenericValue userLogin = (GenericValue) LoginWorker.externalLoginKeys.get(externalKey);        if (userLogin != null) {            // found userLogin, do the external login...            // if the user is already logged in and the login is different, logout the other user            GenericValue currentUserLogin = (GenericValue) session.getAttribute("userLogin");            if (currentUserLogin != null) {                if (currentUserLogin.getString("userLoginId").equals(userLogin.getString("userLoginId"))) {                    // is the same user, just carry on...                    return "success";                }                // logout the current user and login the new user...                logout(request, response);                // ignore the return value; even if the operation failed we want to set the new UserLogin            }            doBasicLogin(userLogin, request);        } else {            Debug.logWarning("Could not find userLogin for external login key: " + externalKey, module);        }        return "success";    }    public static boolean isFlaggedLoggedOut(GenericValue userLogin) {        if ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "login.disable.global.logout"))) {            return false;        }        if (userLogin == null || userLogin.get("userLoginId") == null) {            return true;        }        // refresh the login object -- maybe cache this?        try {            userLogin.refreshFromCache();        } catch (GenericEntityException e) {            Debug.logWarning(e, "Unable to refresh UserLogin", module);        }        return (userLogin.get("hasLoggedOut") != null ?                "Y".equalsIgnoreCase(userLogin.getString("hasLoggedOut")) : false);    }    protected static boolean hasBasePermission(GenericValue userLogin, HttpServletRequest request) {        ServletContext context = (ServletContext) request.getAttribute("servletContext");        Security security = (Security) request.getAttribute("security");        String serverId = (String) context.getAttribute("_serverId");        String contextPath = request.getContextPath();        ComponentConfig.WebappInfo info = ComponentConfig.getWebAppInfo(serverId, contextPath);        if (security != null) {            if (info != null) {                String[] permissions = info.getBasePermission();                for (int i = 0; i < permissions.length; i++) {                    if (("NONE".equals(permissions[i])) || (security.hasEntityPermission(permissions[i], "_VIEW", userLogin))) {                        return true;                    }                }            } else {                Debug.logInfo("No webapp configuration found for : " + serverId + " / " + contextPath, module);            }        } else {            Debug.logWarning("Received a null Security object from HttpServletRequest", module);        }        return false;    }    public static String storeCheckLogin(HttpServletRequest request, HttpServletResponse response) {        String responseString = LoginEvents.checkLogin(request, response);        if ("error".equals(responseString)) {            return responseString;        }        // if we are logged in okay, do the check store customer role        return ProductEvents.checkStoreCustomerRole(request, response);    }    public static String storeLogin(HttpServletRequest request, HttpServletResponse response) {        String responseString = LoginEvents.login(request, response);        if ("error".equals(responseString)) {            return responseString;        }        // if we logged in okay, do the check store customer role        return ProductEvents.checkStoreCustomerRole(request, response);    }}

⌨️ 快捷键说明

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