Search in sources :

Example 11 with Table

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

the class AuthKit method userSign.

/**
 * 自运营登录
 * @param ah
 * @param place
 * @param appid
 * @param usrid
 * @param uname 名称
 * @param uhead 头像
 * @param utime 用户信息更新时间
 * @return
 * @throws HongsException
 */
public static Map userSign(ActionHelper ah, String place, String appid, String usrid, String uname, String uhead, long utime) throws HongsException {
    HttpSession sd = ah.getRequest().getSession(false);
    long stime = System.currentTimeMillis() / 1000;
    // 登录时哪些会话数据需要保留
    String sesmk = CoreConfig.getInstance("master").getProperty("core.keep.sess", "");
    // 重建会话
    if (sd != null) {
        Map<String, Object> xs = new HashMap();
        Set<String> ks = Synt.toTerms(sesmk);
        ks.add(Cnst.SAE_SES);
        for (String kn : ks) {
            Object kv = sd.getAttribute(kn);
            if (null != kv)
                xs.put(kn, kv);
        }
        sd.invalidate();
        sd = ah.getRequest().getSession(true);
        for (Map.Entry<String, Object> et : xs.entrySet()) {
            sd.setAttribute(et.getKey(), et.getValue());
        }
    } else {
        sd = ah.getRequest().getSession(true);
    }
    String sesid = sd.getId();
    // 设置会话
    if (place != null && 0 < place.length()) {
        Set s = Synt.asSet(sd.getAttribute(Cnst.SAE_SES));
        if (s == null) {
            s = new HashSet();
        }
        s.add(place);
        // 仅保留拥有的区域
        s.retainAll(RoleSet.getInstance(usrid));
        sd.setAttribute(Cnst.SAE_SES, s);
    }
    sd.setAttribute(Cnst.STM_SES, stime);
    sd.setAttribute(Cnst.UID_SES, usrid);
    sd.setAttribute("appid", appid);
    sd.setAttribute("uname", uname);
    sd.setAttribute("uhead", uhead);
    sd.setAttribute("utime", utime);
    // 返回数据
    Map rd = new HashMap();
    rd.put(Cnst.STM_SES, stime);
    rd.put(Cnst.UID_SES, usrid);
    rd.put("appid", appid);
    rd.put("place", place);
    rd.put("uname", uname);
    rd.put("uhead", uhead);
    rd.put("utime", utime);
    rd.put("sesid", sesid);
    // 记录登录
    DB db = DB.getInstance("master");
    Table tb = db.getTable("user_sign");
    tb.remove("(`user_id` = ? AND `appid` = ?) OR `sesid` = ?", usrid, appid, sesid);
    Map ud = new HashMap();
    ud.put("user_id", usrid);
    ud.put("sesid", sesid);
    ud.put("appid", appid);
    ud.put("ctime", stime);
    tb.insert(ud);
    return rd;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Table(app.hongs.db.Table) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) HashMap(java.util.HashMap) Map(java.util.Map) DB(app.hongs.db.DB) HashSet(java.util.HashSet)

Example 12 with Table

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

the class AuthKit method openSign.

/**
 * 第三方登录
 * @param ah
 * @param place
 * @param appid
 * @param opnid
 * @param uname 名称
 * @param uhead 头像
 * @param utime 用户信息更新时间
 * @return
 * @throws HongsException
 */
public static Map openSign(ActionHelper ah, String place, String appid, String opnid, String uname, String uhead, long utime) throws HongsException {
    DB db = DB.getInstance("master");
    Table tb = db.getTable("user_open");
    Map ud = tb.fetchCase().filter("`opnid` =? AND `appid` = ?", opnid, appid).select("`user_id`").one();
    // 记录关联
    String usrid;
    if (ud != null && !ud.isEmpty()) {
        usrid = ud.get("user_id").toString();
    } else {
        ud = new HashMap();
        ud.put("name", uname);
        ud.put("head", uhead);
        usrid = db.getModel("user").add(ud);
        // 第三方登录项
        ud = new HashMap();
        ud.put("user_id", usrid);
        ud.put("appid", appid);
        ud.put("opnid", opnid);
        db.getTable("user_open").insert(ud);
        // 赋予公共权限
        ud = new HashMap();
        ud.put("user_id", usrid);
        ud.put("role", "public");
        db.getTable("user_role").insert(ud);
        // 加入公共部门
        ud = new HashMap();
        ud.put("user_id", usrid);
        ud.put("dept_id", "PUBLIC");
        db.getTable("user_dept").insert(ud);
    }
    return userSign(ah, place, appid, usrid, uname, uhead, utime);
}
Also used : Table(app.hongs.db.Table) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DB(app.hongs.db.DB)

Example 13 with Table

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

the class AuthKit method getMoreDepts.

public static Set getMoreDepts(String uid) throws HongsException {
    Table rel = DB.getInstance("master").getTable("user_dept");
    List<Map> lst = rel.fetchCase().filter("user_id = ?", uid).select("dept_id").all();
    Set set = new HashSet();
    Dept dp = new Dept();
    for (Map row : lst) {
        set.addAll(dp.getChildIds((String) row.get("dept_id"), true));
    }
    return set;
}
Also used : Table(app.hongs.db.Table) Set(java.util.Set) HashSet(java.util.HashSet) Dept(app.hongs.serv.master.Dept) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 14 with Table

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

the class AuthKit method getDeptRoles.

public static Set getDeptRoles(String gid) throws HongsException {
    Table rel = DB.getInstance("master").getTable("dept_role");
    List<Map> lst = rel.fetchCase().filter("dept_id = ?", gid).select("role").all();
    Set set = new HashSet();
    for (Map row : lst) {
        set.add(row.get("role"));
    }
    return set;
}
Also used : Table(app.hongs.db.Table) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with Table

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

the class AuthKit method getUserDepts.

public static Set getUserDepts(String uid) throws HongsException {
    Table rel = DB.getInstance("master").getTable("user_dept");
    List<Map> lst = rel.fetchCase().filter("user_id = ?", uid).select("dept_id").all();
    Set set = new HashSet();
    for (Map row : lst) {
        set.add(row.get("dept_id"));
    }
    return set;
}
Also used : Table(app.hongs.db.Table) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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