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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations