Search in sources :

Example 1 with Verify

use of io.github.ihongs.action.anno.Verify in project HongsCORE by ihongs.

the class UserAction method doSave.

@Action("save")
@Verify(conf = "master", form = "user")
@CommitSuccess
public void doSave(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    // Ignore empty password in update
    boolean cp;
    if (null == rd.get("password") || "".equals(rd.get("password"))) {
        rd.remove("password");
        rd.remove("passcode");
        cp = false;
    } else if (null == rd.get("id") || "".equals(rd.get("id"))) {
        cp = false;
    } else {
        cp = true;
    }
    String id = model.set(rd);
    CoreLocale ln = CoreLocale.getInstance().clone();
    ln.load("master");
    String ms = ln.translate("core.save.user.success");
    helper.reply(ms, id);
    /**
     * 2019/02/26
     * 有修改密码则将重试次数归零,
     * 若密码重试次数标记有用到IP,
     * 需告知登录的校验标记改用ID.
     *
     * 2021/06/20
     * 已加修改密码需重新登录逻辑,
     * 重写会话规避当前用户重登录.
     */
    if (cp) {
        Calendar ca;
        long et;
        ca = Calendar.getInstance(Core.getTimezone());
        ca.setTimeInMillis(Core.ACTION_TIME.get());
        ca.set(Calendar.HOUR_OF_DAY, 23);
        ca.set(Calendar.MINUTE, 59);
        ca.set(Calendar.SECOND, 59);
        et = ca.getTimeInMillis() / 1000 + 1;
        Record.set("sign.retry.allow." + id, 1, et);
        Record.del("sign.retry.times." + id);
        if ("*".equals(helper.getSessibute(Cnst.USK_SES))) {
            helper.setSessibute(Cnst.UST_SES, System.currentTimeMillis() / 1000);
        }
    }
}
Also used : CoreLocale(io.github.ihongs.CoreLocale) Calendar(java.util.Calendar) HashMap(java.util.HashMap) NaviMap(io.github.ihongs.action.NaviMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Verify(io.github.ihongs.action.anno.Verify)

Example 2 with Verify

use of io.github.ihongs.action.anno.Verify in project HongsCORE by ihongs.

the class MineAction method mineSave.

@Action("save")
@Preset(conf = "master", form = "mine")
@Verify(conf = "master", form = "mine", type = 1, trim = 1)
@CommitSuccess
public void mineSave(ActionHelper ah) throws HongsException {
    Object id = ah.getSessibute(Cnst.UID_SES);
    if (id == null || "".equals(id)) {
        throw new HongsException(401, "");
    }
    Map rd = ah.getRequestData();
    rd.put("id", id);
    // 禁止危险修改, 其实校验已经做过限制了. 这是以防万一
    rd.remove("depts");
    rd.remove("roles");
    rd.remove("state");
    // 验证原始密码
    Table ut = DB.getInstance("master").getTable("user");
    String pw = (String) rd.get("password");
    String po = (String) rd.get("passolde");
    if (pw != null && !"".equals(pw)) {
        Map xd = new HashMap();
        Map ed = new HashMap();
        xd.put("ok", false);
        xd.put("errs", ed);
        xd.put("msg", CoreLocale.getInstance().translate("fore.form.invalid"));
        if (po != null && !"".equals(po)) {
            Map row = ut.fetchCase().filter("id = ?", id).select("password , passcode").getOne();
            String ps = (String) row.get("password");
            String pc = (String) row.get("passcode");
            if (pc != null)
                po += pc;
            po = AuthKit.getCrypt(po);
            if (!po.equals(ps)) {
                ed.put("passolde", "旧密码不正确");
                ah.reply(xd);
                return;
            }
        } else {
            ed.put("passolde", "请填写旧密码");
            ah.reply(xd);
            return;
        }
    }
    // 附加验证标识, 当要验证的字段值改变时, 重设为未验证
    Map<String, Object> fs = ut.getFields();
    Map<String, Object> fz = new HashMap();
    for (String fn : fs.keySet()) {
        String fx;
        if (fn.endsWith("_checked")) {
            fx = fn.substring(0, fn.length() - 8);
            if (fs.containsKey(fx) && rd.containsKey(fx)) {
                fz.put(fx, rd.get(fx));
            }
        }
    }
    if (!fz.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (String fn : fz.keySet()) {
            sb.append(",`").append(fn).append("`");
        }
        Map ud = ut.fetchCase().filter("`id` = ?", id).select(sb.substring(1)).getOne();
        for (Map.Entry<String, Object> et : fz.entrySet()) {
            String fn = et.getKey();
            Object fv = et.getValue();
            Object fo = ud.get(fn);
            if (fv == null || fv.equals("") || !fv.equals(fo)) {
                rd.put(et.getKey() + "_checked", "0");
            }
        }
    }
    UserAction ua = new UserAction();
    ua.doSave(ah);
}
Also used : UserAction(io.github.ihongs.serv.master.UserAction) Table(io.github.ihongs.db.Table) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) UserAction(io.github.ihongs.serv.master.UserAction) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Preset(io.github.ihongs.action.anno.Preset) Verify(io.github.ihongs.action.anno.Verify)

