| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.map.MapBuilder; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import cn.hutool.extra.servlet.ServletUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | |
| | | import com.sandu.ximon.admin.security.PermissionConfig; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.*; |
| | | import com.sandu.ximon.admin.utils.IPUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.bo.MenuNode; |
| | |
| | | if (admin == null) { |
| | | return ResponseUtil.error(ResponseStatusEnums.BAD_CREDENTIALS.getCode(), ResponseStatusEnums.BAD_CREDENTIALS.getMessage()); |
| | | } |
| | | // String s = RedisUtils.getBean().get(loginParam.getKey()); |
| | | // if (!loginParam.getVlue().equals(s)) { |
| | | // log.error(loginParam.getVlue() + "验证码"); |
| | | // return ResponseUtil.error(ResponseStatusEnums.BAD_AUTHENTICATION.getCode(), ResponseStatusEnums.BAD_AUTHENTICATION.getMessage()); |
| | | // } |
| | | // RedisUtils.getBean().delete(loginParam.getKey()); |
| | | String s = RedisUtils.getBean().get(loginParam.getKey()); |
| | | if (!loginParam.getVlue().equals(s)) { |
| | | log.error(loginParam.getVlue() + "验证码"); |
| | | return ResponseUtil.error(ResponseStatusEnums.BAD_AUTHENTICATION.getCode(), ResponseStatusEnums.BAD_AUTHENTICATION.getMessage()); |
| | | } |
| | | RedisUtils.getBean().delete(loginParam.getKey()); |
| | | if (!passwordEncoder.matches(loginParam.getPassword(), admin.getPassword())) { |
| | | return ResponseUtil.error(ResponseStatusEnums.BAD_CREDENTIALS.getCode(), ResponseStatusEnums.BAD_CREDENTIALS.getMessage()); |
| | | } |
| | |
| | | put("token", properties.getTokenStartWith() + token); |
| | | put("user", admin); |
| | | }}; |
| | | //保存登录信息到日志 |
| | | |
| | | |
| | | /** |
| | | * 登录信息日志记录开始 |
| | | */ |
| | | UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); |
| | | Browser browser = userAgent.getBrowser(); |
| | | OperatingSystem os = userAgent.getOperatingSystem(); |
| | | String content = "登录IP地址:" + IPUtils.getPublicIp() + ",操作系统:" + os + ",浏览器:" + browser; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "用户登录", content, null); |
| | | String content = "用户ID:" + admin.getId() |
| | | + ",用户名:" + admin.getUsername() |
| | | + ",用户类型:管理员" |
| | | + ",登录IP地址:" + ServletUtil.getClientIP(request) |
| | | + ",操作系统:" + os |
| | | + ",浏览器:" + browser; |
| | | StoreOperationRecordsUtils.storeOperationLoginData(admin.getId(), admin.getUsername(), "管理员登录", content); |
| | | /** |
| | | * 登录信息日志记录结束 |
| | | */ |
| | | return ResponseUtil.success(authInfo); |
| | | } |
| | | |
| | |
| | | |
| | | @GetMapping(value = "/logout") |
| | | public ResponseVO<Object> LogOut() { |
| | | String content = "用户名:" + SecurityUtils.getUsername(); |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "用管理员退出登录", content); |
| | | String key = String.format("%d_%d", SecurityUtils.getUserDetails().getUserId(), SecurityUtils.getUserDetails().getAdministratorType()); |
| | | redisService.set(key, null); |
| | | return ResponseUtil.success("退出登录成功"); |
| | |
| | | |
| | | @Log("后台用户列表") |
| | | @GetMapping(value = "/list") |
| | | public ResponseVO<Object> listAdmin(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) { |
| | | public ResponseVO<Object> listAdmin(BaseConditionVO baseConditionVO, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "order", required = false) Integer order, |
| | | @RequestParam(value = "seq", required = false) Integer seq) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | return ResponseUtil.successPage(adminService.listAdmin(baseConditionVO, keyword)); |
| | | return ResponseUtil.successPage(adminService.listAdmin(baseConditionVO, keyword, order, seq)); |
| | | } |
| | | |
| | | @Log("后台用户注册") |
| | |
| | | } |
| | | } |
| | | |
| | | @Log("后台用户删除") |
| | | @PostMapping("/del/{adminId}") |
| | | @GetMapping("/del/{adminId}") |
| | | public ResponseVO<Object> deleteAdmin(@PathVariable Long adminId) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_DELETE.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = adminService.deleteAdmin(adminId); |
| | | if (result) { |
| | | return ResponseUtil.success("修改成功"); |
| | | return ResponseUtil.success("删除管理员成功!"); |
| | | } else { |
| | | return ResponseUtil.fail("修改失败"); |
| | | return ResponseUtil.fail("删除管理员失败!"); |
| | | } |
| | | } |
| | | |