Search in sources :

Example 1 with CoreLocale

use of io.github.ihongs.CoreLocale 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 CoreLocale

use of io.github.ihongs.CoreLocale 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 CoreLocale

use of io.github.ihongs.CoreLocale 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 CoreLocale

use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.

the class FileAction method update.

@Override
@Action("update")
public void update(ActionHelper helper) throws HongsException {
    CoreLocale lang = CoreLocale.getInstance("manage");
    String path = helper.getParameter("path");
    String dist = helper.getParameter("dist");
    String text = helper.getParameter("text");
    File file;
    File dizt;
    if (dist != null && dist.equals(path)) {
        dist = null;
    }
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.required"));
        return;
    }
    path = realPath(path);
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.is.error"));
        return;
    }
    file = new File(path);
    if (!file.exists()) {
        helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
        return;
    }
    if (isDenyFile(file)) {
        helper.fault(lang.translate("core.manage.file.interdicted"));
        return;
    }
    // 改名移动
    if (dist != null) {
        dist = realPath(dist);
        if (dist == null) {
            helper.fault(lang.translate("core.manage.file.path.is.error"));
            return;
        }
        dizt = new File(dist);
        if (dizt.exists()) {
            helper.fault(lang.translate("core.manage.file.dist.is.exist"));
            return;
        }
        if (isDenyFile(file)) {
            helper.fault(lang.translate("core.manage.file.interdicted"));
            return;
        }
        if (!file.renameTo(dizt)) {
            helper.fault(lang.translate("core.manage.file.rename.failed"));
            return;
        }
        file = dizt;
    }
    // 写入文件
    try {
        saveFile(file, text);
    } catch (Exception ex) {
        CoreLogger.error(ex);
        helper.fault(lang.translate("core.manage.file.update.failed"));
        return;
    }
    helper.reply("");
}
Also used : CoreLocale(io.github.ihongs.CoreLocale) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HongsException(io.github.ihongs.HongsException) Action(io.github.ihongs.action.anno.Action) IAction(io.github.ihongs.dh.IAction)

Example 5 with CoreLocale

use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.

the class FileAction method delete.

@Override
@Action("delete")
public void delete(ActionHelper helper) throws HongsException {
    CoreLocale lang = CoreLocale.getInstance("manage");
    Set<String> list = Synt.asSet(helper.getRequestData().get("path"));
    if (list == null || list.isEmpty()) {
        helper.fault(lang.translate("core.manage.file.path.required"));
        return;
    }
    for (String path : list) {
        File file;
        if (path == null) {
            helper.fault(lang.translate("core.manage.file.path.required"));
            return;
        }
        path = realPath(path);
        if (path == null) {
            helper.fault(lang.translate("core.manage.file.path.is.error"));
            return;
        }
        file = new File(path);
        if (!file.exists()) {
            helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
            return;
        }
        if (isDenyDire(file)) {
            helper.fault(lang.translate("core.manage.file.path.is.not.empty"));
            return;
        }
        if (isDenyFile(file)) {
            helper.fault(lang.translate("core.manage.file.interdicted"));
            return;
        }
        if (!file.delete()) {
            helper.fault(lang.translate("core.manage.file.delete.failed"));
            return;
        }
    }
    helper.reply("");
}
Also used : CoreLocale(io.github.ihongs.CoreLocale) File(java.io.File) Action(io.github.ihongs.action.anno.Action) IAction(io.github.ihongs.dh.IAction)

Aggregations

CoreLocale (io.github.ihongs.CoreLocale)21 Map (java.util.Map)15 Action (io.github.ihongs.action.anno.Action)12 HashMap (java.util.HashMap)11 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)7 NaviMap (io.github.ihongs.action.NaviMap)5 IAction (io.github.ihongs.dh.IAction)4 File (java.io.File)4 LinkedHashMap (java.util.LinkedHashMap)4 HongsException (io.github.ihongs.HongsException)2 ActionRunner (io.github.ihongs.action.ActionRunner)2 Verify (io.github.ihongs.action.anno.Verify)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Wrong (io.github.ihongs.util.verify.Wrong)1 Wrongs (io.github.ihongs.util.verify.Wrongs)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1