Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
9a02181211 | |||
c246abab12 | |||
529a0a755c |
5
pom.xml
5
pom.xml
@ -37,6 +37,11 @@
|
|||||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
||||||
<version>4.1.1</version>
|
<version>4.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.3</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
package cn.czyx007.reggie.config;
|
package cn.czyx007.reggie.config;
|
||||||
|
|
||||||
import cn.czyx007.reggie.common.JacksonObjectMapper;
|
import cn.czyx007.reggie.common.JacksonObjectMapper;
|
||||||
|
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -14,13 +23,36 @@ import java.util.List;
|
|||||||
* @createTime : 2022/12/20 - 19:54
|
* @createTime : 2022/12/20 - 19:54
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
@EnableKnife4j
|
||||||
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
||||||
|
private ApiInfo apiInfo(){
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title("瑞吉外卖")
|
||||||
|
.version("1.0")
|
||||||
|
.description("瑞吉外卖接口文档")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket createRestApi(){
|
||||||
|
//文档类型
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.apiInfo(apiInfo())
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("cn.czyx007.reggie.controller"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
* @param registry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend/");
|
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend/");
|
||||||
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/static/front/");
|
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/static/front/");
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package cn.czyx007.reggie.controller;
|
|||||||
import cn.czyx007.reggie.bean.User;
|
import cn.czyx007.reggie.bean.User;
|
||||||
import cn.czyx007.reggie.common.R;
|
import cn.czyx007.reggie.common.R;
|
||||||
import cn.czyx007.reggie.service.UserService;
|
import cn.czyx007.reggie.service.UserService;
|
||||||
|
import cn.czyx007.reggie.utils.SendEmailUtils;
|
||||||
|
import cn.czyx007.reggie.utils.ValidateCodeUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
@ -39,12 +41,12 @@ public class UserController {
|
|||||||
String phone = user.getPhone();
|
String phone = user.getPhone();
|
||||||
if (StringUtils.hasLength(phone)) {
|
if (StringUtils.hasLength(phone)) {
|
||||||
//生成随机的4位验证码
|
//生成随机的4位验证码
|
||||||
//String code = ValidateCodeUtils.generateValidateCode4String(4);
|
String code = ValidateCodeUtils.generateValidateCode4String(4);
|
||||||
//发送邮件验证码
|
//发送邮件验证码
|
||||||
//SendEmailUtils.sendAuthCodeEmail(phone, code);
|
SendEmailUtils.sendAuthCodeEmail(phone, code);
|
||||||
//将生成的验证码保存到Redis用于校验,并且设置有效期为5分钟
|
//将生成的验证码保存到Redis用于校验,并且设置有效期为5分钟
|
||||||
// redisTemplate.opsForValue().set(phone, code, 5, TimeUnit.MINUTES);
|
redisTemplate.opsForValue().set(phone, code, 5, TimeUnit.MINUTES);
|
||||||
redisTemplate.opsForValue().set(phone, "1234", 5, TimeUnit.MINUTES);
|
// redisTemplate.opsForValue().set(phone, "1234", 5, TimeUnit.MINUTES);
|
||||||
return R.success("验证码发送成功");
|
return R.success("验证码发送成功");
|
||||||
}
|
}
|
||||||
return R.error("验证码发送失败");
|
return R.error("验证码发送失败");
|
||||||
@ -59,7 +61,7 @@ public class UserController {
|
|||||||
//从Redis中获取保存的验证码
|
//从Redis中获取保存的验证码
|
||||||
String codeInRedis = redisTemplate.opsForValue().get(phone);
|
String codeInRedis = redisTemplate.opsForValue().get(phone);
|
||||||
|
|
||||||
codeInRedis = "1234";
|
//codeInRedis = "1234";
|
||||||
|
|
||||||
//将两个验证码进行比对
|
//将两个验证码进行比对
|
||||||
if(StringUtils.hasLength(codeInRedis) && codeInRedis.equals(code)){
|
if(StringUtils.hasLength(codeInRedis) && codeInRedis.equals(code)){
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package cn.czyx007.reggie.filter;
|
package cn.czyx007.reggie.filter;
|
||||||
|
|
||||||
import cn.czyx007.reggie.bean.Employee;
|
|
||||||
import cn.czyx007.reggie.common.BaseContext;
|
import cn.czyx007.reggie.common.BaseContext;
|
||||||
import cn.czyx007.reggie.common.R;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import org.springframework.boot.json.JacksonJsonParser;
|
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.*;
|
||||||
@ -21,8 +17,8 @@ import java.io.IOException;
|
|||||||
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
|
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
|
||||||
public class LoginCheckFilter implements Filter {
|
public class LoginCheckFilter implements Filter {
|
||||||
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
|
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
|
||||||
public static final String[] urls = {"/employee/login", "/employee/logout", "/backend/**", "/front/**",
|
private static final String[] urls = {"/employee/login", "/employee/logout", "/backend/**", "/front/**",
|
||||||
"/user/sendMsg", "/user/login"};
|
"/user/sendMsg", "/user/login", "/doc.html", "/webjars/**", "/swagger-resources", "/v2/api-docs"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
|
||||||
@ -59,6 +55,10 @@ public class LoginCheckFilter implements Filter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));
|
// response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));
|
||||||
|
response.setContentType("text/html;charset=UTF-8");
|
||||||
|
response.getWriter().write("未登录!请先跳转以下页面登录<br>\n" +
|
||||||
|
"<a href=\"http://reggie.czyx007.cn/backend/page/login/login.html\">后台页面跳转</a><br>\n" +
|
||||||
|
"<a href=\"http://reggie.czyx007.cn/front/page/login.html\">用户页面跳转</a>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
if (regex.test(this.form.phone)) {
|
if (regex.test(this.form.phone)) {
|
||||||
this.msgFlag = false
|
this.msgFlag = false
|
||||||
//this.form.code = (Math.random()*1000000).toFixed(0)
|
//this.form.code = (Math.random()*1000000).toFixed(0)
|
||||||
this.form.code = '1234'
|
//this.form.code = '1234'
|
||||||
sendMsgApi({phone:this.form.phone})
|
sendMsgApi({phone:this.form.phone})
|
||||||
}else{
|
}else{
|
||||||
this.msgFlag = true
|
this.msgFlag = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user