Search in sources :

Example 1 with IForm

use of cn.cerc.jbean.form.IForm in project summer-mis by cn-cerc.

the class StartForms method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    String uri = req.getRequestURI();
    // 遇到静太文件直接输出
    if (isStatic(uri)) {
        chain.doFilter(req, resp);
        return;
    }
    log.info(uri);
    String childCode = getRequestCode(req);
    if (childCode == null) {
        req.setAttribute("message", "无效的请求:" + childCode);
        req.getRequestDispatcher(Application.getAppConfig().getJspErrorFile()).forward(req, resp);
        return;
    }
    String[] params = childCode.split("\\.");
    String formId = params[0];
    String funcCode = params.length == 1 ? "execute" : params[1];
    req.setAttribute("logon", false);
    // 验证菜单是否启停
    if (Application.containsBean("AppFormFilter")) {
        IFormFilter formFilter = Application.getBean("AppFormFilter", IFormFilter.class);
        if (formFilter != null) {
            if (formFilter.doFilter(resp, formId, funcCode)) {
                return;
            }
        }
    }
    IForm form = null;
    try {
        form = createForm(req, resp, formId);
        if (form == null) {
            req.setAttribute("message", "error servlet:" + req.getServletPath());
            AppConfig conf = createConfig();
            req.getRequestDispatcher(conf.getJspErrorFile()).forward(req, resp);
            return;
        }
        // 设备讯息
        ClientDevice info = new ClientDevice(form);
        info.setRequest(req);
        req.setAttribute("_showMenu_", !ClientDevice.device_ee.equals(info.getDevice()));
        form.setClient(info);
        // 建立数据库资源
        try (AppHandle handle = createHandle(req)) {
            try {
                handle.setProperty(Application.sessionId, req.getSession().getId());
                handle.setProperty(Application.deviceLanguage, info.getLanguage());
                req.setAttribute("myappHandle", handle);
                form.setHandle(handle);
                log.debug("进行安全检查,若未登录则显示登录对话框");
                IAppLogin page = createLogin(form);
                if (page.checkSecurity(info.getSid())) {
                    String corpNo = handle.getCorpNo();
                    if (null != corpNo && !"".equals(corpNo)) {
                        String tempStr = String.format("调用菜单: %s(%s), 用户:%s", form.getTitle(), formId, handle.getUserName());
                        log.info(tempStr);
                    }
                    // 进行维护检查,在每月的最后一天晚上11点到下个月的第一天早上5点,不允许使用系统
                    if (checkEnableTime())
                        callForm(form, funcCode);
                }
            } catch (Exception e) {
                Throwable err = e.getCause();
                if (err == null)
                    err = e;
                req.setAttribute("msg", err.getMessage());
                ErrorPage opera = new ErrorPage(form, err);
                opera.execute();
            }
        }
    } catch (Exception e) {
        log.error(childCode + ":" + e.getMessage());
        req.setAttribute("message", e.getMessage());
        AppConfig conf = Application.getAppConfig();
        req.getRequestDispatcher(conf.getJspErrorFile()).forward(req, resp);
        return;
    }
}
Also used : AppConfig(cn.cerc.jbean.core.AppConfig) ErrorPage(cn.cerc.jmis.page.ErrorPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) IForm(cn.cerc.jbean.form.IForm) AppHandle(cn.cerc.jbean.core.AppHandle) PageException(cn.cerc.jbean.core.PageException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) IAppLogin(cn.cerc.jbean.tools.IAppLogin)

Example 2 with IForm

use of cn.cerc.jbean.form.IForm in project summer-mis by cn-cerc.

the class StartApp method doFilter.

