use of com.tale.model.entity.Users in project tale by otale.
the class BaseWebHook method isRedirect.
private boolean isRedirect(RouteContext context) {
Users user = TaleUtils.getLoginUser();
String uri = context.uri();
if (uri.startsWith(TaleConst.ADMIN_URI) && !uri.startsWith(TaleConst.LOGIN_URI)) {
context.attribute(TaleConst.PLUGINS_MENU_NAME, TaleConst.PLUGIN_MENUS);
if (null != user) {
return true;
}
Integer uid = TaleUtils.getCookieUid(context);
if (null != uid) {
user = select().from(Users.class).byId(uid);
context.session().attribute(TaleConst.LOGIN_SESSION_KEY, user);
}
if (null == user) {
context.redirect(TaleConst.LOGIN_URI);
return false;
}
}
return true;
}
use of com.tale.model.entity.Users in project tale by otale.
the class TaleUtils method getLoginUser.
/**
* 返回当前登录用户
*/
public static Users getLoginUser() {
Session session = com.blade.mvc.WebContext.request().session();
if (null == session) {
return null;
}
Users user = session.attribute(TaleConst.LOGIN_SESSION_KEY);
return user;
}
use of com.tale.model.entity.Users in project tale by otale.
the class InstallController method doInstall.
@PostRoute
@JSON
public RestResponse<?> doInstall(InstallParam installParam) {
if (isRepeatInstall()) {
return RestResponse.fail("请勿重复安装");
}
CommonValidator.valid(installParam);
Users temp = new Users();
temp.setUsername(installParam.getAdminUser());
temp.setPassword(installParam.getAdminPwd());
temp.setEmail(installParam.getAdminEmail());
siteService.initSite(temp);
String siteUrl = TaleUtils.buildURL(installParam.getSiteUrl());
optionsService.saveOption("site_title", installParam.getSiteTitle());
optionsService.saveOption("site_url", siteUrl);
TaleConst.OPTIONS = Environment.of(optionsService.getOptions());
return RestResponse.ok();
}
use of com.tale.model.entity.Users 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.model.entity.Users 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();
}
Aggregations