• 抖音实战~密码找回


    在这里插入图片描述

    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
    							});
    							// 登录成功,跳转登录页,关闭当前页
    						}
    					}
    				});
    			}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    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);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    拦截器放过

    在这里插入图片描述

  • 相关阅读:
    React常用开源组件①
    Python脚本一键给多个视频批量添加片头
    shell脚本的多线程介绍
    创建个人中心页面
    LeetCode 110.平衡二叉树 (C++)
    C++线程库的基本使用(初级)
    社招前端一面经典手写面试题集锦
    SpringSecurity中注解讲解
    Word控件Spire.Doc 【图像形状】教程(7): 如何使用 C# 在 Word 中替换图像
    理解并掌握C#的Channel:从使用案例到源码解读(一)
  • 原文地址:https://blog.csdn.net/weixin_40816738/article/details/125431889