dev-v2 #3

Merged
bunny merged 122 commits from dev-v2 into master-v2 2024-03-30 23:40:58 +08:00
8 changed files with 27 additions and 7 deletions
Showing only changes of commit ca94463861 - Show all commits

View File

@ -9,4 +9,7 @@ public class EnumException {
public static final String USERNAME_IS_EMPTY = "用户名不能为空"; public static final String USERNAME_IS_EMPTY = "用户名不能为空";
public static final String PASSWORD_ERROR = "密码错误"; public static final String PASSWORD_ERROR = "密码错误";
public static final String PASSWORD_IS_EMPTY = "密码不能为空"; public static final String PASSWORD_IS_EMPTY = "密码不能为空";
public static final String CAPTCHA_IS_EMPTY = "提交验证码不能为空";
public static final String KEY_IS_EMPTY = "验证码key不能为空";
public static final String VERIFICATION_CODE_DOES_NOT_MATCH = "验证码不匹配";
} }

View File

@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -35,9 +36,21 @@ public class SysUserServiceImpl implements SysUserService {
public LoginVo login(LoginDto loginDto) { public LoginVo login(LoginDto loginDto) {
String password = loginDto.getPassword(); String password = loginDto.getPassword();
String userName = loginDto.getUserName(); String userName = loginDto.getUserName();
String captcha = loginDto.getCaptcha();
String key = loginDto.getCodeKey();
stringEmptyUtil.isEmpty(userName, EnumException.USERNAME_IS_EMPTY); stringEmptyUtil.isEmpty(userName, EnumException.USERNAME_IS_EMPTY);
stringEmptyUtil.isEmpty(password, EnumException.PASSWORD_IS_EMPTY); stringEmptyUtil.isEmpty(password, EnumException.PASSWORD_IS_EMPTY);
stringEmptyUtil.isEmpty(captcha, EnumException.CAPTCHA_IS_EMPTY);
stringEmptyUtil.isEmpty(key, EnumException.KEY_IS_EMPTY);
// 得到Redis中验证码
String code = (String) redisTemplate.opsForValue().get(key);
// 验证码不匹配
assert code != null;
if ((!Objects.equals(code.toLowerCase(), captcha.toLowerCase()))) {
throw new BunnyException(EnumException.VERIFICATION_CODE_DOES_NOT_MATCH);
}
// 比较完成后删除验证码
redisTemplate.delete(key);
// 根据username查询用户信息 // 根据username查询用户信息
SysUser sysUser = sysUserMapper.selectByUsername(userName); SysUser sysUser = sysUserMapper.selectByUsername(userName);
if (sysUser == null) { if (sysUser == null) {

View File

@ -1,22 +1,26 @@
package com.atguigu.spzx.model.dto.system; package com.atguigu.spzx.model.dto.system;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "用户登录请求参数") @Schema(description = "用户登录请求参数")
public class LoginDto { public class LoginDto {
@Schema(description = "用户名") @Schema(description = "用户名")
private String userName ; private String userName;
@Schema(description = "密码") @Schema(description = "密码")
private String password ; private String password;
@Schema(description = "提交验证码") @Schema(description = "提交验证码")
private String captcha ; private String captcha;
@Schema(description = "验证码key") @Schema(description = "验证码key")
private String codeKey ; private String codeKey;
} }