当前位置:网站首页>抖音实战~手机号密码一键注册登录流程(限制手机终端登录)
抖音实战~手机号密码一键注册登录流程(限制手机终端登录)
2022-06-23 22:20:00 【gblfy】



一、手机号+密码

二、前端
2.1. 点击登陆流程
- 1.先校验手机号是否合法?不合法,则提示“请输入正确的手机号”
- 2.再校验是否勾选隐私协议,未勾选,则提示“请先同意《隐私及服务协议》”
- 3.校验通过后,根据选择的登录类型进行判断,最后,则调用后端手机号验证码登录接口
- 4.后端返回结果
- 4.1.成功,则保存用户信息+token信息
- 4.2.失败:则提示后端返回的提示语
2.2. 点击登录源码
loginOrRegist() {
var me = this;
var mobile = me.mobile;
// 提交前,手机号校验
var reg = /^1[0-9]{
10,10}$/;
if (!mobile || !reg.test(mobile)) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
return
}
if (!this.agree) {
uni.showToast({
title: '请先同意《隐私及服务协议》',
icon: 'none'
});
return;
}
var serverUrl = app.globalData.serverUrl;
// 手机号密码~登录/注册
if (!this.logintype) {
var password = me.password;
if (app.isStrEmpty(password)) {
uni.showToast({
title: "密码不能为空",
icon: "none"
});
return;
}
// uni.showLoading()
// 调用后端登录注册
uni.request({
method: "POST",
url: serverUrl + "/user/mobileAndPasswordRegistLogin",
data: {
"mobile": mobile,
"password": password
},
success(result) {
var status = result.data.status;
// uni.hideLoading();
if (status == 200) {
var userInfo = result.data.data;
console.log("密码->userInfo", userInfo)
app.setUserInfoSession(userInfo);
app.setUserSessionToken(userInfo.userToken);
// 登录成功,关闭当前页
// me.close();
uni.reLaunch({
url: "../me/me"
})
} else if (status != 200) {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
}
// 手机号验证码~登录/注册
if (this.logintype) {
var verifyCode = me.verifyCode;
console.log("verifyCode", verifyCode)
if (app.isStrEmpty(verifyCode)) {
uni.showToast({
title: "请填写验证码",
icon: "none"
});
return;
}
// 调用后端登录注册
uni.request({
method: "POST",
url: serverUrl + "/user/login",
data: {
"mobile": mobile,
"smsCode": verifyCode
},
success(result) {
var status = result.data.status;
// uni.hideLoading();
if (status == 200) {
var userInfo = result.data.data;
console.log("验证码->userInfo", userInfo)
app.setUserInfoSession(userInfo);
app.setUserSessionToken(userInfo.userToken);
// 登录成功,关闭当前页
// me.close();
uni.reLaunch({
url: "../me/me"
})
} else if (status != 200) {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
}
}
三、后端登录
3.1. 登录流程图
会话拦截限制一台手机登录(流程图)
3.2. 流程简述
- 1.前端传递userId和token
- 2.后端接收userId和token
- 3.校验userId和token是否为空
- 4.校验任一为空,则提示“请登录后再继续操作!”
- 5.不为空,通过UserId从redis中获取token
- 6.redis中的token与传参token校验是否一致
- 7.不一致,第一台登录的会“会话失效,请重新登录!”
- 8.一致继续操作
备注:由于登录不拦截,因此当第二台手机登录时,token会将第一台手机的登录token进行覆盖


3.3. 手机号验证码登录流程
- 1.查询数据库,判断用户是否存在
- 1.1 如果用户为空,表示没有注册过,则为null,需要注册信息入库(md5+盐值)
- 1.2 如果用户不为空,表示已经注册过
- 1.2.1.根据手机号获取加密盐值
- 1.2.2.前端密码+加密盐值md5加密
- 1.2.3.加密密码和数据库密码比对,不一致,则提示“用户或密码有误!”;一致,则继续。
- 2.保存用户会话信息到redis
- 3.回用户信息,包含token令牌
/**
* 账号密码一键登录注册
*
* @param mobileAndPasswordRegistLoginBO
* @param request
* @return
* @throws Exception
*/
@PostMapping("mobileAndPasswordRegistLogin")
public GraceJSONResult mobiletAndPasswordRegistLogin(@Valid @RequestBody MobileAndPasswordRegistLoginBO mobileAndPasswordRegistLoginBO,
HttpServletRequest request) throws Exception {
String mobile = mobileAndPasswordRegistLoginBO.getMobile();
String password = mobileAndPasswordRegistLoginBO.getPassword();
// 1.查询数据库,判断用户是否存在
Users user = userService.queryMobileIsExist(mobile);
//当用户和密码不为空时,进行密码判断
if (user != null && StringUtils.isNotBlank(password)) {
if (!MD5Utils.comparePasswordsForEquality(user.getSalt(), user.getPassword(), password)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.ERROR_MOBILE_OR_PASSWORD);
}
}
//用户不存在则,新增用户信息
if (user == null) {
// 如果用户为空,表示没有注册过,则为null,需要注册信息入库
user = userService.createUser(mobile, password);
}
// 2. 如果不为空,可以继续下方业务,可以保存用户会话信息
String uToken = UUID.randomUUID().toString();
redis.set(REDIS_USER_TOKEN + ":" + user.getId(), uToken);
// 3.返回用户信息,包含token令牌
UsersVO usersVO = new UsersVO();
BeanUtils.copyProperties(user, usersVO);
usersVO.setUserToken(uToken);
return GraceJSONResult.ok(usersVO);
}
边栏推荐
- == 和 equals 的区别是什么?
- 工作中一些常用的工具函数
- fatal: The upstream branch of your current branch does not match the name of your current branch.
- Generate all possible binary search trees
- 【Bug】C# IQueryable里的元素更改不了值
- 迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......
- How to achieve energy-saving and reasonable lighting control in order to achieve the "double carbon" goal
- 格林公式挖洞法中内曲线顺时针的直观解释
- Nice input edit box
- PMP考试相关计算公式汇总!考前必看
猜你喜欢

Tupu software intelligent wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment

如何入门机器学习?

2.摄像机标定

SAVE: 软件分析验证和测试平台

Quantitative investment model -- research interpretation of high frequency trading market making model (Avellaneda & Stoikov's) & code resources

2018/gan:self attention generating adversarial networks
![Restore IP address [standard backtracking + standard pruning]](/img/e6/5f9d2a5af973b6c7051ed434a4b93d.png)
Restore IP address [standard backtracking + standard pruning]

抖音实战~密码找回

Solve the problem of project dependency red reporting

Smart doc + Torna compatible version
随机推荐
Web site SSL certificate
Smart doc + Torna compatible version
2. camera calibration
迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......
How to ensure reliable power supply of Expressway
微信小程序中three.js的canvas非全屏情况下射线检测不准确问题解决方案
Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?
产线工控安全有什么好的解决方案
数字物业管理成趋势,传统物业公司如何通过转型实现数字化蝶变?
生成所有可能的二叉搜索树
《德阳市餐饮服务业油烟污染防治管理办法(征求意见稿)》之创新油烟监管
extern、struct等关键字
医疗是什么?AI医疗概念解析AI
依赖倒置原则
matlab实现对图像批量重命名
被同事坑到周末加班, 没见过把Redis用成这个鬼样子的。。。
Leetcode - linked list written test questions
【Bug】C# IQueryable里的元素更改不了值
Another short video app with high imitation and eye opening
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)