Search in sources :

Example 1 with Message

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);
}
Also used : Message(com.ganster.cms.admin.dto.Message) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 2 with Message

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;
}
Also used : Message(com.ganster.cms.admin.dto.Message) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with 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;
}
Also used : Message(com.ganster.cms.admin.dto.Message)

Example 4 with 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;
}
Also used : Message(com.ganster.cms.admin.dto.Message)

Example 5 with 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;
}
Also used : Message(com.ganster.cms.admin.dto.Message)

Aggregations

Message (com.ganster.cms.admin.dto.Message)8 User (com.ganster.cms.core.pojo.User)2 Date (java.util.Date)2 InformationObject (com.ganster.cms.admin.dto.InformationObject)1 UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)1 Group (com.ganster.cms.core.pojo.Group)1 UserExample (com.ganster.cms.core.pojo.UserExample)1 GroupService (com.ganster.cms.core.service.GroupService)1 UserService (com.ganster.cms.core.service.UserService)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 SecurityUtils (org.apache.shiro.SecurityUtils)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1