Search in sources :

Example 1 with ResultObject

use of com.codingmore.webapi.ResultObject in project coding-more by itwanger.

the class UsersController method getAdminInfo.

@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public ResultObject getAdminInfo(Principal principal) {
    if (principal == null) {
        return ResultObject.unauthorized(null);
    }
    AdminUserDetails adminUserDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Users user = adminUserDetails.getUsers();
    // ?
    user.setUserPass(null);
    Map<String, Object> data = new HashMap<>();
    data.put("userDetail", adminUserDetails.getUsers());
    data.put("username", user.getUserLogin());
    data.put("menus", roleService.getMenuList(user.getUsersId()));
    data.put("icon", user.getDisplayName());
    List<Role> roleList = usersService.getRoleList(user.getUsersId());
    if (CollUtil.isNotEmpty(roleList)) {
        List<String> roles = roleList.stream().map(Role::getName).collect(Collectors.toList());
        data.put("roles", roles);
    }
    return ResultObject.success(data);
}
Also used : Role(com.codingmore.model.Role) HashMap(java.util.HashMap) ResultObject(com.codingmore.webapi.ResultObject) Users(com.codingmore.model.Users) AdminUserDetails(com.codingmore.model.AdminUserDetails) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ResultObject

use of com.codingmore.webapi.ResultObject in project codingmore-learning by itwanger.

the class UsersController method getAdminInfo.

@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public ResultObject getAdminInfo(Principal principal) {
    if (principal == null) {
        return ResultObject.unauthorized(null);
    }
    String username = principal.getName();
    Users users = usersService.getAdminByUsername(username);
    Map<String, Object> data = new HashMap<>();
    data.put("username", users.getUserLogin());
    /*  data.put("menus", roleService.getMenuList(umsAdmin.getId()));
        data.put("icon", umsAdmin.getIcon());
        List<UmsRole> roleList = usersService.getRoleList(umsAdmin.getId());
        if(CollUtil.isNotEmpty(roleList)){
            List<String> roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList());
            data.put("roles",roles);
        }*/
    return ResultObject.success(data);
}
Also used : HashMap(java.util.HashMap) ResultObject(com.codingmore.webapi.ResultObject) Users(com.codingmore.model.Users) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Users (com.codingmore.model.Users)2 ResultObject (com.codingmore.webapi.ResultObject)2 ApiOperation (io.swagger.annotations.ApiOperation)2 HashMap (java.util.HashMap)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 AdminUserDetails (com.codingmore.model.AdminUserDetails)1 Role (com.codingmore.model.Role)1