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