Search in sources :

Example 1 with CustomHandle

use of cn.cerc.jbean.core.CustomHandle 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 2 with CustomHandle

use of cn.cerc.jbean.core.CustomHandle in project summer-bean by cn-cerc.

the class AppSessionRestore method byToken.

public boolean byToken() throws ServiceException {
    Record headIn = getDataIn().getHead();
    DataValidateException.stopRun("token不允许为空", !headIn.hasValue("token"));
    String token = headIn.getString("token");
    SqlQuery cdsCurrent = new SqlQuery(this);
    cdsCurrent.add("select CorpNo_,UserID_,LoginTime_,Account_ as UserCode_,Language_ ");
    cdsCurrent.add("from %s", SystemTable.get(SystemTable.getCurrentUser));
    cdsCurrent.add("where loginID_= '%s' ", token);
    cdsCurrent.open();
    if (cdsCurrent.eof()) {
        log.warn(String.format("token %s 没有找到!", token));
        CustomHandle sess = (CustomHandle) this.getProperty(null);
        sess.setProperty(Application.token, null);
        return false;
    }
    String userId = cdsCurrent.getString("UserID_");
    SqlQuery cdsUser = new SqlQuery(this);
    cdsUser.add("select ID_,Code_,DiyRole_,RoleCode_,CorpNo_, Name_ as UserName_,ProxyUsers_");
    cdsUser.add("from %s", SystemTable.get(SystemTable.getUserInfo), userId);
    cdsUser.add("where ID_='%s'", userId);
    cdsUser.open();
    if (cdsUser.eof()) {
        log.warn(String.format("userId %s 没有找到!", userId));
        CustomHandle sess = (CustomHandle) this.getProperty(null);
        sess.setProperty(Application.token, null);
        return false;
    }
    Record headOut = getDataOut().getHead();
    headOut.setField("LoginTime_", cdsCurrent.getDateTime("LoginTime_"));
    headOut.setField("Language_", cdsCurrent.getString("Language_"));
    copyData(cdsUser, headOut);
    return true;
}
Also used : SqlQuery(cn.cerc.jdb.mysql.SqlQuery) Record(cn.cerc.jdb.core.Record) CustomHandle(cn.cerc.jbean.core.CustomHandle)

Example 3 with CustomHandle

use of cn.cerc.jbean.core.CustomHandle in project summer-mis by cn-cerc.

the class SvrUserLogin method Check.

/*
     * 用户登录入口
     */