// private static final Logger log = Logger.getLogger(AppStart.class);
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    String uri = req.getRequestURI();
    // 处理默认首页问题
    if (uri.equals("/")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        AppConfig conf = Application.getAppConfig();
        resp.sendRedirect(String.format("/%s/%s", conf.getPathForms(), conf.getFormWelcome()));
        return;
    } else if (uri.equals("/MobileConfig")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        try {
            IForm form = Application.getBean("MobileConfig", IForm.class);
            form.setRequest((HttpServletRequest) request);
            form.setResponse((HttpServletResponse) response);
            try (AppHandle handle = new AppHandle()) {
                handle.setProperty(Application.sessionId, req.getSession().getId());
                form.setHandle(handle);
            }
            IPage page = form.execute();
            page.execute();
        } catch (Exception e) {
            resp.getWriter().print(e.getMessage());
        }
        return;
    }
    chain.doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AppConfig(cn.cerc.jbean.core.AppConfig) IPage(cn.cerc.jbean.form.IPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) IForm(cn.cerc.jbean.form.IForm) AppHandle(cn.cerc.jbean.core.AppHandle) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with IForm

use of cn.cerc.jbean.form.IForm in project summer-mis by cn-cerc.

the class AppLoginPage method checkLogin.

@Override
public boolean checkLogin(String userCode, String password) throws ServletException, IOException {
    IForm form = this.getForm();
    HttpServletRequest req = this.getRequest();
    log.debug(String.format("校验用户帐号(%s)与密码", userCode));
    // 进行设备首次登记
    String deviceId = form.getClient().getId();
    req.setAttribute("userCode", userCode);
    req.setAttribute("password", password);
    req.setAttribute("needVerify", "false");
    // 如长度大于10表示用手机号码登入
    if (userCode.length() > 10) {
        String oldCode = userCode;
        userCode = getAccountFromTel(form.getHandle(), oldCode);
        log.debug(String.format("将手机号 %s 转化成帐号 %s", oldCode, userCode));
    }
    boolean result = false;
    log.debug(String.format("进行用户帐号(%s)与密码认证", userCode));
    // 进行用户名、密码认证
    LocalService app;
    if (form instanceof AbstractForm)
        app = new LocalService((AbstractForm) form);
    else
        app = new LocalService(form.getHandle());
    app.setService("SvrUserLogin.check");
    String IP = getIPAddress();
    if (app.exec("Account_", userCode, "Password_", password, "MachineID_", deviceId, "ClientIP_", IP, "Language_", form.getClient().getLanguage())) {
        String sid = app.getDataOut().getHead().getString("SessionID_");
        if (sid != null && !sid.equals("")) {
            log.debug(String.format("认证成功,取得sid(%s)", sid));
            ((ClientDevice) this.getForm().getClient()).setSid(sid);
            result = true;
        }
    } else {
        // 登陆验证失败,进行判断,手机号为空,则回到登陆页,手机不为空,密码为空,则跳到发送验证码页面
        String mobile = Utils.safeString(app.getDataOut().getHead().getString("Mobile_"));
        if (mobile == null || "".equals(mobile)) {
            log.debug(String.format("用户帐号(%s)与密码认证失败", userCode));
            req.setAttribute("loginMsg", app.getMessage());
            this.execute();
        } else if (password == null || "".equals(password)) {
            getResponse().sendRedirect("TFrmEasyReg?phone=" + mobile);
            return false;
        } else {
            log.debug(String.format("用户帐号(%s)与密码认证失败", userCode));
            req.setAttribute("loginMsg", app.getMessage());
            this.execute();
        }
    }
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IForm(cn.cerc.jbean.form.IForm) AbstractForm(cn.cerc.jmis.form.AbstractForm) LocalService(cn.cerc.jbean.client.LocalService) ClientDevice(cn.cerc.jmis.core.ClientDevice)

Example 4 with IForm

use of cn.cerc.jbean.form.IForm in project summer-mis by cn-cerc.

the class UIPagePhone method execute.

@Override
public void execute() throws ServletException, IOException {
    HttpServletRequest request = getRequest();
    IForm form = this.getForm();
    CustomHandle sess = (CustomHandle) form.getHandle().getProperty(null);
    if (sess.logon()) {
        List<UrlRecord> rightMenus = getHeader().getRightMenus();
        RightMenus menus = Application.getBean("RightMenus", RightMenus.class);
        menus.setHandle(form.getHandle());
        for (IMenuBar item : menus.getItems()) item.enrollMenu(form, rightMenus);
    } else {
        getHeader().getHomePage().setSite(Application.getAppConfig().getFormWelcome());
    }
    // 系统通知消息
    Component content = this.getContent();
    if (form instanceof AbstractForm) {
        this.getHeader().initHeader();
        request.setAttribute(content.getId(), content);
        for (Component component : content.getComponents()) {
            request.setAttribute(component.getId(), component);
        }
    }
    // 开始输出
    PrintWriter out = getResponse().getWriter();
    out.println("<!DOCTYPE html>");
    out.println("<html>");
    out.println("<head>");
    out.printf("<title>%s</title>\n", this.getForm().getTitle());
    out.printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n");
    out.printf("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n");
    out.println("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9; IE=8; IE=7;\"/>");
    out.printf("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0\"/>\n");
    out.print(this.getCssHtml());
    out.print(getScriptHtml());
    out.println("<script>");
    out.println("var Application = new TApplication();");
    out.printf("Application.device = '%s';\n", form.getClient().getDevice());
    out.printf("Application.bottom = '%s';\n", this.getFooter().getId());
    String msg = form.getParam("message", "");
    msg = msg == null ? "" : msg.replaceAll("\r\n", "<br/>");
    out.printf("Application.message = '%s';\n", msg);
    out.printf("Application.searchFormId = '%s';\n", this.searchWaitingId);
    out.println("$(document).ready(function() {");
    out.println("Application.init();");
    out.println("});");
    out.println("</script>");
    out.println("</head>");
    outBody(out);
    out.println("</html>");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IMenuBar(cn.cerc.jmis.page.IMenuBar) IForm(cn.cerc.jbean.form.IForm) UrlRecord(cn.cerc.jpage.core.UrlRecord) AbstractForm(cn.cerc.jmis.form.AbstractForm) CustomHandle(cn.cerc.jbean.core.CustomHandle) Component(cn.cerc.jpage.core.Component) RightMenus(cn.cerc.jui.parts.RightMenus) PrintWriter(java.io.PrintWriter)

Example 5 with IForm

use of cn.cerc.jbean.form.IForm in project summer-bean by cn-cerc.

the class Application method getForm.

public static IForm getForm(HttpServletRequest req, HttpServletResponse resp, String formId) {
    if (formId == null || formId.equals("") || formId.equals("service"))
        return null;
    init();
    formItems = getFormItems();
    if (!formItems.containsBean(formId)) {
        throw new RuntimeException(String.format("form %s not find!", formId));
    }
    IForm form = formItems.getBean(formId, IForm.class);
    form.setRequest(req);
    form.setResponse(resp);
    return form;
}
Also used : IForm(cn.cerc.jbean.form.IForm)

Aggregations

IForm (cn.cerc.jbean.form.IForm)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 AbstractForm (cn.cerc.jmis.form.AbstractForm)7 UrlRecord (cn.cerc.jpage.core.UrlRecord)7 CustomHandle (cn.cerc.jbean.core.CustomHandle)6 IMenuBar (cn.cerc.jmis.page.IMenuBar)6 Component (cn.cerc.jpage.core.Component)6 RightMenus (cn.cerc.jui.parts.RightMenus)6 PrintWriter (java.io.PrintWriter)5 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 AppConfig (cn.cerc.jbean.core.AppConfig)2 AppHandle (cn.cerc.jbean.core.AppHandle)2 OperaPages (cn.cerc.jpage.other.OperaPages)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LocalService (cn.cerc.jbean.client.LocalService)1 PageException (cn.cerc.jbean.core.PageException)1 IPage (cn.cerc.jbean.form.IPage)1 IAppLogin (cn.cerc.jbean.tools.IAppLogin)1 IHandle (cn.cerc.jdb.core.IHandle)1