Search in sources :

Example 1 with DataValidateException

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

the class SvrUserLoginTest method test_sendVerifyCode.

@Test
@Ignore(value = "此处用于测试在5分钟内不允许重复申请验证码,耗时很长")
public void test_sendVerifyCode() throws InterruptedException, DataValidateException {
    String corpNo = "911001";
    String userCode = "91100123";
    String deviceId = "TEST";
    try (StubHandle handle = new StubHandle(corpNo, userCode)) {
        // 清空缓存
        try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, handle.getUserCode(), SvrUserLogin.class.getName(), "sendVerifyCode")) {
            buff.clear();
        }
        // 检查验证码是否存在
        SqlQuery ds = new SqlQuery(handle);
        ds.add("select * from %s", SystemTable.get(SystemTable.getDeviceVerify));
        ds.add("where CorpNo_='%s'", corpNo);
        ds.add("and UserCode_='%s'", userCode);
        ds.add("and MachineCode_='%s'", deviceId);
        ds.open();
        String msg = String.format("帐号 %s 验证码 %s 不存在,无法完成测试", userCode, deviceId);
        assertThat(msg, ds.eof(), is(false));
        SvrUserLogin app = new SvrUserLogin();
        app.init(handle);
        app.getDataIn().getHead().setField("deviceId", deviceId);
        assertThat(app.sendVerifyCode(), is(true));
        Thread.sleep(1000 * 30);
        try {
            app.sendVerifyCode();
            assertThat("此处不应该执行到", false, is(true));
        } catch (Exception e) {
            e.printStackTrace();
            assertThat(e.getMessage().indexOf("5 分钟") > 0, is(true));
        }
        Thread.sleep(1000 * 60 * SvrUserLogin.TimeOut);
        assertThat(app.sendVerifyCode(), is(true));
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) StubHandle(cn.cerc.jbean.rds.StubHandle) SqlQuery(cn.cerc.jdb.mysql.SqlQuery) DataValidateException(cn.cerc.jbean.core.DataValidateException) ServiceException(cn.cerc.jbean.core.ServiceException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DataValidateException

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

the class SecurityEnvironment method check.

// 用于Form中,向UI(jsp)传递当前是否安全,若不安全则显示输入验证码画面
public static boolean check(AbstractJspPage jspPage) {
    AbstractForm form = (AbstractForm) jspPage.getForm();
    boolean result = isSecurity(form);
    if (form.getRequest().getParameter("checkSecurity") != null) {
        try {
            safetyCheck(form);
            result = true;
        } catch (DataValidateException e) {
            jspPage.add("message", e.getMessage());
            result = false;
        }
    }
    if (result) {
        jspPage.add("securityEnvironment", true);
    } else {
        jspPage.setJspFile("common/SecurityVerify.jsp");
    }
    return result;
}
Also used : DataValidateException(cn.cerc.jbean.core.DataValidateException) AbstractForm(cn.cerc.jmis.form.AbstractForm)

Example 3 with DataValidateException

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

the class SecurityEnvironment method backCheck.

// 后台环境安全检测
public static boolean backCheck(AbstractJspPage jspPage) {
    AbstractForm form = (AbstractForm) jspPage.getForm();
    boolean result = isSecurity(form);
    if (form.getRequest().getParameter("checkSecurity") != null) {
        try {
            safetyCheck(form);
            result = true;
        } catch (DataValidateException e) {
            jspPage.add("message", e.getMessage());
            result = false;
        }
    }
    if (result) {
        jspPage.add("securityEnvironment", true);
    } else {
        jspPage.setJspFile("common/SecurityVerify-back.jsp");
    }
    return result;
}
Also used : DataValidateException(cn.cerc.jbean.core.DataValidateException) AbstractForm(cn.cerc.jmis.form.AbstractForm)

Aggregations

DataValidateException (cn.cerc.jbean.core.DataValidateException)3 AbstractForm (cn.cerc.jmis.form.AbstractForm)2 ServiceException (cn.cerc.jbean.core.ServiceException)1 MemoryBuffer (cn.cerc.jbean.other.MemoryBuffer)1 StubHandle (cn.cerc.jbean.rds.StubHandle)1 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1