parent
11d6d818ae
commit
59501feb4a
@ -1,84 +0,0 @@
|
||||
package com.luojia_channel.modules.captcha.controller;
|
||||
|
||||
import com.luojia_channel.common.domain.Result;
|
||||
import com.luojia_channel.modules.captcha.utils.CaptchaUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
@Tag(name = "图形验证码", description = "图形验证码相关接口")
|
||||
public class CaptchaController {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
/**
|
||||
* 生成验证码图片
|
||||
* @param request
|
||||
* @param res
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/captcha")
|
||||
@Operation(
|
||||
summary = "生成验证码图片"
|
||||
)
|
||||
public void generateCaptcha(HttpServletRequest request,
|
||||
HttpServletResponse res) throws IOException {
|
||||
|
||||
CaptchaUtils captcha = new CaptchaUtils();
|
||||
BufferedImage image = captcha.getImage();
|
||||
String text = captcha.getText();
|
||||
|
||||
String captchaKey = UUID.randomUUID().toString();
|
||||
redisTemplate.opsForValue().set("captcha:" + captchaKey, text, 60, TimeUnit.SECONDS);
|
||||
|
||||
Cookie cookie = new Cookie("captchaKey", captchaKey);
|
||||
cookie.setPath("/");
|
||||
res.addCookie(cookie);
|
||||
|
||||
CaptchaUtils.output(image,res.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证验证码
|
||||
* @param session
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/verify-captcha")
|
||||
public Result verifyCaptcha(@RequestBody Map<String, String> params, @CookieValue(value = "captchaKey", required = false) String captchaKey, HttpSession session) {
|
||||
String captcha = params.get("captcha");
|
||||
|
||||
if (captchaKey == null) {
|
||||
return Result.fail(500, "验证码已失效,请重新获取");
|
||||
}
|
||||
|
||||
String redisKey = "captcha:" + captchaKey;
|
||||
String correctCaptcha = redisTemplate.opsForValue().get(redisKey);
|
||||
if (correctCaptcha == null) {
|
||||
return Result.fail(500, "验证码已过期,请重新获取");
|
||||
}
|
||||
|
||||
if (captcha.equalsIgnoreCase(correctCaptcha)) {
|
||||
redisTemplate.delete(redisKey);
|
||||
return Result.success();
|
||||
} else {
|
||||
return Result.fail(500, "图形验证码错误");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.luojia_channel.modules.search.controller;
|
||||
|
||||
public class SearchController {
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.luojia_channel.modules.search.entity;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Data
|
||||
@Document(indexName = "post_index")
|
||||
public class EsPost {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Field(type = FieldType.Text, analyzer = "ik_max_word")
|
||||
private String title;
|
||||
|
||||
private String image;
|
||||
|
||||
@Field(type = FieldType.Text, analyzer = "ik_max_word")
|
||||
private String content;
|
||||
|
||||
private Integer status;
|
||||
private Integer likeCount;
|
||||
private Integer commentCount;
|
||||
private Integer favoriteCount;
|
||||
private Integer viewCount;
|
||||
private Long userId;
|
||||
private Long categoryId;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.luojia_channel.modules.search.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
|
||||
@Data
|
||||
@Document(indexName = "user_index")
|
||||
public class EsUser {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Field(type = FieldType.Text, analyzer = "ik_max_word")
|
||||
private String username;
|
||||
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String studentId;
|
||||
|
||||
private String avatar;
|
||||
private Integer gender;
|
||||
|
||||
|
||||
private Integer integral;
|
||||
|
||||
@Field(type = FieldType.Keyword)
|
||||
private String college;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.luojia_channel.modules.search.service;
|
||||
|
||||
public class SearchService {
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.luojia_channel.modules.search.task;
|
||||
|
||||
public class DataSyncTask {
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.luojia_channel.modules.captcha.utils;
|
||||
package com.luojia_channel.modules.user.utils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue