- 登录需求
- 登录实现
- 添加用户基础类
- JWT生成token
- 搭建service-msm模块
1,登录采取弹出层的形式
2,登录方式:
(1)手机号码+手机验证码
(2)微信扫描
3,无注册界面,第一次登录根据手机号判断系统是否存在,如果不存在则自动注册
4,微信扫描登录成功必须绑定手机号码,即:第一次扫描成功后绑定手机号,以后登录扫描直接登录成功
5,网关统一判断登录状态,如何需要登录,页面弹出登录层
1,搭建service-user模块
1.1 搭建service-user模块
搭建过程参考service-hosp模块
1.2 修改配置
1、修改pom.xml
service com.atguigu 0.0.1-SNAPSHOT 4.0.0 service_user com.atguigu service_cmn_client 0.0.1-SNAPSHOT
2、添加配置文件application.properties
# 服务端口 server.port=8203 # 服务名 spring.application.name=service-user # 环境设置:dev、test、prod spring.profiles.active=dev # mysql数据库连接 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://192.168.44.165:3306/yygh_user?characterEncoding=utf-8&useSSL=false spring.datasource.username=root spring.datasource.password=root123 #返回json的全局时间格式 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8 # nacos服务地址 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 #配置mapper xml文件的路径 mybatis-plus.mapper-locations=classpath:com/atguigu/yygh/user/mapper/xml/*.xml
1.3 启动类
@SpringBootApplication
@ComponentScan(basePackages = "com.atguigu")
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.atguigu")
public class ServiceUserApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceUserApplication.class, args);
}
}
1.4配置网关
#设置路由id
spring.cloud.gateway.routes[2].id=service-user
#设置路由的uri
spring.cloud.gateway.routes[2].uri=lb://service-user
#设置路由断言,代理servicerId为auth-service的/auth/路径
spring.cloud.gateway.routes[2].predicates= Path=/*/usermsm
public static ArrayList getRandom(List list, int n) {
Random random = new Random();
HashMap
6.3.4 完善登录service接口
修改UserInfoServiceImpl类登录方法,编写验证码校验
//校验校验验证码
String mobleCode = redisTemplate.opsForValue().get(phone);
if(!code.equals(mobleCode)) {
throw new YyghException(ResultCodeEnum.CODE_ERROR);
}



