use of app.hongs.util.verify.Wrongs in project HongsCORE by ihongs.
the class AuthKit method getWrong.
/**
* 快速输出登录的错误
* @param k 字段
* @param w 错误
* @return
* @throws HongsException
*/
public static Map getWrong(String k, String w) throws HongsException {
Map m = new HashMap();
Map e = new HashMap();
CoreLocale lang = CoreLocale.getInstance("master");
if (k != null && !"".equals(k)) {
m.put(k, new Wrong(w).setLocalizedContext("master"));
e.put("errs", new Wrongs(m).getErrors());
e.put("msg", lang.translate(w));
} else {
e.put("msg", lang.translate(w));
}
e.put("ok", false);
return e;
}
use of app.hongs.util.verify.Wrongs in project HongsCORE by ihongs.
the class VerifyInvoker method invoke.
@Override
public void invoke(ActionHelper helper, ActionRunner chains, Annotation anno) throws HongsException {
Verify ann = (Verify) anno;
String conf = ann.conf();
String form = ann.form();
byte mode = ann.mode();
byte type = ann.type();
byte trim = ann.trim();
// 准备数据
Map<String, Object> dat = helper.getRequestData();
Object id = dat.get(Cnst.ID_KEY);
String at = chains.getAction();
if (mode == -1) {
Set ab = Synt.toTerms(helper.getRequestData().get(Cnst.AB_KEY));
if (ab != null) {
if (ab.contains(".errs")) {
mode = 1;
} else if (ab.contains("!errs")) {
mode = 2;
}
}
}
if (type == -1) {
Boolean up = Synt.asBool(helper.getAttribute(Cnst.UPDATE_MODE));
if (up == null) {
type = at.endsWith("/update") || (null != id && !"".equals(id)) ? (byte) 1 : (byte) 0;
} else {
type = up ? (byte) 1 : (byte) 0;
}
}
boolean prp = mode <= 0;
boolean upd = type == 1;
boolean cln = trim == 1;
// 识别路径
if (form.length() == 0) {
form = chains.getEntity();
}
if (conf.length() == 0) {
conf = chains.getModule();
// 照顾 Module Action 的配置规则
if (FormSet.hasConfFile(conf + "/" + form)) {
conf = conf + "/" + form;
}
}
// 执行校验
try {
Map data = (Map) helper.getAttribute("form:" + conf + "." + form);
if (data == null) {
data = FormSet.getInstance(conf).getForm(form);
}
VerifyHelper ver = new VerifyHelper();
ver.addRulesByForm(conf, form, data);
ver.isPrompt(prp);
ver.isUpdate(upd);
Map vls = ver.verify(dat);
if (cln)
dat.clear();
dat.putAll(vls);
} catch (Wrongs err) {
dat = err.toReply(prp ? 0 : mode);
helper.reply(dat);
// Servlet 环境下设置状态码为 400 (错误的请求)
if (helper.getResponse() != null) {
helper.getResponse().setStatus(SC_BAD_REQUEST);
}
return;
} catch (HongsException ex) {
int ec = ex.getErrno();
if (ec != 0x10e8 && ec != 0x10e9 && ec != 0x10ea) {
throw ex;
}
}
chains.doAction();
}
Aggregations