认证服务
一、初始化
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2X13xOiM-1634396228713)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016211306992.png)]](https://img-blog.csdnimg.cn/dfa79f532eef452688779b1232ad4f37.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_18,color_FFFFFF,t_70,g_se,x_16)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oIWVYnkX-1634396228715)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016211424288.png)]](https://img-blog.csdnimg.cn/e3047973f1c5462c8eac00f8e83ac8ef.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_20,color_FFFFFF,t_70,g_se,x_16)
- 统一springboot版本
2.2.1.RELEASE ,并引入Common服务依赖,因为不操作数据库,所以排除mybaitsplus依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
</properties>
<dependency>
<groupId>com.achang.achangmall</groupId>
<artifactId>achangmall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
spring.application.name=achang-auth-server
spring.cloud.nacos.server-addr=127.0.0.1:8848
server.port=20000
spring.thymeleaf.cache=false
- com.achang.achangmall.auth.AchangAuthServerApplication
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class AchangAuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(AchangAuthServerApplication.class, args);
}
}
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dlA3Cwnw-1634396228717)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016212619429.png)]](https://img-blog.csdnimg.cn/067772c47b894d13b62d80d974915360.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_20,color_FFFFFF,t_70,g_se,x_16)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EqYAPVS9-1634396228720)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016212640220.png)]](https://img-blog.csdnimg.cn/437306d605c243b98403b4ca38fb882d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_20,color_FFFFFF,t_70,g_se,x_16)
- 拉入登录页面,将资料高级篇登录页面和注册页面放到 templates 下,并改名为login、reg.html
- 为了测试直接访问登录页,把login.html改名为index.html
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vbmpRH2k-1634396228721)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016220636486.png)]](https://img-blog.csdnimg.cn/4ec39e8446764b8288fc71f7bd4cc509.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_10,color_FFFFFF,t_70,g_se,x_16)
- C:\Windows\System32\drivers\etc\hosts,添加本地域名映射
192.168.109.101 auth.achangmall.com
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bzacnjcQ-1634396228726)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016214303159.png)]](https://img-blog.csdnimg.cn/61265a1f19eb405da09878217cbeef48.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-11tfs3Qd-1634396228729)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016215151482.png)]](https://img-blog.csdnimg.cn/5be0348f255a43e1ba012c87566ec1e8.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_10,color_FFFFFF,t_70,g_se,x_16)
- id: auth_route
uri: lb://achang-auth-server
predicates:
- Host=auth.achangmall.com
- 启动网关服务AchangmallGatewayApplication +AchangAuthServerApplication 测试转发效果
访问http://auth.achangmall.com/ ,访问成功!!!
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-95pmxVvH-1634396228731)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016220650202.png)]](https://img-blog.csdnimg.cn/65a5a11051ad4c139a9a0d1d9bdfab61.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_20,color_FFFFFF,t_70,g_se,x_16)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8KdRQaHy-1634396228733)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20211016222147788.png)]](https://img-blog.csdnimg.cn/cf8eed1e5fec4fb9a607adb68ee74b65.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Zi_5piM5Zac5qyi5ZCD6buE5qGD,size_20,color_FFFFFF,t_70,g_se,x_16)
- com.achang.achangmall.auth.controller.LoginController
@Controller
public class LoginController {
@GetMapping("/login.html")
public String loginPage(){
return "login";
}
@GetMapping("/reg.html")
public String register(){
return "reg";
}
}

二、短信验证码
<a id="sendCode">发送验证码</a>
$(function (){
$("#sendCode").click(function (){
if ($(this).hasClass("disabled")){
}{
timeoutChangeSytle()
}
});
})
var num = 60;
function timeoutChangeSytle(){
$("#sendCode").attr("class","disabled")
if (num==0){
$("#sendCode").text("发送验证码")
num = 60;
$("#sendCode").attr("class","")
}else {
var str = num+"后再次发送"
$("#sendCode").text(str)
setTimeout("timeoutChangeSytle()",1000)
}
num--;
}
com.achang.achangmall.auth.conf.AchangWebConfig
@Configuration
public class AchangWebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login.html").setViewName("login");
registry.addViewController("/reg.html").setViewName("reg");
}
}
|