Search in sources :

Example 6 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-bean by cn-cerc.

the class CustomHandle method init.

@Override
public boolean init(String corpNo, String userCode, String clientCode) {
    String token = GuidFixStr(cn.cerc.jdb.other.utils.newGuid());
    this.setProperty(Application.token, token);
    this.setProperty(Application.bookNo, corpNo);
    this.setProperty(Application.userCode, userCode);
    this.setProperty(Application.clientIP, clientCode);
    LocalService svr = new LocalService(this, "AppSessionRestore.byUserCode");
    if (!svr.exec("userCode", userCode)) {
        throw new RuntimeException(new UserNotFindException(userCode));
    }
    Record headOut = svr.getDataOut().getHead();
    this.setProperty(Application.userId, headOut.getString("UserID_"));
    this.setProperty(Application.loginTime, headOut.getDateTime("LoginTime_"));
    this.setProperty(Application.roleCode, headOut.getString("RoleCode_"));
    this.setProperty(Application.ProxyUsers, headOut.getString("ProxyUsers_"));
    this.setProperty(Application.userName, headOut.getString("UserName_"));
    this.setProperty(Application.deviceLanguage, headOut.getString("Language_"));
    try (MemoryBuffer buff = new MemoryBuffer(BufferType.getSessionBase, token)) {
        buff.setField("LoginTime_", headOut.getDateTime("LoginTime_"));
        buff.setField("UserID_", headOut.getString("UserID_"));
        buff.setField("UserCode_", userCode);
        buff.setField("CorpNo_", corpNo);
        buff.setField("UserName_", headOut.getString("UserName_"));
        buff.setField("RoleCode_", headOut.getString("RoleCode_"));
        buff.setField("ProxyUsers_", headOut.getString("ProxyUsers_"));
        buff.setField("Language_", headOut.getString("Language_"));
        buff.setField("exists", true);
    }
    return true;
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) UserNotFindException(cn.cerc.jbean.other.UserNotFindException) Record(cn.cerc.jdb.core.Record) LocalService(cn.cerc.jbean.client.LocalService)

Example 7 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer 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 8 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class ClientDevice method setDevice.

@Override
public void setDevice(String deviceType) {
    if (deviceType == null || "".equals(deviceType))
        return;
    this.deviceType = deviceType;
    request.setAttribute(deviceType_key, deviceType == null ? "" : deviceType);
    request.getSession().setAttribute(deviceType_key, deviceType);
    if (sid != null && deviceType != null && !"".equals(deviceType)) {
        try (MemoryBuffer buff = new MemoryBuffer(BufferType.getDeviceInfo, sid)) {
            getValue(buff, deviceType_key, deviceType);
        }
    }
    return;
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer)

Example 9 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class StartForms method passDevice.

// 是否在当前设备使用此菜单,如:检验此设备是否需要设备验证码
protected boolean passDevice(IForm form) {
    // 若是iphone应用商店测试,则跳过验证
    if (getIphoneAppstoreAccount().equals(form.getHandle().getUserCode()))
        return true;
    String deviceId = form.getClient().getId();
    // TODO 验证码变量,需要改成静态变量,统一取值
    String verifyCode = form.getRequest().getParameter("verifyCode");
    log.debug(String.format("进行设备认证, deviceId=%s", deviceId));
    String userId = (String) form.getHandle().getProperty(Application.userId);
    try (MemoryBuffer buff = new MemoryBuffer(BufferType.getSessionInfo, userId, deviceId)) {
        if (!buff.isNull()) {
            if (buff.getBoolean("VerifyMachine")) {
                log.debug("已经认证过,跳过认证");
                return true;
            }
        }
        boolean result = false;
        LocalService app = new LocalService(form.getHandle());
        app.setService("SvrUserLogin.verifyMachine");
        app.getDataIn().getHead().setField("deviceId", deviceId);
        if (verifyCode != null && !"".equals(verifyCode))
            app.getDataIn().getHead().setField("verifyCode", verifyCode);
        if (app.exec())
            result = true;
        else {
            int used = app.getDataOut().getHead().getInt("Used_");
            if (used == 1)
                result = true;
            else
                form.setParam("message", app.getMessage());
        }
        if (result)
            buff.setField("VerifyMachine", true);
        return result;
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) LocalService(cn.cerc.jbean.client.LocalService)

Example 10 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class ExportService method export.

public void export() throws WriteException, IOException, AccreditException {
    if (service == null || "".equals(service))
        throw new RuntimeException("错误的调用:service is null");
    if (exportKey == null || "".equals(exportKey))
        throw new RuntimeException("错误的调用:exportKey is null");
    IHandle handle = (IHandle) this.getHandle();
    LocalService app = new LocalService(handle);
    app.setService(service);
    try (MemoryBuffer buff = new MemoryBuffer(BufferType.getExportKey, handle.getUserCode(), exportKey)) {
        app.getDataIn().close();
        app.getDataIn().setJSON(buff.getString("data"));
    }
    if (!app.exec()) {
        this.export(app.getMessage());
        return;
    }
    DataSet dataOut = app.getDataOut();
    // 对分类进行处理
    dataOut.first();
    while (dataOut.fetch()) {
        if (dataOut.getBoolean("IsType_"))
            dataOut.delete();
    }
    this.getTemplate().setDataSet(dataOut);
    super.export();
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) DataSet(cn.cerc.jdb.core.DataSet) LocalService(cn.cerc.jbean.client.LocalService) IHandle(cn.cerc.jdb.core.IHandle)

Aggregations

MemoryBuffer (cn.cerc.jbean.other.MemoryBuffer)10 LocalService (cn.cerc.jbean.client.LocalService)4 Record (cn.cerc.jdb.core.Record)3 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)3 Webfunc (cn.cerc.jbean.core.Webfunc)2 CustomHandle (cn.cerc.jbean.core.CustomHandle)1 DataValidateException (cn.cerc.jbean.core.DataValidateException)1 ServiceException (cn.cerc.jbean.core.ServiceException)1 UserNotFindException (cn.cerc.jbean.other.UserNotFindException)1 StubHandle (cn.cerc.jbean.rds.StubHandle)1 DataSet (cn.cerc.jdb.core.DataSet)1 IHandle (cn.cerc.jdb.core.IHandle)1 Transaction (cn.cerc.jdb.mysql.Transaction)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1