当前位置:网站首页>Tiktok practice ~ one click registration and login process of mobile phone number and password (restrict mobile terminal login)
Tiktok practice ~ one click registration and login process of mobile phone number and password (restrict mobile terminal login)
2022-06-24 00:09:00 【gblfy】



List of articles
One 、 cell-phone number + password

Two 、 front end
2.1. Click login process
- 1. First verify whether the mobile phone number is legal ? illegal , Prompt “ Please input the correct mobile number ”
- 2. Verify whether the privacy agreement is checked , Uncheck , Prompt “ Please agree first 《 Privacy and service agreement 》”
- 3. After the verification is passed , Judge according to the selected login type , Last , Then call the backend mobile number verification code login interface
- 4. The back end returns the result
- 4.1. success , Save the user information +token Information
- 4.2. Failure : Prompt the prompt returned by the backend
2.2. Click to log in to the source code
loginOrRegist() {
var me = this;
var mobile = me.mobile;
// Before submission , Cell phone number verification
var reg = /^1[0-9]{
10,10}$/;
if (!mobile || !reg.test(mobile)) {
uni.showToast({
title: ' Please input the correct mobile number ',
icon: 'none'
})
return
}
if (!this.agree) {
uni.showToast({
title: ' Please agree first 《 Privacy and service agreement 》',
icon: 'none'
});
return;
}
var serverUrl = app.globalData.serverUrl;
// Mobile phone number and password ~ Sign in / register
if (!this.logintype) {
var password = me.password;
if (app.isStrEmpty(password)) {
uni.showToast({
title: " The password cannot be empty ",
icon: "none"
});
return;
}
// uni.showLoading()
// Call back-end login registration
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(" password ->userInfo", userInfo)
app.setUserInfoSession(userInfo);
app.setUserSessionToken(userInfo.userToken);
// Login successful , Close current page
// me.close();
uni.reLaunch({
url: "../me/me"
})
} else if (status != 200) {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
}
// Mobile phone number verification code ~ Sign in / register
if (this.logintype) {
var verifyCode = me.verifyCode;
console.log("verifyCode", verifyCode)
if (app.isStrEmpty(verifyCode)) {
uni.showToast({
title: " Please fill in the verification code ",
icon: "none"
});
return;
}
// Call back-end login registration
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(" Verification Code ->userInfo", userInfo)
app.setUserInfoSession(userInfo);
app.setUserSessionToken(userInfo.userToken);
// Login successful , Close current page
// me.close();
uni.reLaunch({
url: "../me/me"
})
} else if (status != 200) {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
}
}
3、 ... and 、 Back end login
3.1. Login flowchart
Session interception restricts the login of one mobile phone ( flow chart )
3.2. Process brief
- 1. Front end delivery userId and token
- 2. Back end reception userId and token
- 3. check userId and token Is it empty
- 4. Verify that any one is empty , Prompt “ Please log in and continue !”
- 5. Not empty , adopt UserId from redis In order to get token
- 6.redis Medium token And Chuan Shen token Check for consistency
- 7. atypism , The first one to log in will “ Session failure , Please login again !”
- 8. Continue operation consistently
remarks : Because login is not blocked , So when the second phone logs in ,token Will log in the first mobile phone token To cover


3.3. Mobile number verification code login process
- 1. Query the database , Judge whether the user exists
- 1.1 If the user is empty , Indicates that you have not registered , Then for null, The registration information needs to be stored (md5+ Salt value )
- 1.2 If the user is not empty , Indicates that you have registered
- 1.2.1. Obtain the encrypted salt value according to the mobile phone number
- 1.2.2. Front end password + Encryption salt value md5 encryption
- 1.2.3. Encryption password and database password comparison , atypism , Prompt “ Incorrect user or password !”; Agreement , Continued to .
- 2. Save user session information to redis
- 3. Return user information , contain token token
/**
* One click login with account and password
*
* @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. Query the database , Judge whether the user exists
Users user = userService.queryMobileIsExist(mobile);
// When the user and password are not empty , Make password judgment
if (user != null && StringUtils.isNotBlank(password)) {
if (!MD5Utils.comparePasswordsForEquality(user.getSalt(), user.getPassword(), password)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.ERROR_MOBILE_OR_PASSWORD);
}
}
// If the user does not exist , New user information
if (user == null) {
// If the user is empty , Indicates that you have not registered , Then for null, The registration information needs to be stored
user = userService.createUser(mobile, password);
}
// 2. If it's not empty , You can continue the business below , User session information can be saved
String uToken = UUID.randomUUID().toString();
redis.set(REDIS_USER_TOKEN + ":" + user.getId(), uToken);
// 3. Return user information , contain token token
UsersVO usersVO = new UsersVO();
BeanUtils.copyProperties(user, usersVO);
usersVO.setUserToken(uToken);
return GraceJSONResult.ok(usersVO);
}
边栏推荐
- Basic usage of oushudb database (medium)
- Principles and differences between hash and history
- 测试 - 用例篇 - 细节狂魔
- 迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......
- Learn PWN from CTF wiki - ret2text
- EasyCVR程序以服务启动异常,进程启动却正常,是什么原因?
- docker 部署redis
- [interview experience package] summary of experience of being hanged during interview (I)
- windows10安全模式进入循环蓝屏修复
- 混沌工程,了解一下
猜你喜欢

Docker redis cluster configuration

extern、struct等关键字

Complete open source project poetry bar app

Another short video app with high imitation and eye opening

测试 - 用例篇 - 细节狂魔

依赖倒置原则

Confused test / development programmers, different people have different stories and different puzzles

Revit API: schedule viewschedule

985本3Android程序员40天拿下阿里P6口头offer,面试成功后整理了这些面试思路

Test - use case - detail frenzy
随机推荐
[bug] the element in C iqueryable cannot change its value
超标量处理器设计 姚永斌 第3章 虚拟存储器 --3.1~3.2 小节摘录
2. camera calibration
Don't miss | Huawei's internal data - Successful Project Management PPT (page 123)
js 语言 精度问题
Jimureport building block report - table linkage chart topic
Basic usage of oushudb database (medium)
Detailed process from CPU fetching to sending control and microprogram control principle
测试 - 用例篇 - 细节狂魔
Synthetic big watermelon games wechat applet source code / wechat game applet source code
如何利用數倉創建時序錶
Android App bundle exploration, client development interview questions
微信小程序中three.js的canvas非全屏情况下射线检测不准确问题解决方案
How to use data warehouse to create time series
Do280openshift access control -- manage projects and accounts
逻辑的定义
Total number of combinations ii[each element can only be solved by + once]
Complete open source project poetry bar app
985本3Android程序员40天拿下阿里P6口头offer,面试成功后整理了这些面试思路
Recommend 4 flutter heavy open source projects