use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class AuthKit method openSign.
/**
* 第三方登录
* @param ah
* @param unit
* @param code
* @param uname 名称
* @param uhead 头像
* @return
* @throws HongsException
*/
public static Map openSign(ActionHelper ah, String unit, String code, String uname, String uhead) throws HongsException {
DB db = DB.getInstance("master");
Table tb = db.getTable("user_sign");
Table ub = db.getTable("user");
Map ud = tb.fetchCase().from(tb.tableName, "s").join(ub.tableName, "u", "`u`.`id` = `s`.`user_id`").filter("`s`.`unit` = ? AND `s`.`code` = ?", unit, code).select("`u`.`id`, `u`.`name`, `u`.`head`, `u`.`state`").getOne();
int stat = Synt.declare(ud.get("state"), 0);
String uuid;
if (!ud.isEmpty()) {
// 锁定或系统账号
if (stat <= 0) {
throw new Wrongs(Synt.mapOf("state", new Wrong("core.sign.state.invalid"))).setLocalizedContext("master");
// .setLocalizedOptions( stat );
}
uuid = (String) ud.get("id");
uname = (String) ud.get("name");
uhead = (String) ud.get("head");
} else {
ud = new HashMap();
ud.put("name", uname);
ud.put("head", uhead);
// 校验及下载头像
ud = new VerifyHelper().addRulesByForm("master", "user").verify(ud, true, true);
uuid = db.getModel("user").add(ud);
uname = (String) ud.get("name");
uhead = (String) ud.get("head");
// 第三方登录项
ud = new HashMap();
ud.put("user_id", uuid);
ud.put("unit", unit);
ud.put("code", code);
db.getTable("user_sign").insert(ud);
// 加入公共部门
ud = new HashMap();
ud.put("user_id", uuid);
ud.put("dept_id", "CENTRE");
db.getTable("dept_user").insert(ud);
// 赋予公共权限. 仅用部门即可(2019/02/28)
// ud = new HashMap( );
// ud.put("user_id", uuid );
// ud.put("role" , "centre");
// db.getTable("user_role").insert(ud);
}
ud = userSign(ah, unit, uuid, uname, uhead);
ud.put("unit", /**/
unit);
ud.put("regs", 0 == stat);
return ud;
}
use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class UploadHelper method upload.
/**
* 检查文件流并写入目标目录
* @param xis 上传文件输入流
* @param type 上传文件类型
* @param extn 上传文件扩展
* @param subn 目标文件名称
* @return
* @throws Wrong
*/
public File upload(InputStream xis, String type, String extn, String subn) throws Wrong {
if (type.contains(";")) {
type = type.substring(0, type.indexOf(";"));
}
if (extn.contains(".")) {
extn = extn.substring(1 + extn.lastIndexOf('.'));
}
chkTypeOrExtn(type, extn);
setResultName(subn, extn);
File file = new File(getResultPath());
File fdir = file.getParentFile();
if (!fdir.exists()) {
fdir.mkdirs();
}
// 拷贝数据
try {
try (FileOutputStream fos = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(xis);
BufferedOutputStream bos = new BufferedOutputStream(fos)) {
byte[] buf = new byte[1024];
int ovr;
while ((ovr = bis.read(buf)) != -1) {
bos.write(buf, 0, ovr);
}
}
} catch (IOException ex) {
throw new Wrong(ex, "fore.form.upload.failed");
}
return file;
}
use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class AuthKit method getWrong.
/**
* 快速输出登录的错误
* @param k 字段
* @param w 错误
* @return
*/
public static Map getWrong(String k, String w) {
CoreLocale l = CoreLocale.getInstance("master");
Map e = new HashMap();
if (k != null && !"".equals(k)) {
Map m = new HashMap();
m.put(k, new Wrong(w));
e.put("errs", new Wrongs(m).setLocalizedContext(l).getErrors());
e.put("msg", l.translate(w));
} else {
e.put("msg", l.translate(w));
}
e.put("ok", false);
return e;
}
use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class UploadHelper method upload.
/**
* 检查上传对象并写入目标目录
* @param part
* @param subn
* @return
* @throws Wrong
*/
public File upload(Part part, String subn) throws Wrong {
if (part == null) {
setResultName("", null);
return null;
}
/**
* 从上传项中获取类型并提取扩展名
*/
String type = part.getContentType();
type = getTypeByMime(type);
String extn = part.getSubmittedFileName();
extn = getExtnByName(extn);
try {
return upload(part.getInputStream(), type, extn, subn);
} catch (IOException ex) {
throw new Wrong(ex, "fore.form.upload.failed");
}
}
use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class UploadHelper method upload.
/**
* 检查临时文件或目标链接情况
* 参数为临时文件名或结果链接
* 注意: 如果有 URL encode 务必先 decode
* @param name
* @return
* @throws Wrong
*/
public File upload(String name) throws Wrong {
if (name == null || name.length() == 0) {
setResultName("", null);
return null;
}
// 避免 Windows 异常
name = name.replace('\\', '/');
/**
* 值与目标网址的前导路径如果一致,
* 视为修改表单且没有重新上传文件;
* 但需规避用相对路径访问敏感文件,
* 目录不得以点结尾, 如 ./ 和 ../
*
* 反之将其视为传递来的临时文件名,
* 此时不得含斜杠从而规避同上问题.
*/
String subn;
do {
String href = getResultHref(uploadHref) + "/";
String path = getResultPath(uploadPath) + "/";
if (name.startsWith(href)) {
subn = name.substring(href.length());
if (subn.contains("./")) {
throw new Wrong("core.file.upload.not.allows");
}
name = path + subn;
break;
}
if (name.startsWith(path)) {
subn = name.substring(path.length());
if (subn.contains("./")) {
throw new Wrong("core.file.upload.not.allows");
}
// name = path + subn;
break;
}
String temp = getUploadTemp(uploadTemp) + "/";
{
if (name.contains("./")) {
throw new Wrong("core.file.upload.not.allows");
}
name = temp + name;
subn = getDigestName(new File(name));
break;
}
} while (false);
return upload(new File(name), subn);
}
Aggregations