use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.
the class ArticleController method uploadImg.
@PostMapping("/img")
@ResponseBody
public Message uploadImg(@Param("file") MultipartFile file) {
// 得到文件最初的名字
String originalFileName = file.getOriginalFilename();
LOGGER.info(originalFileName);
String uuid = UUID.randomUUID().toString();
String newName = uuid + originalFileName.substring(originalFileName.lastIndexOf("."));
File dir = new File(settingService.get(CmsConst.PIC_PATH_SETTING));
if (!dir.exists()) {
dir.mkdirs();
}
File newFile = new File(dir, newName);
if (!newFile.exists()) {
try {
newFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
LOGGER.info("文件上传" + newFile.toString());
try {
file.transferTo(newFile);
} catch (IOException e) {
e.printStackTrace();
// return new Message(2, "存储文件错误", null);
}
String fileUrl = "/pic/" + newName;
Map<String, Object> map = new HashMap<>();
map.put("src", fileUrl);
return new Message(0, "success", map);
}
use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.
the class LoginController method login.
@PostMapping("/login")
public Message login(@RequestParam("userName") String userName, @RequestParam("password") String password) {
logger.info("用户" + userName + "进行登录");
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
// token.setRememberMe(true);
Message message = new Message();
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
message.setCode(100);
message.setMsg("ok");
} catch (Exception e) {
message.setCode(120);
message.setMsg("抱歉,信息错误");
return message;
}
return message;
}
use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.
the class BaseController method buildMessage.
Message buildMessage(int code, String msg, Object data) {
Message message = new Message();
message.setCode(code);
message.setMsg(msg);
message.setData(data);
return message;
}
use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.
the class PermissionController method addPermission.
/**
* 为用户组添加权限
*
* @return Message 权限是否添加成功
*/
@PostMapping("/addpermission")
public Message addPermission(@RequestBody PermissionData permissionData) {
Message message = new Message();
message.setMsg("添加权限失败");
message.setCode(0);
if (!this.index()) {
message.setMsg("添加权限失败");
return message;
}
Group group = groupService.selectByPrimaryKey(permissionData.getGroupId());
if (group != null) {
Integer gid = permissionData.getGroupId();
Integer cid = permissionData.getCategoryId();
Integer sid = permissionData.getSiteId();
List<String> pName = permissionData.getPermissionName();
Integer mid = permissionData.getMoudleId();
if (sid == null || pName == null)
return null;
if (judgeAuthUtil.judgeAuthIsNull(gid, PermissionUtil.formatSitePermissionName(sid))) {
permissionService.addSitePermissionToGroup(sid, gid);
addPermissionDescUtil.setSitePermissionDesc(sid);
message.setMsg("添加权限成功");
}
if (!pName.isEmpty() && cid != null) {
for (String i : pName) {
if (i.equals("READ")) {
if (judgeAuthUtil.judgeAuthIsNull(gid, PermissionUtil.formatCategoryPermissionName(sid, cid, i))) {
i = CmsConst.PERMISSION_READ;
permissionService.addCategoryPermissionToGroup(gid, sid, cid, i);
addPermissionDescUtil.setCategoryPermissionDesc(sid, cid, i);
}
} else if (i.equals("WRITE")) {
if (judgeAuthUtil.judgeAuthIsNull(gid, PermissionUtil.formatCategoryPermissionName(sid, cid, i))) {
i = CmsConst.PERMISSION_WRITE;
permissionService.addCategoryPermissionToGroup(gid, sid, cid, i);
addPermissionDescUtil.setCategoryPermissionDesc(sid, cid, i);
}
}
}
message.setMsg("添加权限成功");
message.setCode(0);
}
if (mid != null && !pName.isEmpty()) {
for (String i : pName) {
if (i.equals("READ")) {
if (judgeAuthUtil.judgeAuthIsNull(gid, PermissionUtil.formatModulePermissionName(sid, mid, i))) {
i = CmsConst.PERMISSION_READ;
permissionService.addModulePermissionToGroup(gid, sid, mid, i);
addPermissionDescUtil.setModulePermissionDesc(sid, mid, i);
}
} else if (i.equals("WRITE")) {
if (judgeAuthUtil.judgeAuthIsNull(gid, PermissionUtil.formatModulePermissionName(sid, mid, i))) {
i = CmsConst.PERMISSION_WRITE;
permissionService.addModulePermissionToGroup(gid, sid, mid, i);
addPermissionDescUtil.setModulePermissionDesc(sid, mid, i);
}
}
}
this.delectSurplusPermission(gid);
message.setMsg("添加权限成功");
message.setCode(0);
}
}
return message;
}
use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.
the class UserController method updateUser.
/**
* 修改用户信息
*
* @param userid
* @param user
* @return Message 修改用户是否成功
*/
@PostMapping(value = "/update/{userid}")
@ResponseBody
public Message updateUser(@PathVariable("userid") Integer userid, @RequestBody User user) {
Message message = new Message();
if (!this.index()) {
message.setMsg("添加权限失败");
return message;
}
int updateNumber;
if (userService.selectByPrimaryKey(userid) != null) {
updateNumber = userService.updateByPrimaryKeySelective(user);
message.setData(updateNumber);
message.setCode(1);
message.setMsg("success");
} else {
message.setMsg("用户不存在");
}
return message;
}
Aggregations