Search in sources :

Example 1 with Preset

use of io.github.ihongs.action.anno.Preset 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 2 with Preset

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

the class MineAction method mineInfo.

@Action("info")
@Preset(conf = "master", form = "mine")
public void mineInfo(ActionHelper ah) throws HongsException {
    Object id = ah.getSessibute(Cnst.UID_SES);
    if (id == null || "".equals(id)) {
        throw new HongsException(401, "");
    }
    UserAction ua = new UserAction();
    Map rd = ah.getRequestData();
    rd.put("id", id);
    ua.getInfo(ah);
}
Also used : UserAction(io.github.ihongs.serv.master.UserAction) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) UserAction(io.github.ihongs.serv.master.UserAction) Preset(io.github.ihongs.action.anno.Preset)

Example 3 with Preset

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

the class MineAction method sameName.

@Action("same")
@Preset(conf = "master", form = "mine")
public void sameName(ActionHelper ah) throws HongsException {
    Object id = ah.getSessibute(Cnst.UID_SES);
    if (id == null || "".equals(id)) {
        throw new HongsException(401, "");
    }
    UserAction ua = new UserAction();
    Map rd = ah.getRequestData();
    rd.put("id", id);
    ua.isUnique(ah);
}
Also used : UserAction(io.github.ihongs.serv.master.UserAction) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) UserAction(io.github.ihongs.serv.master.UserAction) Preset(io.github.ihongs.action.anno.Preset)

Example 4 with Preset

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

the class DBAction method search.

@Override
@Action("search")
@Preset(conf = "", form = "")
@Select(conf = "", form = "")
public void search(ActionHelper helper) throws HongsException {
    Model ett = getEntity(helper);
    Map req = helper.getRequestData();
    req = getReqMap(helper, ett, "search", req);
    Map rsp = ett.search(req);
    rsp = getRspMap(helper, ett, "search", rsp);
    helper.reply(rsp);
}
Also used : Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) IAction(io.github.ihongs.dh.IAction) Preset(io.github.ihongs.action.anno.Preset) Select(io.github.ihongs.action.anno.Select)

Example 5 with Preset

use of io.github.ihongs.action.anno.Preset 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)

Aggregations

Action (io.github.ihongs.action.anno.Action)15 Preset (io.github.ihongs.action.anno.Preset)15 Map (java.util.Map)15 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)7 Verify (io.github.ihongs.action.anno.Verify)5 Select (io.github.ihongs.action.anno.Select)4 IAction (io.github.ihongs.dh.IAction)4 JAction (io.github.ihongs.dh.JAction)4 HongsException (io.github.ihongs.HongsException)3 UserAction (io.github.ihongs.serv.master.UserAction)3 HashMap (java.util.HashMap)3 Titles (io.github.ihongs.dh.search.TitlesHelper.Titles)2 FormSet (io.github.ihongs.action.FormSet)1 Table (io.github.ihongs.db.Table)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1