mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-20 18:45:38 +08:00
完成登录校验
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.types.PaginationResult;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/backend/v1/admin-user")
|
||||
public class AdminUserController {
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse List(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "size", defaultValue = "10") Integer size) {
|
||||
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, null);
|
||||
return JsonResponse.data(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.exception.JwtLogoutException;
|
||||
import xyz.playedu.api.middleware.ImageCaptchaCheckMiddleware;
|
||||
import xyz.playedu.api.request.LoginRequest;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.JWTService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.JwtToken;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
import xyz.playedu.api.util.RequestUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/auth")
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Autowired
|
||||
private JWTService jwtService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@ImageCaptchaCheckMiddleware
|
||||
public JsonResponse login(@RequestBody @Validated LoginRequest loginRequest) {
|
||||
AdminUser adminUser = adminUserService.findByEmail(loginRequest.email);
|
||||
if (adminUser == null) {
|
||||
return JsonResponse.error("邮箱不存在");
|
||||
}
|
||||
String password = HelperUtil.MD5(loginRequest.getPassword() + adminUser.getSalt()).toLowerCase();
|
||||
if (!adminUser.getPassword().equals(password)) {
|
||||
return JsonResponse.error("密码错误");
|
||||
}
|
||||
if (adminUser.getIsBanLogin() == 1) {
|
||||
return JsonResponse.error("当前用户禁止登录");
|
||||
}
|
||||
|
||||
String url = RequestUtil.url();
|
||||
JwtToken token = jwtService.generate(adminUser.getId(), url, SystemConstant.JWT_PRV_ADMIN_USER);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("token", token.getToken());
|
||||
data.put("expire", token.getExpire());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public JsonResponse logout() throws JwtLogoutException {
|
||||
jwtService.logout(RequestUtil.token(), SystemConstant.JWT_PRV_ADMIN_USER);
|
||||
return JsonResponse.success("success");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.service.ImageCaptchaService;
|
||||
import xyz.playedu.api.types.ImageCaptchaResult;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/system")
|
||||
public class SystemController {
|
||||
|
||||
@Autowired
|
||||
private ImageCaptchaService imageCaptchaService;
|
||||
|
||||
@GetMapping("/image-captcha")
|
||||
public JsonResponse imageCaptcha() throws IOException {
|
||||
ImageCaptchaResult imageCaptchaResult = imageCaptchaService.generate();
|
||||
|
||||
HashMap<String, String> data = new HashMap();
|
||||
data.put("key", imageCaptchaResult.getKey());
|
||||
data.put("image", imageCaptchaResult.getImage());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user