This commit is contained in:
parent
73717d6e6f
commit
91302cb95a
|
@ -15,7 +15,7 @@ public class SecurityConstants {
|
|||
"/demo/**", // 测试接口
|
||||
"/api/user/register", // 用户注册
|
||||
"/api/user/login", // 用户登录
|
||||
"/api/user/register/email", // 邮箱注册
|
||||
"/api/user/getEmailCode", // 邮箱注册
|
||||
"/api/user/register/phone", // 手机号注册
|
||||
"/api/user/email/code", // 获取邮箱验证码
|
||||
"/api/user/phone/code" // 获取手机验证码
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.thymeleaf.context.Context;
|
|||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/demo")
|
||||
@RequestMapping("/user")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class DemoController {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.dto.user.RegisterDTO;
|
||||
import com.guwan.backend.dto.user.UserDTO;
|
||||
import com.guwan.backend.service.EmailService;
|
||||
import com.guwan.backend.service.UserService;
|
||||
import com.guwan.backend.util.RedisUtils;
|
||||
import com.guwan.backend.vo.user.LoginRequest;
|
||||
import com.guwan.backend.vo.user.RegisterRequest;
|
||||
import com.guwan.backend.vo.user.EmailRegisterRequest;
|
||||
|
@ -15,6 +19,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import org.thymeleaf.context.Context;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
@ -24,6 +31,10 @@ import jakarta.validation.constraints.Email;
|
|||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final EmailService emailService;
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@PostMapping("/register")
|
||||
public Result<UserDTO> register(@RequestBody @Valid RegisterDTO request) {
|
||||
|
@ -88,6 +99,24 @@ public class UserController {
|
|||
log.info("邮箱注册: {}", request.getEmail());
|
||||
return Result.success(userService.registerByEmail(request));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getEmailCode")
|
||||
public Result getEmailCode(@RequestBody Map<String, Object> params) {
|
||||
|
||||
String email = (String) params.get("email");
|
||||
log.info("邮箱注册: {}", email);
|
||||
Context context = new Context();
|
||||
context.setVariable("nowDate", DateUtil.now());
|
||||
String code = RandomUtil.randomNumbers(6);
|
||||
redisUtils.set(email, code, 10);
|
||||
context.setVariable("code", code.toCharArray());
|
||||
|
||||
emailService.sendHtmlMessage(email,
|
||||
"养老平台邮箱验证码", "email_template.html", context);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/register/phone")
|
||||
public Result<UserDTO> registerByPhone(@RequestBody @Valid PhoneRegisterRequest request) {
|
||||
|
|
|
@ -24,6 +24,14 @@ import java.io.IOException;
|
|||
* JWT认证过滤器
|
||||
* 负责处理JWT token的验证和用户认证
|
||||
*/
|
||||
|
||||
/**
|
||||
* SecurityConfig 和 JwtAuthenticationFilter 之间的关系是,
|
||||
* 在SecurityConfig中配置JwtAuthenticationFilter,
|
||||
* 使其成为Spring Security过滤器链的一部分。
|
||||
* 这样,当请求到达时,JwtAuthenticationFilter会先于Spring Security的其他过滤器执行,以验证JWT的有效性。
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
|
|
|
@ -10,13 +10,13 @@ spring:
|
|||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
password: root
|
||||
|
||||
# Redis配置
|
||||
data:
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6380
|
||||
port: 6379
|
||||
password: 123456 # 如果有密码,请设置
|
||||
database: 8
|
||||
timeout: 10000
|
||||
|
|
Loading…
Reference in New Issue