Ajax登录ofbiz

public static String login(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    String username=request.getParameter("loginPhone");
    String pwd=request.getParameter("pwd");
    String rember=request.getParameter("rember");
    HttpSession session=request.getSession();

    //登录
    String visitId = VisitHandler.getVisitId(session);
    try {
        Map<String,Object>  result = dispatcher.runSync("userLogin", UtilMisc.toMap(
                "login.username", username, "login.password", pwd,
                "visitId", visitId, "locale",
                UtilHttp.getLocale(request)));
        if(result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS)){
            GenericValue userLogin = (GenericValue) result.get("userLogin");
            Map<String, Object> userLoginSession = checkMap(result.get("userLoginSession"), String.class, Object.class);
            LoginWorker.doMainLogin(request, response, userLogin, userLoginSession);
            //成功
            request.setAttribute("errorCode","success");
            if(UtilValidate.isNotEmpty(rember) && rember.equals("1")){
                //记住密码
                LoginWorker.autoLoginSet(request,response);
            }
        }else{
            request.setAttribute("errorCode","error");
        }
    } catch (GenericServiceException e) {
        e.printStackTrace();
        request.setAttribute("errorCode","error");
    }
    return "success";
}

你可能感兴趣的:(Ajax登录ofbiz)