/// <summary> /// 通过邮箱验证码重置密码 /// </summary> /// <param name="email">邮箱</param> /// <param name="code">验证码</param> /// <param name="newPassword">新密码</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommonMessage> ResetPasswordByEmailCode( string email, string code, string newPassword, CancellationToken cancellationToken = default) { var param = new ResetPasswordParam(code, Encrypt(newPassword)) { Email = email, }; var res = await Request <ResetPasswordResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }
/// <summary> /// Sets the new password for the user idenfied by the secure Ticket. /// </summary> /// <param name="resetPasswordParam">Service call params <see cref="ResetPasswordParam"/></param> /// <returns> /// The updated Customer and a status representing a possible cause of errors /// </returns> public virtual async Task <ResetPasswordViewModel> ResetPasswordAsync(ResetPasswordParam resetPasswordParam) { if (resetPasswordParam == null) { throw new ArgumentNullException("resetPasswordParam"); } if (string.IsNullOrWhiteSpace(resetPasswordParam.Ticket)) { throw new ArgumentException("resetPasswordParam.Ticket"); } if (resetPasswordParam.CultureInfo == null) { throw new ArgumentException("resetPasswordParam.CultureInfo"); } if (string.IsNullOrWhiteSpace(resetPasswordParam.Scope)) { throw new ArgumentException("resetPasswordParam.Scope"); } if (string.IsNullOrWhiteSpace(resetPasswordParam.NewPassword)) { throw new ArgumentException("resetPasswordParam.NewPassword"); } if (string.IsNullOrWhiteSpace(resetPasswordParam.PasswordAnswer) && MembershipProvider.RequiresQuestionAndAnswer) { throw new ArgumentException("resetPasswordParam.PasswordAnswer"); } var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl( new BaseUrlParameter { CultureInfo = resetPasswordParam.CultureInfo }); var customer = await CustomerRepository.GetCustomerByTicketAsync(resetPasswordParam.Ticket).ConfigureAwait(false); await CustomerRepository.ResetPasswordAsync( customer.Username, resetPasswordParam.Scope, resetPasswordParam.NewPassword, resetPasswordParam.PasswordAnswer).ConfigureAwait(false); return(GetResetPasswordViewModel(new GetResetPasswordViewModelParam { ReturnUrl = resetPasswordParam.ReturnUrl, Status = MyAccountStatus.Success, Customer = customer, CultureInfo = resetPasswordParam.CultureInfo, ForgotPasswordUrl = forgotPasswordUrl })); }
/// <summary> /// 通过手机号验证码重置密码 /// </summary> /// <param name="phone">手机号</param> /// <param name="code">验证码</param> /// <param name="newPassword">新密码</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task<CommonMessage> ResetPasswordByPhoneCode( string phone, string code, string newPassword, CancellationToken cancellationToken = default) { var param = new ResetPasswordParam() { Phone = phone, Code = code, NewPassword = Encrypt(newPassword), }; var res = await Request<ResetPasswordResponse>(param.CreateRequest(), cancellationToken); return res.Result; }