| | |
| | | import com.vincent.rsf.server.system.entity.Tenant; |
| | | import com.vincent.rsf.server.system.entity.User; |
| | | import com.vincent.rsf.server.system.entity.UserLogin; |
| | | import com.vincent.rsf.server.system.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import com.vincent.rsf.server.system.enums.StatusType; |
| | | import com.vincent.rsf.server.system.service.RoleMenuService; |
| | | import com.vincent.rsf.server.system.service.TenantService; |
| | | import com.vincent.rsf.server.system.service.UserLoginService; |
| | | import com.vincent.rsf.server.system.service.UserService; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | private RoleMenuService roleMenuService; |
| | | @Resource |
| | | private TenantService tenantService; |
| | | @Autowired |
| | | private UserRoleService userRoleService; |
| | | |
| | | @PostMapping("/login") |
| | | public R login(@RequestBody LoginParam param, HttpServletRequest request) { |
| | |
| | | if (user == null) { |
| | | return R.error("Username Does Not Exist"); |
| | | } |
| | | if (!user.getStatus().equals(1)) { |
| | | if (!user.getStatus().equals(StatusType.ENABLE.val)) { |
| | | return R.error("Account Frozen"); |
| | | } |
| | | if (!userService.comparePassword(user.getPassword(), param.getPassword())) { |
| | | return R.error("Wrong Password"); |
| | | return R.error("Invalid Password"); |
| | | } |
| | | String accessToken = JwtUtil.buildToken(new JwtSubject(username, user.getTenantId()), |
| | | configProperties.getTokenExpireTime(), configProperties.getTokenKey()); |
| | | userLoginService.saveAsync(user.getId(), accessToken, UserLogin.TYPE_LOGIN, tenantId, null, request); |
| | | Tenant tenant = tenantService.getById(user.getTenantId()); |
| | | return R.ok("Login Success").add(new LoginResult(accessToken, user, tenant.getName())); |
| | | return R.ok("Sign In Success").add(new LoginResult(accessToken, user, tenant.getName())); |
| | | } |
| | | |
| | | @GetMapping("/tenant/list") |
| | |
| | | |
| | | @GetMapping("/auth/user") |
| | | public R userInfo() { |
| | | User user = userService.getByIdRel(getLoginUserId()); |
| | | user.setRoles(userRoleService.listByUserId(user.getId())); |
| | | return R.ok(user); |
| | | User user = userService.getById(getLoginUserId()); |
| | | return R.ok(userService.setUserAuthInfo(user)); |
| | | } |
| | | |
| | | @GetMapping("/auth/menu") |
| | | public R userMenu() { |
| | | List<Menu> menus = roleMenuService.listMenuByUserId(getLoginUserId(), Menu.TYPE_MENU); |
| | | // return R.ok().add(Utils.toTreeData(menus, 0L, Menu::getParentId, Menu::getId, Menu::setChildren)); |
| | | List<MenuVo> voList = menus.stream().map(this::convertToVo).collect(Collectors.toList()); |
| | | // exclude tenant |
| | | if (!configProperties.getSuperUserList().contains(getLoginUser().getUsername())) { |
| | | voList = voList.stream().filter(vo -> |
| | | !vo.getName().equals("menu.tenant") |
| | | && !vo.getName().equals("menu.menu") |
| | | ).collect(Collectors.toList()); |
| | | } |
| | | return R.ok().add(Utils.toTreeData(voList, 0L, MenuVo::getParentId, MenuVo::getId, MenuVo::setChildren)); |
| | | } |
| | | |
| | |
| | | user.setTenantId(null); |
| | | user.setStatus(null); |
| | | if (userService.updateById(user)) { |
| | | return R.ok("Save Success").add(userService.getByIdRel(user.getId())); |
| | | return R.ok("Save Success").add(userService.getById(user.getId())); |
| | | } |
| | | return R.error("Save Fail"); |
| | | } |