Example 3 with Verify

use of io.github.ihongs.action.anno.Verify in project HongsCORE by ihongs.

the class DBAction method update.

@Override
@Action("update")
@Preset(conf = "", form = "", defs = { ":defence" })
@Verify(conf = "", form = "")
@CommitSuccess
public void update(ActionHelper helper) throws HongsException {
    Model ett = getEntity(helper);
    Map req = helper.getRequestData();
    req = getReqMap(helper, ett, "update", req);
    int num = ett.update(req);
    String msg = getRspMsg(helper, ett, "update", num);
    helper.reply(msg, num);
}
Also used : Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) IAction(io.github.ihongs.dh.IAction) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Preset(io.github.ihongs.action.anno.Preset) Verify(io.github.ihongs.action.anno.Verify)

Example 4 with Verify

use of io.github.ihongs.action.anno.Verify in project HongsCORE by ihongs.

the class JAction method update.

@Override
@Action("update")
@Preset(conf = "", form = "", defs = { ":defence" })
@Verify(conf = "", form = "")
@CommitSuccess
public void update(ActionHelper helper) throws HongsException {
    IEntity sr = getEntity(helper);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "update", rd);
    int sn = sr.update(rd);
    String ss = getRspMsg(helper, sr, "update", sn);
    helper.reply(ss, sn);
}
Also used : Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Preset(io.github.ihongs.action.anno.Preset) Verify(io.github.ihongs.action.anno.Verify)

Example 5 with Verify

use of io.github.ihongs.action.anno.Verify in project HongsCORE by ihongs.

the class JAction method create.

@Override
@Action("create")
@Preset(conf = "", form = "", defs = { ":initial" })
@Verify(conf = "", form = "")
@CommitSuccess
public void create(ActionHelper helper) throws HongsException {
    IEntity sr = getEntity(helper);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "create", rd);
    String sn = sr.create(rd);
    String ss = getRspMsg(helper, sr, "create", 1);
    helper.reply(ss, sn);
}
Also used : Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Preset(io.github.ihongs.action.anno.Preset) Verify(io.github.ihongs.action.anno.Verify)

Aggregations

Action (io.github.ihongs.action.anno.Action)10 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)10 Verify (io.github.ihongs.action.anno.Verify)10 Map (java.util.Map)9 Preset (io.github.ihongs.action.anno.Preset)5 CoreConfig (io.github.ihongs.CoreConfig)3 HongsException (io.github.ihongs.HongsException)3 HashMap (java.util.HashMap)3 CoreLocale (io.github.ihongs.CoreLocale)2 Table (io.github.ihongs.db.Table)2 IAction (io.github.ihongs.dh.IAction)2 Calendar (java.util.Calendar)2 NaviMap (io.github.ihongs.action.NaviMap)1 DB (io.github.ihongs.db.DB)1 FetchCase (io.github.ihongs.db.util.FetchCase)1 RoleSet (io.github.ihongs.serv.auth.RoleSet)1 User (io.github.ihongs.serv.master.User)1 UserAction (io.github.ihongs.serv.master.UserAction)1 Set (java.util.Set)1