Search in sources :

Example 6 with Message

use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.

the class UserController method addUser.

/**
 * 添加用户
 * @param user
 * @return   Message 添加用户是否成功
 */
@PostMapping("/add")
@ResponseBody
public Message addUser(@RequestBody User user) {
    Message message = new Message();
    if (!this.index()) {
        message.setMsg("添加权限失败");
        return message;
    }
    user.setUserCreateTime(new Date());
    UserExample userExample = new UserExample();
    userExample.createCriteria().andUserNameEqualTo(user.getUserName());
    List<User> userList = userService.selectByExample(userExample);
    if (userList != null && !userList.isEmpty()) {
        message.setMsg("用户已存在");
        message.setCode(1);
    } else {
        userService.createUser(user);
        message.setCode(0);
        message.setMsg("成功添加");
    }
    return message;
}
Also used : User(com.ganster.cms.core.pojo.User) Message(com.ganster.cms.admin.dto.Message) Date(java.util.Date) UserExample(com.ganster.cms.core.pojo.UserExample)

Example 7 with Message

use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.

the class CategoryController method add.

@PostMapping("/add")
public Message add(@RequestBody Category category) {
    Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
    // 判断栏目内容是否为空
    if (category == null) {
        return super.buildMessage(1, "false", null);
    }
    // 判断登陆用户是否具有对栏目具有写的操作
    // 查询栏目对应的modelId
    ModuleExample moduleExample = new ModuleExample();
    moduleExample.or().andModuleNameEqualTo("栏目管理");
    Module module = moduleService.selectByExample(moduleExample).get(0);
    if (!permissionService.hasModulePermission(userId, category.getCategorySiteId(), module.getModuleId(), CmsConst.PERMISSION_WRITE)) {
        return super.buildMessage(2, "Null Permission", null);
    }
    // 插入栏目数据表的操作
    category.setCategoryCreateTime(new Date());
    category.setCategorySkin("default");
    Category parentCategory = categoryService.selectByPrimaryKey(category.getCategoryParentId());
    Integer level = parentCategory.getCategoryLevel();
    if (level == -1) {
        category.setCategoryLevel(0);
    } else {
        category.setCategoryLevel(level + 1);
    }
    int count = categoryService.insert(category);
    // 插入权限表的操作
    try {
        User user = userService.selectByPrimaryKey(userId);
        permissionService.addCategoryPermissionToUser(userId, category.getCategorySiteId(), category.getCategoryId(), CmsConst.PERMISSION_READ);
        permissionService.addCategoryPermissionToUser(userId, category.getCategorySiteId(), category.getCategoryId(), CmsConst.PERMISSION_WRITE);
        ArticleController.addPermission(category, user, userService, permissionService);
        PermissionUtil.flush(userId);
    } catch (UserNotFoundException e) {
        e.printStackTrace();
        return new Message(1, "false", "没有找到该用户");
    }
    if (count == 1) {
        return new Message(0, "success", count);
    } else {
        return new Message(1, "false", count);
    }
}
Also used : UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) Message(com.ganster.cms.admin.dto.Message) Date(java.util.Date)

Example 8 with Message

use of com.ganster.cms.admin.dto.Message in project Ganster-CMS by Gangster-trio.

the class InformationController method findInformation.

@GetMapping("/{UserId}")
public Message findInformation(@PathVariable("UserId") Integer userId) {
    Message message = new Message();
    InformationObject informationObject = new InformationObject();
    User user = userService.selectByPrimaryKey(userId);
    informationObject.setUserName(user.getUserName());
    informationObject.setUserPhone(user.getUserPhone());
    informationObject.setUserEmail(user.getUserEmail());
    informationObject.setUserStatus(user.getUserStatus());
    informationObject.setUserCreateTime(user.getUserCreateTime());
    informationObject.setUserOrg(user.getUserOrg());
    List<String> groupName = groupService.selectByUserId(userId).stream().map(group -> "<input type='text' disabled='disabled' value='" + group.getGroupName() + "'" + "class='layui-input'" + "/>").collect(Collectors.toList());
    informationObject.setUserGroup(groupName);
    message.setData(informationObject);
    return message;
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Message(com.ganster.cms.admin.dto.Message) Collectors(java.util.stream.Collectors) UserService(com.ganster.cms.core.service.UserService) ArrayList(java.util.ArrayList) List(java.util.List) InformationObject(com.ganster.cms.admin.dto.InformationObject) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(com.ganster.cms.core.pojo.User) Group(com.ganster.cms.core.pojo.Group) GroupService(com.ganster.cms.core.service.GroupService) SecurityUtils(org.apache.shiro.SecurityUtils) User(com.ganster.cms.core.pojo.User) Message(com.ganster.cms.admin.dto.Message) InformationObject(com.ganster.cms.admin.dto.InformationObject)

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