public virtual async Task ResetPasswordAsync(PhoneResetPasswordDto input)
        {
            var securityTokenCacheKey  = SmsSecurityTokenCacheItem.CalculateCacheKey(input.PhoneNumber, "SmsVerifyCode");
            var securityTokenCacheItem = await SecurityTokenCache.GetAsync(securityTokenCacheKey);

            if (securityTokenCacheItem == null)
            {
                throw new UserFriendlyException(L["InvalidSmsVerifyCode"]);
            }
            // 传递 isConfirmed 用户必须是已确认过手机号的
            var user = await GetUserByPhoneNumberAsync(input.PhoneNumber, isConfirmed : true);

            // 验证二次认证码
            if (!await UserManager.VerifyTwoFactorTokenAsync(user, TokenOptions.DefaultPhoneProvider, input.Code))
            {
                // 验证码无效
                throw new UserFriendlyException(L["InvalidSmsVerifyCode"]);
            }
            // 生成真正的重置密码Token
            var resetPwdToken = await UserManager.GeneratePasswordResetTokenAsync(user);

            // 重置密码
            (await UserManager.ResetPasswordAsync(user, resetPwdToken, input.NewPassword)).CheckErrors();
            // 移除缓存项
            await SecurityTokenCache.RemoveAsync(securityTokenCacheKey);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
コード例 #2
0
 public virtual async Task ResetPasswordAsync(PhoneResetPasswordDto input)
 {
     await AccountAppService.ResetPasswordAsync(input);
 }