Search in sources :

Example 1 with Action

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

the class DeptAction method doSave.

@Action("save")
@CommitSuccess
public void doSave(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    String id = model.set(rd);
    CoreLocale ln = CoreLocale.getInstance().clone();
    ln.load("master");
    String ms = ln.translate("core.save.dept.success");
    helper.reply(ms, id);
}
Also used : CoreLocale(io.github.ihongs.CoreLocale) 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)

Example 2 with Action

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

the class UserAction method doDelete.

@Action("delete")
@CommitSuccess
public void doDelete(ActionHelper helper) throws HongsException {
    // 不能删除自己和超级管理员
    Set rs = Synt.asSet(helper.getParameter(Cnst.ID_KEY));
    if (rs != null) {
        if (rs.contains(helper.getSessibute(Cnst.UID_SES))) {
            helper.fault("不能删除当前登录用户");
            return;
        }
        if (rs.contains(Cnst.ADM_UID)) {
            helper.fault("不能删除超级管理账号");
            return;
        }
    }
    Map rd = helper.getRequestData();
    int rn = model.delete(rd);
    CoreLocale ln = CoreLocale.getInstance().clone();
    ln.load("master");
    String ms = ln.translate("core.delete.user.success", null, Integer.toString(rn));
    helper.reply(ms, rn);
}
Also used : CoreLocale(io.github.ihongs.CoreLocale) Set(java.util.Set) HashSet(java.util.HashSet) 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)

Example 3 with Action

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

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

the class UserAction method isUnique.

@Action("unique")
public void isUnique(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    FetchCase fc = model.fetchCase();
    fc.setOption("INCLUDE_REMOVED", Synt.declare(rd.get("include-removed"), false));
    boolean rv = model.unique(rd, fc);
    helper.reply(null, rv ? 1 : 0);
}
Also used : FetchCase(io.github.ihongs.db.util.FetchCase) HashMap(java.util.HashMap) NaviMap(io.github.ihongs.action.NaviMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action)

Example 5 with Action

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

the class UserAction method getList.

@Action("list")
@Select(conf = "master", form = "user")
public void getList(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    byte wd = Synt.declare(rd.get("with-depts"), (byte) 0);
    boolean fd = Synt.declare(rd.get("find-depth"), false);
    // With sub depts
    if (fd) {
        Dept depth = (Dept) DB.getInstance("master").getModel("dept");
        String pid = Synt.declare(rd.get("dept_id"), "");
        if (!"".equals(pid) && !"-".equals(pid)) {
            Collection ids = depth.getChildIds(pid, true);
            ids.add(pid);
            rd.put("dept_id", ids);
        }
    }
    rd = model.getList(rd);
    List<Map> list = (List) rd.get("list");
    if (list != null) {
        // With all depts
        if (wd == 1) {
            Map<String, Map> maps = new HashMap();
            for (Map info : list) {
                info.put("depts", new HashSet());
                maps.put(info.get("id").toString(), info);
            }
            List<Map> rows = model.db.getTable("dept_user").fetchCase().filter("user_id IN (?)", maps.keySet()).select("user_id, dept_id").getAll();
            for (Map dept : rows) {
                String uid = dept.remove("user_id").toString();
                ((Set) maps.get(uid).get("depts")).add(dept);
            }
        } else if (wd == 2) {
            Map<String, Map> maps = new HashMap();
            for (Map info : list) {
                info.put("depts", new HashSet());
                maps.put(info.get("id").toString(), info);
            }
            List<Map> rows = model.db.getTable("dept_user").fetchCase().join(model.db.getTable("dept").tableName, "dept", "dept_user.dept_id = dept.id").filter("user_id IN (?)", maps.keySet()).select("user_id, dept_id, dept.*").getAll();
            for (Map dept : rows) {
                String uid = dept.remove("user_id").toString();
                ((Set) maps.get(uid).get("depts")).add(dept);
            }
        }
        // Remove the password field, don't show password in page
        for (Map info : list) {
            info.remove("password");
            info.remove("passcode");
        }
    }
    helper.reply(rd);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Collection(java.util.Collection) List(java.util.List) HashMap(java.util.HashMap) NaviMap(io.github.ihongs.action.NaviMap) Map(java.util.Map) HashSet(java.util.HashSet) Action(io.github.ihongs.action.anno.Action) Select(io.github.ihongs.action.anno.Select)

Aggregations

Action (io.github.ihongs.action.anno.Action)64 Map (java.util.Map)53 HashMap (java.util.HashMap)26 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)22 Preset (io.github.ihongs.action.anno.Preset)15 HongsException (io.github.ihongs.HongsException)14 CoreLocale (io.github.ihongs.CoreLocale)12 NaviMap (io.github.ihongs.action.NaviMap)12 Verify (io.github.ihongs.action.anno.Verify)10 IAction (io.github.ihongs.dh.IAction)10 CoreConfig (io.github.ihongs.CoreConfig)9 Select (io.github.ihongs.action.anno.Select)8 Set (java.util.Set)8 List (java.util.List)7 File (java.io.File)6 HashSet (java.util.HashSet)6 FetchCase (io.github.ihongs.db.util.FetchCase)5 JAction (io.github.ihongs.dh.JAction)4 UserAction (io.github.ihongs.serv.master.UserAction)3 ArrayList (java.util.ArrayList)3