商户登录相关
This commit is contained in:
parent
4cd260d0b9
commit
80d1325753
|
|
@ -1,6 +1,10 @@
|
||||||
package com.czg.controller;
|
package com.czg.controller;
|
||||||
|
|
||||||
|
import com.czg.dto.SysLoginDTO;
|
||||||
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
|
import com.czg.service.AuthorizationService;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
@ -12,10 +16,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("auth")
|
@RequestMapping("auth")
|
||||||
public class AuthorizationController {
|
public class AuthorizationController {
|
||||||
|
private final AuthorizationService authorizationService;
|
||||||
|
|
||||||
|
public AuthorizationController(AuthorizationService authorizationService) {
|
||||||
|
this.authorizationService = authorizationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("captcha")
|
||||||
|
public CzgResult<?> captcha() {
|
||||||
|
return CzgResult.success(authorizationService.getCaptcha());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public void login() {
|
public CzgResult<?> login(@Validated SysLoginDTO loginDTO) {
|
||||||
StpKit.USER.checkLogin();
|
return CzgResult.success(authorizationService.login(loginDTO));
|
||||||
System.out.println(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.czg.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("shopInfo")
|
||||||
|
public class ShopInfoController {
|
||||||
|
}
|
||||||
|
|
@ -3,11 +3,13 @@ package com.czg.config;
|
||||||
import cn.dev33.satoken.SaManager;
|
import cn.dev33.satoken.SaManager;
|
||||||
import cn.dev33.satoken.application.ApplicationInfo;
|
import cn.dev33.satoken.application.ApplicationInfo;
|
||||||
import cn.dev33.satoken.config.SaTokenConfig;
|
import cn.dev33.satoken.config.SaTokenConfig;
|
||||||
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
|
@ -17,6 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
public class SaTokenConfigure implements WebMvcConfigurer {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
|
@ -47,10 +50,13 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 注册路由拦截器,自定义认证规则
|
// 注册路由拦截器,自定义认证规则
|
||||||
registry.addInterceptor(new SaInterceptor(handler -> {
|
registry.addInterceptor(new SaInterceptor(handler -> {
|
||||||
|
log.info(SaHolder.getRequest().getRequestPath());
|
||||||
// 重置根路径,防止satoken切割根路径导致匹配不到路径
|
// 重置根路径,防止satoken切割根路径导致匹配不到路径
|
||||||
ApplicationInfo.routePrefix = "";
|
ApplicationInfo.routePrefix = "";
|
||||||
|
|
||||||
SaRouter.match("/admin/**").check(r -> StpKit.ADMIN.checkLogin());
|
SaRouter.match("/admin/**")
|
||||||
|
.notMatch("/admin/auth/**")
|
||||||
|
.check(r -> StpKit.ADMIN.checkLogin());
|
||||||
SaRouter.match("/user/**").check(r -> StpKit.USER.checkLogin());
|
SaRouter.match("/user/**").check(r -> StpKit.USER.checkLogin());
|
||||||
})).addPathPatterns("/**");
|
})).addPathPatterns("/**");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,15 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.whvcse</groupId>
|
||||||
|
<artifactId>easy-captcha</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.czg</groupId>
|
||||||
|
<artifactId>cash-common-tools</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.czg.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public record SysLoginDTO(
|
||||||
|
@NotEmpty(message = "用户名不为空")
|
||||||
|
String username,
|
||||||
|
@NotEmpty(message = "密码不为空")
|
||||||
|
String password,
|
||||||
|
@NotEmpty(message = "验证码不为空")
|
||||||
|
String code,
|
||||||
|
@NotEmpty(message = "uid不为空")
|
||||||
|
String uuid,
|
||||||
|
String staffName
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.czg.service;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
public interface AuthorizationService {
|
||||||
|
Object getCaptcha();
|
||||||
|
|
||||||
|
Object login(com.czg.dto.SysLoginDTO loginDTO);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.czg.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.czg.dto.SysLoginDTO;
|
||||||
|
import com.czg.service.AuthorizationService;
|
||||||
|
import com.wf.captcha.SpecCaptcha;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AuthorizationServiceImpl implements AuthorizationService {
|
||||||
|
@Override
|
||||||
|
public Object getCaptcha() {
|
||||||
|
// 生成验证码(130x48,4位字符)
|
||||||
|
SpecCaptcha captcha = new SpecCaptcha(130, 48, 4);
|
||||||
|
|
||||||
|
// 获取验证码文本
|
||||||
|
String code = captcha.text();
|
||||||
|
|
||||||
|
// 生成唯一的验证码 ID
|
||||||
|
String captchaKey = IdUtil.randomUUID();
|
||||||
|
|
||||||
|
// 返回 Base64 格式验证码
|
||||||
|
return Map.of("code", captcha.toBase64(), "uuid", captchaKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object login(SysLoginDTO loginDTO) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
4
pom.xml
4
pom.xml
|
|
@ -66,6 +66,10 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.minidev</groupId>
|
<groupId>net.minidev</groupId>
|
||||||
<artifactId>json-smart</artifactId>
|
<artifactId>json-smart</artifactId>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue