|
19 | 19 | using StsServerIdentity.Resources; |
20 | 20 | using System.Reflection; |
21 | 21 | using Microsoft.AspNetCore.Authentication; |
| 22 | +using Microsoft.AspNetCore.WebUtilities; |
| 23 | +using System.Text; |
| 24 | +using System.Text.Encodings.Web; |
22 | 25 |
|
23 | 26 | namespace StsServerIdentity.Controllers |
24 | 27 | { |
@@ -266,9 +269,10 @@ public async Task<IActionResult> Register(RegisterViewModel model, string return |
266 | 269 | if (result.Succeeded) |
267 | 270 | { |
268 | 271 | //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); |
| 272 | + // WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); |
269 | 273 | //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); |
270 | 274 | //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", |
271 | | - // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); |
| 275 | + // $"Please confirm your account by clicking this link: <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>link</a>"); |
272 | 276 | //await _signInManager.SignInAsync(user, isPersistent: false); |
273 | 277 | //_logger.LogInformation(3, "User created a new account with password."); |
274 | 278 | return RedirectToLocal(returnUrl); |
@@ -408,6 +412,7 @@ public async Task<IActionResult> ConfirmEmail(string userId, string code) |
408 | 412 | { |
409 | 413 | return View("Error"); |
410 | 414 | } |
| 415 | + code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); |
411 | 416 | var result = await _userManager.ConfirmEmailAsync(user, code); |
412 | 417 | return View(result.Succeeded ? "ConfirmEmail" : "Error"); |
413 | 418 | } |
@@ -442,11 +447,12 @@ public async Task<IActionResult> ForgotPassword(ForgotPasswordViewModel model) |
442 | 447 | // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 |
443 | 448 | // Send an email with this link |
444 | 449 | var code = await _userManager.GeneratePasswordResetTokenAsync(user); |
| 450 | + code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); |
445 | 451 | var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); |
446 | 452 | await _emailSender.SendEmail( |
447 | 453 | model.Email, |
448 | 454 | "Reset Password", |
449 | | - $"Please reset your password by clicking here: {callbackUrl}", |
| 455 | + $"Please reset your password by clicking here: {HtmlEncoder.Default.Encode(callbackUrl)}", |
450 | 456 | "Hi Sir"); |
451 | 457 |
|
452 | 458 | return View("ForgotPasswordConfirmation"); |
@@ -491,7 +497,8 @@ public async Task<IActionResult> ResetPassword(ResetPasswordViewModel model) |
491 | 497 | // Don't reveal that the user does not exist |
492 | 498 | return RedirectToAction(nameof(AccountController.ResetPasswordConfirmation), "Account"); |
493 | 499 | } |
494 | | - var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password); |
| 500 | + var code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(model.Code)); |
| 501 | + var result = await _userManager.ResetPasswordAsync(user, code, model.Password); |
495 | 502 | if (result.Succeeded) |
496 | 503 | { |
497 | 504 | return RedirectToAction(nameof(AccountController.ResetPasswordConfirmation), "Account"); |
@@ -550,6 +557,7 @@ public async Task<IActionResult> SendCode(SendCodeViewModel model) |
550 | 557 | // Email used |
551 | 558 | // Generate the token and send it |
552 | 559 | var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider); |
| 560 | + code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); |
553 | 561 | if (string.IsNullOrWhiteSpace(code)) |
554 | 562 | { |
555 | 563 | return View("Error"); |
|
0 commit comments