use of io.github.ihongs.serv.master.UserAction in project HongsCORE by ihongs.
the class AuthKit method redirect.
/**
* 登录成功后跳转
* 依此检查 Parameters,Cookies,Session 中是否有指定返回路径
* 都没有指定时则跳转到默认地址
* 默认地址缺失则跳转到网站首页
* 也可用特殊值要求返回特定数据
* _mine_info 用户信息
* _sign_info 会话信息
* - 无返回信息
* @param helper
* @param rst
* @throws HongsException
*/
public static void redirect(ActionHelper helper, Map rst) throws HongsException {
String k, v, r;
CoreConfig cc = CoreConfig.getInstance("oauth2");
do {
k = cc.getProperty("oauth2.bak.prm", "r");
r = v = helper.getParameter(k);
if (v != null && !v.isEmpty()) {
break;
}
k = cc.getProperty("oauth2.bak.cok");
if (k != null && !k.isEmpty()) {
v = (String) helper.getCookibute(k);
if (v != null && !v.isEmpty()) {
// 清除 Cookies
helper.setCookibute(k, null);
break;
}
}
k = cc.getProperty("oauth2.bak.ses");
if (k != null && !k.isEmpty()) {
v = (String) helper.getSessibute(k);
if (v != null && !v.isEmpty()) {
// 清除 Session
helper.setSessibute(k, null);
break;
}
}
v = cc.getProperty("oauth2.bak.url", Core.SERV_PATH + "/");
} while (false);
if ("_mine_info_".equals(r)) {
Object id = helper.getSessibute(Cnst.UID_SES);
Map rd = helper.getRequestData();
rd.put(Cnst.ID_KEY, id);
new UserAction().getInfo(helper);
} else if ("_sign_info_".equals(r)) {
helper.reply(Synt.mapOf("info", rst));
} else if ("-".equals(r)) {
helper.reply("");
} else {
helper.ensue(v);
}
}
use of io.github.ihongs.serv.master.UserAction in project HongsCORE by ihongs.
the class MineAction method mineSave.
@Action("save")
@Preset(conf = "master", form = "mine")
@Verify(conf = "master", form = "mine", type = 1, trim = 1)
@CommitSuccess
public void mineSave(ActionHelper ah) throws HongsException {
Object id = ah.getSessibute(Cnst.UID_SES);
if (id == null || "".equals(id)) {
throw new HongsException(401, "");
}
Map rd = ah.getRequestData();
rd.put("id", id);
// 禁止危险修改, 其实校验已经做过限制了. 这是以防万一
rd.remove("depts");
rd.remove("roles");
rd.remove("state");
// 验证原始密码
Table ut = DB.getInstance("master").getTable("user");
String pw = (String) rd.get("password");
String po = (String) rd.get("passolde");
if (pw != null && !"".equals(pw)) {
Map xd = new HashMap();
Map ed = new HashMap();
xd.put("ok", false);
xd.put("errs", ed);
xd.put("msg", CoreLocale.getInstance().translate("fore.form.invalid"));
if (po != null && !"".equals(po)) {
Map row = ut.fetchCase().filter("id = ?", id).select("password , passcode").getOne();
String ps = (String) row.get("password");
String pc = (String) row.get("passcode");
if (pc != null)
po += pc;
po = AuthKit.getCrypt(po);
if (!po.equals(ps)) {
ed.put("passolde", "旧密码不正确");
ah.reply(xd);
return;
}
} else {
ed.put("passolde", "请填写旧密码");
ah.reply(xd);
return;
}
}
// 附加验证标识, 当要验证的字段值改变时, 重设为未验证
Map<String, Object> fs = ut.getFields();
Map<String, Object> fz = new HashMap();
for (String fn : fs.keySet()) {
String fx;
if (fn.endsWith("_checked")) {
fx = fn.substring(0, fn.length() - 8);
if (fs.containsKey(fx) && rd.containsKey(fx)) {
fz.put(fx, rd.get(fx));
}
}
}
if (!fz.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String fn : fz.keySet()) {
sb.append(",`").append(fn).append("`");
}
Map ud = ut.fetchCase().filter("`id` = ?", id).select(sb.substring(1)).getOne();
for (Map.Entry<String, Object> et : fz.entrySet()) {
String fn = et.getKey();
Object fv = et.getValue();
Object fo = ud.get(fn);
if (fv == null || fv.equals("") || !fv.equals(fo)) {
rd.put(et.getKey() + "_checked", "0");
}
}
}
UserAction ua = new UserAction();
ua.doSave(ah);
}
use of io.github.ihongs.serv.master.UserAction in project HongsCORE by ihongs.
the class MineAction method mineInfo.
@Action("info")
@Preset(conf = "master", form = "mine")
public void mineInfo(ActionHelper ah) throws HongsException {
Object id = ah.getSessibute(Cnst.UID_SES);
if (id == null || "".equals(id)) {
throw new HongsException(401, "");
}
UserAction ua = new UserAction();
Map rd = ah.getRequestData();
rd.put("id", id);
ua.getInfo(ah);
}
use of io.github.ihongs.serv.master.UserAction in project HongsCORE by ihongs.
the class MineAction method sameName.
@Action("same")
@Preset(conf = "master", form = "mine")
public void sameName(ActionHelper ah) throws HongsException {
Object id = ah.getSessibute(Cnst.UID_SES);
if (id == null || "".equals(id)) {
throw new HongsException(401, "");
}
UserAction ua = new UserAction();
Map rd = ah.getRequestData();
rd.put("id", id);
ua.isUnique(ah);
}
Aggregations