refacto error handling
This commit is contained in:
parent
96d175f13d
commit
d8ee77b9de
8 changed files with 126 additions and 45 deletions
|
|
@ -791,12 +791,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
if (userId == null || code == null)
|
||||
{
|
||||
return View("Error");
|
||||
return this.ErrorView<AccountController>("Error: userId or code is null.");
|
||||
}
|
||||
var user = await _userManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
return this.ErrorView<AccountController>("Error: user not found.");
|
||||
}
|
||||
IdentityResult result = null;
|
||||
try
|
||||
|
|
@ -819,12 +819,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
if (userId == null || code == null)
|
||||
{
|
||||
return View("Error");
|
||||
return this.ErrorView<AccountController>("Error: userId or code is null.");
|
||||
}
|
||||
var user = await _userManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
return this.ErrorView<AccountController>("Error: user not found.");
|
||||
}
|
||||
bool result = false;
|
||||
try
|
||||
|
|
@ -837,7 +837,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
_logger.LogError(ex.StackTrace);
|
||||
_logger.LogError(ex.Message);
|
||||
}
|
||||
return View(result ? "EmailConfirmed" : "Error");
|
||||
return result ? View("EmailConfirmed") : this.ErrorView<AccountController>("Error confirming two factor token.");
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
using System.Security.Claims;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
|
@ -490,12 +489,7 @@ namespace Yavsc.Controllers
|
|||
: message == ManageMessageId.Error ? "An error has occurred."
|
||||
: "";
|
||||
var user = await GetCurrentUserAsync();
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
}
|
||||
var userLogins = await _userManager.GetLoginsAsync(user);
|
||||
|
||||
ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
|
||||
|
||||
return View(new ManageLoginsViewModel
|
||||
|
|
@ -522,15 +516,7 @@ namespace Yavsc.Controllers
|
|||
public async Task<ActionResult> LinkLoginCallback()
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
if (user == null)
|
||||
{
|
||||
return View("Error");
|
||||
}
|
||||
var info = await _signInManager.GetExternalLoginInfoAsync(User.GetUserId());
|
||||
if (info == null)
|
||||
{
|
||||
return RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error });
|
||||
}
|
||||
var result = await _userManager.AddLoginAsync(user, info);
|
||||
var message = result.Succeeded ? ManageMessageId.AddLoginSuccess : ManageMessageId.Error;
|
||||
return RedirectToAction(nameof(ManageLogins), new { Message = message });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue