MVC 웹 응용 프로그램에 암호 재설정 기능을 추가하려고합니다.토큰이 ASP.NET의 암호 재설정시 유효하지 않습니다.
전자 메일 주소를 입력하고 양식을 제출할 때 토큰 등이 들어있는 전자 메일을 받으면 재설정 된 암호 페이지로 리디렉션 된 링크를 클릭하면 전자 메일 주소를 입력합니다. 메일과 새 암호를 입력하면 재설정 버튼을 누르면 resetPassword 액션에서 다음 오류가 발생합니다.
"잘못된 토큰".
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null)
{
// Don't reveal that the user does not exist
return RedirectToAction("ResetPasswordConfirmation", "Account");
}
var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);
if (result.Succeeded)
{
return RedirectToAction("ResetPasswordConfirmation", "Account");
}
AddErrors(result);
return View();
}
그리고 내 ForgotPassword 방법 :
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null)
{
// Don't reveal that the user does not exist or is not confirmed
return View("ForgotPasswordConfirmation");
}
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
var emailTemplateQuery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "forgotpassword").SelectAsync();
var emailTemplate = emailTemplateQuery.Single();
dynamic email = new Postal.Email("Email");
email.To = user.Email;
email.From = CacheHelper.Settings.EmailAddress;
email.Subject = emailTemplate.Subject;
email.Body = emailTemplate.Body;
email.CallbackUrl = callbackUrl;
EmailHelper.SendEmail(email);
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
ForgotPassword.cshtml 파일 :
<div class="panel-body">
@using (Html.BeginForm("ForgotPassword", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>[[[Enter your email.]]]</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="[[[Email Link]]]" />
</div>
</div>
}
</div>
ForgotPasswordConfirmation.cshtml 파일 :
<div class="panel-body">
<div>
<p>
[[[Please check your email to reset your password.]]]
</p>
</div>
</div>
ResetPassword ViewModel :
public class ResetPasswordViewModel
{
[Required]
[EmailAddress]
[Display(Name = "[[[Email]]]")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "[[[The {0} must be at least {2} characters long.]]]", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "[[[Password]]]")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "[[[Confirm password]]]")]
[Compare("Password", ErrorMessage = "[[[The password and confirmation password do not match.]]]")]
public string ConfirmPassword { get; set; }
public string Code { get; set; }
}
당신이 당신의보기 모델 + 전체 오류 로그를 추가 할 수 있습니까? –
그것은 asp.net MVC 5입니까? – Anil
네, Mvc 5 –