示例#1
0
        public async Task <Result> ForgotPasswordSendPhone([FromBody] ResetPasswordPostParam param)
        {
            var user = await _userManager.FindByNameAsync(param.UserName);

            if (user == null)
            {
                throw new Exception("用户不存在");
            }
            if (!user.IsActive)
            {
                throw new Exception("用户已禁用");
            }
            if (string.IsNullOrWhiteSpace(user.PhoneNumber))
            {
                throw new Exception("用户未绑定手机,无法通过手机找回密码");
            }

            var code   = CodeGen.GenRandomNumber();
            var result = await _smsSender.SendCaptchaAsync(user.PhoneNumber, code);

            if (!result.Success)
            {
                return(Result.Fail(result.Message));
            }
            return(Result.Ok());
        }
示例#2
0
        public async Task <Result> ForgotPasswordSendEmail([FromBody] ResetPasswordPostParam param)
        {
            var user = await _userManager.FindByNameAsync(param.UserName);

            if (user == null)
            {
                throw new Exception("用户不存在");
            }
            if (!user.IsActive)
            {
                throw new Exception("用户已禁用");
            }
            if (string.IsNullOrWhiteSpace(user.Email))
            {
                throw new Exception("用户未绑定邮箱,无法通过邮箱找回密码");
            }

            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
            // Send an email with this link
            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = $"{_webHost.Trim('/')}/user/reset-password?userName={user.UserName}&email={StringHelper.EmailEncryption(user.Email)}&code={HttpUtility.UrlEncode(code)}";
            await _jobService.Enqueue(() => _emailSender.SendEmailAsync(user.Email, "Reset Password",
                                                                        $"Please reset your password by clicking here: <a href='{callbackUrl}'>REST PASSWORD</a>", true));

            return(Result.Ok());
        }