mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-21 22:53:56 +08:00
Manager web (#239)
* update:增加前端设计图 * 前端代码优化 * update:底部信息纠正 * 增加:flyio * update:去除org.quartz * update:登陆功能 * aliyunTTS常联token * 新增aliyunTTS长期Token方式 * 获取用户信息和已绑设备 * update:验证码,登录,注册 * update:去掉依赖错误代码 * update:去除验证码重复服务类 * update:删除重复验证码服务类 --------- Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: CGD <3030332422@qq.com> Co-authored-by: Ken <ulxiping@qq.com>
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
package xiaozhi.modules.sys.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author zjy
|
||||
* @since 2025-3-7
|
||||
*/
|
||||
public interface CaptchaService {
|
||||
/**
|
||||
* 生成验证码
|
||||
* @param response 响应对象
|
||||
* @param uuid 验证码唯一id
|
||||
*/
|
||||
void create(HttpServletResponse response, String uuid);
|
||||
|
||||
/**
|
||||
* 验证码验证
|
||||
* @param uuid 验证码唯一id
|
||||
* @param code 验证码内容
|
||||
* @return
|
||||
*/
|
||||
void validate(String uuid, String code);
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
package xiaozhi.modules.sys.service.impl;
|
||||
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xiaozhi.common.exception.ErrorCode;
|
||||
import xiaozhi.common.exception.RenException;
|
||||
import xiaozhi.common.redis.RedisUtils;
|
||||
import xiaozhi.modules.sys.service.CaptchaService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zjy
|
||||
* @since 2025-3-7
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("captchaService")
|
||||
public class CaptchaServiceImpl implements CaptchaService {
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Value("${captcha.expire}")
|
||||
private Integer captchaExpireTime;
|
||||
|
||||
|
||||
@Override
|
||||
public void create(HttpServletResponse response, String uuid) {
|
||||
response.setContentType("image/png");
|
||||
response.setHeader("Pragma", "No-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
response.setDateHeader("Expires", 0);
|
||||
|
||||
// 创建验证码对象 宽度、高度、字符长度
|
||||
SpecCaptcha captcha = new SpecCaptcha(130, 48, 5);
|
||||
// 默认字符类型
|
||||
captcha.setCharType(Captcha.TYPE_DEFAULT);
|
||||
// 缓存验证码
|
||||
redisUtils.set(uuid,captcha.text(),captchaExpireTime);
|
||||
|
||||
// 输出验证码图片
|
||||
try {
|
||||
captcha.out(response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
throw new RenException(ErrorCode.VERIFICATION_CODE,"验证码生成错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(String uuid, String code) {
|
||||
// 从缓存中获取验证码
|
||||
Object storedCode = redisUtils.get(uuid);
|
||||
//对验证码进行验证过程
|
||||
if(storedCode == null){
|
||||
throw new RenException(ErrorCode.VERIFICATION_CODE,"验证码过期,请从新获取");
|
||||
}else if(code.equalsIgnoreCase(storedCode.toString())){
|
||||
throw new RenException(ErrorCode.VERIFICATION_CODE,"验证码错误");
|
||||
}
|
||||
// 从缓存删除验证码
|
||||
redisUtils.delete(uuid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user