use of com.tale.annotation.SysLog in project tale by otale.
the class BaseWebHook method after.
@Override
public boolean after(RouteContext context) {
if (null != TaleUtils.getLoginUser()) {
SysLog sysLog = context.routeAction().getAnnotation(SysLog.class);
if (null != sysLog) {
Logs logs = new Logs();
logs.setAction(sysLog.value());
logs.setAuthorId(TaleUtils.getLoginUser().getUid());
logs.setIp(context.request().address());
if (!context.request().uri().contains("upload")) {
logs.setData(context.request().bodyToString());
}
logs.setCreated(DateKit.nowUnix());
logs.save();
}
}
return true;
}
use of com.tale.annotation.SysLog in project tale by otale.
the class AdminApiController method saveOptions.
@SysLog("保存系统配置")
@PostRoute("options/save")
public RestResponse<?> saveOptions(Request request) {
Map<String, List<String>> querys = request.parameters();
querys.forEach((k, v) -> optionsService.saveOption(k, v.get(0)));
Environment config = Environment.of(optionsService.getOptions());
TaleConst.OPTIONS = config;
return RestResponse.ok();
}
use of com.tale.annotation.SysLog in project tale by otale.
the class IndexController method upload.
/**
* 上传文件接口
*/
@SysLog("上传附件")
@PostRoute("api/attach/upload")
@JSON
public RestResponse<?> upload(Request request) {
log.info("UPLOAD DIR = {}", TaleUtils.UP_DIR);
Users users = this.user();
Integer uid = users.getUid();
List<Attach> errorFiles = new ArrayList<>();
List<Attach> urls = new ArrayList<>();
Map<String, FileItem> fileItems = request.fileItems();
if (null == fileItems || fileItems.size() == 0) {
return RestResponse.fail("请选择文件上传");
}
fileItems.forEach((fileName, fileItem) -> {
String fname = fileItem.getFileName();
if ((fileItem.getLength() / 1024) <= TaleConst.MAX_FILE_SIZE) {
String fkey = TaleUtils.getFileKey(fname);
String ftype = fileItem.getContentType().contains("image") ? Types.IMAGE : Types.FILE;
String filePath = TaleUtils.UP_DIR + fkey;
try {
Files.write(Paths.get(filePath), fileItem.getData());
if (TaleUtils.isImage(new File(filePath))) {
String newFileName = TaleUtils.getFileName(fkey);
String thumbnailFilePath = TaleUtils.UP_DIR + fkey.replace(newFileName, "thumbnail_" + newFileName);
ImageUtils.cutCenterImage(CLASSPATH + fkey, thumbnailFilePath, 270, 380);
}
} catch (IOException e) {
log.error("", e);
}
Attach attach = new Attach();
attach.setFname(fname);
attach.setAuthorId(uid);
attach.setFkey(fkey);
attach.setFtype(ftype);
attach.setCreated(DateKit.nowUnix());
attach.save();
urls.add(attach);
siteService.cleanCache(Types.SYS_STATISTICS);
} else {
Attach attach = new Attach();
attach.setFname(fname);
errorFiles.add(attach);
}
});
if (errorFiles.size() > 0) {
return RestResponse.fail().payload(errorFiles);
}
return RestResponse.ok(urls);
}
use of com.tale.annotation.SysLog in project tale by otale.
the class SystemController method saveProfile.
@SysLog("保存个人信息")
@PostRoute("profile")
public RestResponse saveProfile(@Param String screenName, @Param String email) {
Users users = this.user();
if (StringKit.isNotBlank(screenName) && StringKit.isNotBlank(email)) {
Users temp = new Users();
temp.setScreenName(screenName);
temp.setEmail(email);
temp.updateById(users.getUid());
}
return RestResponse.ok();
}
use of com.tale.annotation.SysLog in project tale by otale.
the class SystemController method upPwd.
@SysLog("修改登录密码")
@PostRoute("password")
public RestResponse upPwd(@Param String old_password, @Param String password) {
Users users = this.user();
if (StringKit.isBlank(old_password) || StringKit.isBlank(password)) {
return RestResponse.fail("请确认信息输入完整");
}
if (!users.getPassword().equals(EncryptKit.md5(users.getUsername() + old_password))) {
return RestResponse.fail("旧密码错误");
}
if (password.length() < 6 || password.length() > 14) {
return RestResponse.fail("请输入6-14位密码");
}
Users temp = new Users();
String pwd = EncryptKit.md5(users.getUsername() + password);
temp.setPassword(pwd);
temp.updateById(users.getUid());
optionsService.deleteOption(TaleConst.OPTION_SAFE_REMEMBER_ME);
return RestResponse.ok();
}
Aggregations