Search in sources :

Example 1 with Table

use of app.hongs.db.Table in project HongsCORE by ihongs.

the class SignAction method signCreate.

/**
 * 登录
 * @param ah
 * @throws HongsException
 */
@Action("create")
@Verify(conf = "master", form = "sign")
public void signCreate(ActionHelper ah) throws HongsException {
    String appid = Synt.declare(ah.getParameter("appid"), "_WEB_");
    String place = Synt.declare(ah.getParameter("place"), "public");
    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;
    // 验证密码
    fc = new FetchCase().from(tb.tableName).select("password, passcode, id, name, head, mtime, state").filter("username = ?", username);
    ud = db.fetchLess(fc);
    if (ud.isEmpty()) {
        ah.reply(AuthKit.getWrong("username", "core.username.invalid"));
        return;
    }
    passcode = Synt.declare(ud.get("passcode"), "");
    password = AuthKit.getCrypt(password + passcode);
    if (!password.equals(ud.get("password"))) {
        ah.reply(AuthKit.getWrong("passowrd", "core.password.invalid"));
        return;
    }
    String usrid = (String) ud.get("id");
    String uname = (String) ud.get("name");
    String uhead = (String) ud.get("head");
    int state = Synt.declare(ud.get("state"), 0);
    long utime = Synt.declare(ud.get("mtime"), 0L) * 1000;
    // 验证状态
    if (1 != state) {
        ah.reply(AuthKit.getWrong("state", "core.sign.state.invalid"));
        return;
    }
    // 验证区域
    Set rs = RoleSet.getInstance(usrid);
    if (0 != place.length() && !rs.contains(place)) {
        ah.reply(AuthKit.getWrong("place", "core.sign.place.invalid"));
        return;
    }
    ah.reply(AuthKit.userSign(ah, place, appid, usrid, uname, uhead, utime));
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) Set(java.util.Set) RoleSet(app.hongs.serv.auth.RoleSet) Map(java.util.Map) DB(app.hongs.db.DB) Action(app.hongs.action.anno.Action) Verify(app.hongs.action.anno.Verify)

Example 2 with Table

use of app.hongs.db.Table in project HongsCORE by ihongs.

the class Dept method getRoles.

public Set<String> getRoles(String deptId) throws HongsException {
    if (deptId == null)
        throw new HongsException(0x10000, "Dept Id required!");
    Table asoc;
    FetchCase caze;
    List<Map> rows;
    Set<String> roles = new HashSet();
    asoc = this.db.getTable("a_master_dept_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".dept_id = ?", deptId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    return roles;
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) HongsException(app.hongs.HongsException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with Table

use of app.hongs.db.Table in project HongsCORE by ihongs.

the class User method getRoles.

public Set<String> getRoles(String userId) throws HongsException {
    if (userId == null)
        throw new HongsException(0x10000, "User Id required!");
    Table asoc;
    FetchCase caze;
    List<Map> rows;
    Set<String> roles = new HashSet();
    Set<String> depts = new HashSet();
    asoc = this.db.getTable("a_master_user_dept");
    caze = this.fetchCase();
    caze.select(asoc.name + ".dept_id").filter(asoc.name + ".user_id = ?", userId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        depts.add((String) row.get("dept_id"));
    }
    asoc = this.db.getTable("a_master_dept_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".dept_id = ?", depts);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    asoc = this.db.getTable("a_master_user_role");
    caze = this.fetchCase();
    caze.select(asoc.name + ".role").filter(asoc.name + ".user_id = ?", userId);
    rows = asoc.fetchMore(caze);
    for (Map row : rows) {
        roles.add((String) row.get("role"));
    }
    return roles;
}
Also used : Table(app.hongs.db.Table) FetchCase(app.hongs.db.util.FetchCase) HongsException(app.hongs.HongsException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with Table

use of app.hongs.db.Table in project HongsCORE by ihongs.

the class Form method insertAuthRole.

protected void insertAuthRole(String id) throws HongsException {
    ActionHelper helper = Core.getInstance(ActionHelper.class);
    String uid = (String) helper.getSessibute(Cnst.UID_SES);
    String tan;
    // 写入权限
    tan = (String) table.getParams().get("role.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/search"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/create"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/update"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/delete"));
        tab.insert(Synt.mapOf("user_id", uid, "role", prefix + "/" + id + "/revert"));
    }
    // 更新缓存(通过改变权限更新时间)
    tan = (String) table.getParams().get("user.table");
    if (tan != null) {
        Table tab = db.getTable(tan);
        tab.update(Synt.mapOf("rtime", System.currentTimeMillis() / 1000), "`id` = ?", uid);
    }
}
Also used : Table(app.hongs.db.Table) ActionHelper(app.hongs.action.ActionHelper)

Example 5 with Table

use of app.hongs.db.Table in project HongsCORE by ihongs.

the class FormAction method getForkList.

@Action("fork/list")
public void getForkList(ActionHelper helper) throws HongsException {
    Map data = new HashMap();
    Map item;
    List list;
    // 增加预定列表
    Map form = FormSet.getInstance("matrix").getFormTranslated("form_fork");
    list = new ArrayList();
    for (Map.Entry et : (Set<Map.Entry>) form.entrySet()) {
        item = new HashMap();
        item.put("__name__", et.getKey());
        item.putAll((Map) et.getValue());
    }
    data.put("list", list);
    // 获取全部表单
    Table ft = model.table;
    Table ut = model.db.getTable("unit");
    list = new ArrayList();
    getForkList(ft, ut, list, null, "");
    data.put("roll", list);
    helper.reply(data);
}
Also used : Set(java.util.Set) FormSet(app.hongs.action.FormSet) Table(app.hongs.db.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Action(app.hongs.action.anno.Action)

Aggregations

Table (app.hongs.db.Table)21 Map (java.util.Map)19 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)11 Set (java.util.Set)10 HongsException (app.hongs.HongsException)7 DB (app.hongs.db.DB)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 FetchCase (app.hongs.db.util.FetchCase)4 Iterator (java.util.Iterator)3 ActionHelper (app.hongs.action.ActionHelper)2 Action (app.hongs.action.anno.Action)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Document (org.apache.lucene.document.Document)2 FormSet (app.hongs.action.FormSet)1 Verify (app.hongs.action.anno.Verify)1 Cmdlet (app.hongs.cmdlet.anno.Cmdlet)1 RoleSet (app.hongs.serv.auth.RoleSet)1