认证服务
一、初始化
- 统一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);
}
}
- 拉入登录页面,将资料高级篇登录页面和注册页面放到 templates 下,并改名为login、reg.html
- 为了测试直接访问登录页,把login.html改名为index.html
- C:\Windows\System32\drivers\etc\hosts,添加本地域名映射
192.168.109.101 auth.achangmall.com
- id: auth_route
uri: lb://achang-auth-server
predicates:
- Host=auth.achangmall.com
- 启动网关服务AchangmallGatewayApplication +AchangAuthServerApplication 测试转发效果
访问http://auth.achangmall.com/ ,访问成功!!!
- 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");
}
}
|