Search in sources :

Example 6 with Verify

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

the class SignAction method signCreate.

/**
 * 登录
 * @param ah
 * @throws HongsException
 */
@Action("create")
@Verify(conf = "master", form = "sign")
@CommitSuccess
public void signCreate(ActionHelper ah) throws HongsException {
    String place = Synt.declare(ah.getParameter("place"), "centre");
    String username = Synt.declare(ah.getParameter("username"), "");
    String password = Synt.declare(ah.getParameter("password"), "");
    String passcode;
    DB db = DB.getInstance("master");
    Table tb = db.getTable("user");
    FetchCase fc;
    Map ud;
    String id;
    String tt;
    int at;
    int rt;
    // 检查账号
    fc = new FetchCase().from(tb.tableName).filter("username = ?", username).select("password, passcode, id, name, head, state");
    ud = db.fetchLess(fc);
    if (ud.isEmpty()) {
        ah.reply(AuthKit.getWrong("username", "core.username.invalid"));
        return;
    }
    // 重试限制
    CoreConfig cc = CoreConfig.getInstance("master");
    id = (String) ud.get("id");
    tt = Synt.declare(cc.getProperty("core.sign.retry.token"), "");
    at = Synt.declare(cc.getProperty("core.sign.retry.times"), 5);
    if (Synt.declare(Record.get("sign.retry.allow." + id), false)) {
        tt = "id";
    }
    switch(tt) {
        case "id":
            break;
        case "ip":
            id = Core.CLIENT_ADDR.get();
            break;
        default:
            id = id + "-" + Core.CLIENT_ADDR.get();
    }
    rt = Synt.declare(Record.get("sign.retry.times." + id), 0);
    if (rt >= at) {
        ah.reply(AuthKit.getWrong("password", "core.password.timeout"));
        ah.getResponseData().put("allow_times", at);
        ah.getResponseData().put("retry_times", rt);
        return;
    } else {
        rt++;
    }
    // 校验密码
    passcode = Synt.declare(ud.get("passcode"), "");
    password = AuthKit.getCrypt(password + passcode);
    if (!password.equals(ud.get("password"))) {
        ah.reply(AuthKit.getWrong("password", "core.password.invalid"));
        ah.getResponseData().put("allow_times", at);
        ah.getResponseData().put("retry_times", rt);
        // 记录错误次数
        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.times." + id, rt, et);
        return;
    } else {
        Record.del("sign.retry.times." + id);
    }
    String uuid = (String) ud.get("id");
    String uname = (String) ud.get("name");
    String uhead = (String) ud.get("head");
    int state = Synt.declare(ud.get("state"), 0);
    // 验证状态
    if (0 >= state) {
        ah.reply(AuthKit.getWrong("state", "core.sign.state.invalid"));
        return;
    }
    // 规避自定 RoleSet 附加判断
    ah.setSessibute(Cnst.UID_SES, null);
    ah.setSessibute(Cnst.USK_SES, null);
    ah.setSessibute(Cnst.UST_SES, null);
    // 验证区域
    Set rs = RoleSet.getInstance(uuid);
    if (rs != null && !place.isEmpty() && !rs.contains(place)) {
        ah.reply(AuthKit.getWrong("place", "core.sign.place.invalid"));
        return;
    }
    // * 表示密码登录
    Map sd = AuthKit.userSign(ah, "*", uuid, uname, uhead);
    ah.reply(Synt.mapOf("info", sd));
}
Also used : Table(io.github.ihongs.db.Table) FetchCase(io.github.ihongs.db.util.FetchCase) Set(java.util.Set) RoleSet(io.github.ihongs.serv.auth.RoleSet) CoreConfig(io.github.ihongs.CoreConfig) Calendar(java.util.Calendar) Map(java.util.Map) DB(io.github.ihongs.db.DB) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Verify(io.github.ihongs.action.anno.Verify)

Example 7 with Verify

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

the class SignAction method signCreate.

/**
 * 登录
 * @param ah
 * @throws HongsException
 */
@Action("create")
@Verify(conf = "master", form = "sign")
@CommitSuccess
@Override
public void signCreate(ActionHelper ah) throws HongsException {
    CoreConfig cc = CoreConfig.getInstance("master");
    if (!cc.getProperty("core.public.sign.open", true)) {
        throw new HongsException(404, "Sign in is not allowed");
    }
    super.signCreate(ah);
}
Also used : CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Verify(io.github.ihongs.action.anno.Verify)

Example 8 with Verify

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

the class SignAction method userCreate.

/**
 * 注册
 * @param ah
 * @throws HongsException
 */
@Action("user/create")
@Verify(conf = "master", form = "regs", type = 0, trim = 1)
@CommitSuccess
public void userCreate(ActionHelper ah) throws HongsException {
    CoreConfig cc = CoreConfig.getInstance("master");
    if (!cc.getProperty("core.public.regs.open", true)) {
        throw new HongsException(404, "Sign on is not allowed");
    }
    User uo = (User) DB.getInstance("master").getModel("user");
    Map rd = ah.getRequestData();
    String uuid = uo.create(rd);
    String uname = Synt.declare(rd.get("name"), "");
    String uhead = Synt.declare(rd.get("head"), "");
    // 加入公共部门
    Map sd = new HashMap();
    sd.put("user_id", uuid);
    sd.put("dept_id", cc.getProperty("core.public.regs.dept", "CENTRE"));
    uo.db.getTable("dept_user").insert(sd);
    // 赋予公共权限. 仅用部门即可(2019/02/28)
    // Map  sd = new HashMap();
    // sd.put("user_id", uuid);
    // sd.put("role"   , cc.getProperty("core.public.regs.role", "centre"));
    // uo.db.getTable("user_role").insert(sd);
    // * 表示密码登录
    Map ad = AuthKit.userSign(ah, "*", uuid, uname, uhead);
    ah.reply(Synt.mapOf("info", ad));
}
Also used : User(io.github.ihongs.serv.master.User) CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Verify(io.github.ihongs.action.anno.Verify)

Example 9 with Verify

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

the class UnitAction method doSave.

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

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

the class DBAction method create.

@Override
@Action("create")
@Preset(conf = "", form = "", defs = { ":initial" })
@Verify(conf = "", form = "")
@CommitSuccess
public void create(ActionHelper helper) throws HongsException {
    Model ett = getEntity(helper);
    Map req = helper.getRequestData();
    req = getReqMap(helper, ett, "create", req);
    String nid = ett.create(req);
    String msg = getRspMsg(helper, ett, "create", 1);
    helper.reply(msg, nid);
}
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)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