@Webfunc
public boolean Check() throws SecurityCheckException {
    Record headIn = getDataIn().getHead();
    getDataOut().getHead().setField("errorNo", 0);
    String deviceId = headIn.getString("MachineID_");
    // 判断是否为浏览器登陆
    if (Application.webclient.equals(deviceId)) {
        throw new SecurityCheckException("系统不支持使用web浏览器登录,请使用客户端登录系统!");
    }
    String device_name = "";
    if (headIn.hasValue("ClientName_")) {
        device_name = headIn.getString("ClientName_");
    } else {
        device_name = "unknow";
    }
    CustomHandle sess = (CustomHandle) this.getProperty(null);
    if (headIn.exists("ClientIP_")) {
        sess.setProperty(Application.clientIP, headIn.getString("ClientIP_"));
    } else {
        sess.setProperty(Application.clientIP, "0.0.0.0");
    }
    // 开始进行用户验证
    String userCode = headIn.getString("Account_");
    if (userCode.equals("")) {
        throw new SecurityCheckException("用户帐号不允许为空!");
    }
    SqlQuery dsUser = new SqlQuery(this);
    dsUser.add("select UID_,CorpNo_,ID_,Code_,Name_,Mobile_,DeptCode_,Enabled_,Password_,BelongAccount_,");
    dsUser.add("VerifyTimes_,Encrypt_,SecurityLevel_,SecurityMachine_,PCMachine1_,PCMachine2_,");
    dsUser.add("PCMachine3_,RoleCode_,DiyRole_ from %s where Code_='%s'", SystemTable.get(SystemTable.getUserInfo), userCode);
    dsUser.open();
    if (dsUser.eof()) {
        throw new SecurityCheckException(String.format("该帐号(%s)并不存在,禁止登录!", userCode));
    }
    String corpNo = dsUser.getString("CorpNo_");
    BookInfoRecord buff = MemoryBookInfo.get(this, corpNo);
    if (buff == null) {
        throw new SecurityCheckException(String.format("没有找到注册的帐套  %s ", corpNo));
    }
    boolean YGLogin = buff.getCorpType() == BookVersion.ctFree.ordinal();
    if (buff.getStatus() == 3) {
        throw new SecurityCheckException("对不起,您的账套处于暂停录入状态,禁止登录!若需启用,请您联系客服处理!");
    }
    if (buff.getStatus() == 4) {
        throw new SecurityCheckException("对不起,您的帐套已过期,请联系客服续费!");
    }
    if (dsUser.getInt("Enabled_") < 1 && dsUser.getInt("VerifyTimes_") == 6) {
        throw new SecurityCheckException(String.format("该帐号(%s)因输入错误密码或验证码次数达到6次,已被自动停用,禁止登录!若需启用,请您联系客服处理!", userCode));
    }
    if (dsUser.getInt("Enabled_") < 1) {
        throw new SecurityCheckException(String.format("该帐号(%s)被暂停使用,禁止登录!若需启用,请您联系客服处理!", userCode));
    }
    // 判断此帐号是否为附属帐号
    if (dsUser.getString("BelongAccount_") != null && !"".equals(dsUser.getString("BelongAccount_"))) {
        throw new SecurityCheckException(String.format("该帐号已被设置为附属帐号,不允许登录,请使用主帐号 %s 登录系统!", dsUser.getString("BelongAccount_")));
    }
    // 取得认证密码,若是微信入口进入,则免密码录入
    String password = headIn.getString("Password_");
    if (password == null || "".equals(password)) {
        if ("".equals(dsUser.getString("Mobile_"))) {
            throw new RuntimeException("您没有登记手机号,请您输入密码进行登陆!");
        } else {
            getDataOut().getHead().setField("Mobile_", dsUser.getString("Mobile_"));
            throw new RuntimeException("用户密码不允许为空!");
        }
    }
    // 检查设备码
    enrollMachineInfo(dsUser.getString("CorpNo_"), userCode, deviceId, device_name);
    if (dsUser.getBoolean("Encrypt_")) {
        if (!headIn.exists("wx") && !"000000".equals(password)) {
            password = MD5.get(dsUser.getString("Code_") + password);
        }
    }
    if (!isAutoLogin(userCode, deviceId) && !"000000".equals(password)) {
        if (!dsUser.getString("Password_").equals(password)) {
            dsUser.edit();
            if (dsUser.getInt("VerifyTimes_") == 6) {
                // 该账号设置停用
                dsUser.setField("Enabled_", 0);
                dsUser.post();
                throw new RuntimeException("您输入密码的错误次数已超出规定次数,现账号已被自动停用,若需启用,请您联系客服处理!");
            } else {
                dsUser.setField("VerifyTimes_", dsUser.getInt("VerifyTimes_") + 1);
                dsUser.post();
                if (dsUser.getInt("VerifyTimes_") > 3) {
                    throw new SecurityCheckException(String.format("您输入密码的错误次数已达 %d 次,输错超过6次时,您的账号将被自动停用!", dsUser.getInt("VerifyTimes_")));
                } else {
                    throw new SecurityCheckException("您的登录密码错误,禁止登录!");
                }
            }
        }
    }
    // 当前设备是否已被停用
    if (!isStopUsed(userCode, deviceId)) {
        throw new SecurityCheckException("您的当前设备已被停用,禁止登录,请联系管理员恢复启用!");
    }
    try (Transaction tx = new Transaction(this)) {
        String sql = String.format("update %s set LastTime_=now() where UserCode_='%s' and MachineCode_='%s' and Used_=1", SystemTable.get(SystemTable.getDeviceVerify), userCode, deviceId);
        getConnection().execute(sql);
        // 若该账套是待安装,则改为已启用
        SqlQuery dsCorp = new SqlQuery(this);
        dsCorp.add("select * from %s ", SystemTable.get(SystemTable.getBookInfo));
        dsCorp.add("where CorpNo_='%s' and Status_=1 ", corpNo);
        dsCorp.open();
        if (!dsCorp.eof()) {
            dsCorp.edit();
            dsCorp.setField("Status_", 2);
            dsCorp.post();
            MemoryBookInfo.clear(corpNo);
        }
        sess.setProperty(Application.token, GuidFixStr(newGuid()));
        sess.setProperty(Application.userId, dsUser.getString("ID_"));
        sess.setProperty(Application.bookNo, dsUser.getString("CorpNo_"));
        sess.setProperty(Application.userCode, dsUser.getString("Code_"));
        if (dsUser.getBoolean("DiyRole_")) {
            sess.setProperty(Application.roleCode, dsUser.getString("Code_"));
        } else {
            sess.setProperty(Application.roleCode, dsUser.getString("RoleCode_"));
        }
        // 更新当前用户总数
        updateCurrentUser(device_name, headIn.getString("Screen_"), headIn.getString("Language_"));
        try (MemoryBuffer Buff = new MemoryBuffer(BufferType.getSessionInfo, (String) getProperty(Application.userId), deviceId)) {
            Buff.setField("UserID_", getProperty(Application.userId));
            Buff.setField("UserCode_", getUserCode());
            Buff.setField("UserName_", getUserName());
            Buff.setField("LoginTime_", sess.getProperty(Application.loginTime));
            Buff.setField("YGUser", YGLogin);
            Buff.setField("VerifyMachine", false);
        }
        // 返回值于前台
        getDataOut().getHead().setField("SessionID_", getProperty(Application.token));
        getDataOut().getHead().setField("UserID_", getProperty(Application.userId));
        getDataOut().getHead().setField("UserCode_", getUserCode());
        getDataOut().getHead().setField("CorpNo_", handle.getCorpNo());
        getDataOut().getHead().setField("YGUser", YGLogin);
        // 验证成功,将验证次数赋值为0
        dsUser.edit();
        dsUser.setField("VerifyTimes_", 0);
        dsUser.post();
        tx.commit();
        return true;
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) SqlQuery(cn.cerc.jdb.mysql.SqlQuery) Transaction(cn.cerc.jdb.mysql.Transaction) Record(cn.cerc.jdb.core.Record) CustomHandle(cn.cerc.jbean.core.CustomHandle) Webfunc(cn.cerc.jbean.core.Webfunc)

Example 4 with CustomHandle

use of cn.cerc.jbean.core.CustomHandle in project summer-mis by cn-cerc.

the class UIPageDialog method execute.

@Override
public void execute() throws ServletException, IOException {
    // 此行代码不能删除!
    this.getFooter();
    IForm form = this.getForm();
    HttpServletRequest request = form.getRequest();
    CustomHandle sess = (CustomHandle) form.getHandle().getProperty(null);
    request.setAttribute("passport", sess.logon());
    request.setAttribute("logon", sess.logon());
    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());
    }
    // 设置首页
    request.setAttribute("_showMenu_", "true".equals(form.getParam("showMenus", "true")));
    // 系统通知消息
    if (request.getAttribute("message") == null)
        request.setAttribute("message", "");
    if (form instanceof AbstractForm) {
        if (this.isShowMenus())
            this.getHeader().initHeader();
    }
    String msg = form.getParam("message", "");
    request.setAttribute("msg", msg == null ? "" : msg.replaceAll("\r\n", "<br/>"));
    request.setAttribute("formno", form.getParam("formNo", "000"));
    request.setAttribute("form", form);
    // 添加分页控制
    Component operaPages = null;
    if (pages != null) {
        this.put("pages", pages);
        operaPages = new OperaPages(this.getToolBar(), this.getForm(), pages);
        this.put("_operaPages_", operaPages);
    }
    // 输出jsp模版
    String url = String.format("/WEB-INF/%s/%s", Application.getAppConfig().getPathForms(), this.getViewFile());
    getRequest().getServletContext().getRequestDispatcher(url).forward(getRequest(), getResponse());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OperaPages(cn.cerc.jpage.other.OperaPages) 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)

Example 5 with CustomHandle

use of cn.cerc.jbean.core.CustomHandle in project summer-mis by cn-cerc.

the class UIPageModify 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.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)

Aggregations

CustomHandle (cn.cerc.jbean.core.CustomHandle)8 IForm (cn.cerc.jbean.form.IForm)6 AbstractForm (cn.cerc.jmis.form.AbstractForm)6 IMenuBar (cn.cerc.jmis.page.IMenuBar)6 Component (cn.cerc.jpage.core.Component)6 UrlRecord (cn.cerc.jpage.core.UrlRecord)6 RightMenus (cn.cerc.jui.parts.RightMenus)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PrintWriter (java.io.PrintWriter)5 Record (cn.cerc.jdb.core.Record)2 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)2 OperaPages (cn.cerc.jpage.other.OperaPages)2 Webfunc (cn.cerc.jbean.core.Webfunc)1 MemoryBuffer (cn.cerc.jbean.other.MemoryBuffer)1 Transaction (cn.cerc.jdb.mysql.Transaction)1 UIComponent (cn.cerc.jui.parts.UIComponent)1