当前位置:网站首页>抖音实战~密码找回
抖音实战~密码找回
2022-06-23 22:20:00 【gblfy】

1. 密码找回流程图

2. 前端源码
/**
* 密码找回
*/
updatePassword() {
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;
// 密码找回
var password = me.password;
if (app.isStrEmpty(password)) {
uni.showToast({
title: "新密码不能为空",
icon: "none"
});
return;
}
console.log("forgotPassword")
// uni.showLoading()
// 调用后端登录注册
uni.request({
method: "POST",
url: serverUrl + "/user/forgotPassword",
data: {
"mobile": mobile,
"smsCode": me.verifyCode,
"newPassword": password
},
success(result) {
console.log("result", result)
var status = result.data.status;
if (status != 200) {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
if (status == 200) {
uni.navigateTo({
url: '../loginRegist/loginRegist'
})
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
// 登录成功,跳转登录页,关闭当前页
}
}
});
}
3. 后端
/**
* 重置密码
*
* @param forgotPasswordBO 手机号 + 验证码+新密码
*/
@PostMapping("forgotPassword")
public GraceJSONResult forgotPassword(@Valid @RequestBody ForgotPasswordBO forgotPasswordBO,
HttpServletRequest request) {
String mobile = forgotPasswordBO.getMobile();
String code = forgotPasswordBO.getSmsCode();
String newPassword = forgotPasswordBO.getNewPassword();
// 1. 从redis中获得验证码进行校验是否匹配
String redisCode = redis.get(MOBILE_SMSCODE + ":" + mobile);
if (StringUtils.isBlank(redisCode) || !redisCode.equalsIgnoreCase(code)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.SMS_CODE_ERROR);
}
// 2. 查询数据库,判断用户是否存在
Users user = userService.queryMobileIsExist(mobile);
if (user == null) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.ACCOUNT_NOT_EXIST);
}
this.userService.forgotPassword(mobile, newPassword);
//重置密码成功,将验证码删除
redis.del(MOBILE_SMSCODE + ":" + mobile);
return GraceJSONResult.ok(ResponseStatusEnum.RESET_PASSWORD_SUCCESS);
}
拦截器放过

边栏推荐
猜你喜欢

Golang type assertion

Notepad++ practical function sharing (common methods for replacing the end and beginning of regular lines, text comparison function, etc.)

extern、struct等关键字

数据库中索引原理及填充因子

How to achieve the turning effect of wechat video recording?

Generate all possible binary search trees

CVPR2019/图像翻译:TransGaGa: Geometry-Aware Unsupervised Image-to-Image Translation几何感知的无监督图像到图像的翻译

医疗是什么?AI医疗概念解析AI

6 大完整开源项目,一次学个够

Cvpr2019/ image translation: transgaga: geometry aware unsupervised image to image translation
随机推荐
格林公式挖洞法中内曲线顺时针的直观解释
docker redis集群配置
Le roman du drapeau de l'imitation haute version flutter, apprenez - le
2018/GAN:Self-Attention Generative Adversarial Networks自我注意生成对抗网络
Improvement of DC power distribution with open hall current sensor
开口式霍尔电流传感器助力直流配电改造
一个人竟然撸了一个网易云音乐云村
Taylor formula and common expansion
完整开源项目之诗词吧 APP
Docker Deployment redis
1004. number of maximum consecutive 1 III ●●
医疗是什么?AI医疗概念解析AI
Different objects use the same material and have different performances
Idea automatically generates unit tests, doubling efficiency!
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format
Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
Six necessary open source projects for private activities
Classical Chinese can be programmed???
mcu常用寄存器位操作方式汇总
点乘和叉乘