Skip to content

Commit

Permalink
refactored namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
suxrobGM committed Jan 5, 2024
1 parent 214178d commit 87e6593
Show file tree
Hide file tree
Showing 28 changed files with 208 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityModel.OidcClient;
using Logistics.DriverApp.Extensions;
using Logistics.DriverApp.Services;
using Logistics.DriverApp.Services.Authentication;
using Logistics.DriverApp.Services.LocationTracking;
Expand All @@ -11,9 +12,9 @@
using Logistics.DriverApp.Platforms.iOS.Services;
#endif

namespace Logistics.DriverApp.Extensions;
namespace Logistics.DriverApp;

public static class ApplicationExtensions
public static class Setup
{
public static MauiAppBuilder ConfigureServices(this MauiAppBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Logistics.API.Extensions;

internal static class ApplicationExtensions
internal static class Setup
{
public static WebApplication ConfigureServices(this WebApplicationBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using System.Text;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using System.Text;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Encodings.Web;
using System.Text;
using Logistics.Application.Core.Services;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.ForgotPassword;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Text.RegularExpressions;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.Login;

Expand Down Expand Up @@ -188,4 +189,4 @@ private async Task BuildModelAsync(string returnUrl)
ExternalProviders = providers.ToArray()
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Duende.IdentityServer.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.LoginWith2fa;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.LoginWithRecoveryCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Duende.IdentityServer.Extensions;
using Duende.IdentityServer.Services;
using IdentityModel;
using Logistics.Domain.Entities;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -96,4 +97,4 @@ public async Task<IActionResult> OnPost()

return RedirectToPage("/Account/Logout/LoggedOut", new { logoutId = LogoutId });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Logistics.Domain.Entities;
using Logistics.IdentityServer.Pages.Account.Manage.ChangePassword;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Duende.IdentityServer.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.Manage.ChangePassword
{
Expand Down Expand Up @@ -76,4 +74,4 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
using Logistics.Domain.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Logistics.IdentityServer.Pages.Account.Manage
namespace Logistics.IdentityServer.Pages.Account.Manage;

public class Disable2faModel : PageModel
{
public class Disable2faModel : PageModel
private readonly UserManager<User> _userManager;
private readonly ILogger<Disable2faModel> _logger;

public Disable2faModel(
UserManager<User> userManager,
ILogger<Disable2faModel> logger)
{
private readonly UserManager<User> _userManager;
private readonly ILogger<Disable2faModel> _logger;
_userManager = userManager;
_logger = logger;
}

public Disable2faModel(
UserManager<User> userManager,
ILogger<Disable2faModel> logger)
[TempData]
public string StatusMessage { get; set; }

public async Task<IActionResult> OnGet()
{
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
_userManager = userManager;
_logger = logger;
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}

[TempData]
public string StatusMessage { get; set; }
if (!await _userManager.GetTwoFactorEnabledAsync(user))
{
throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled.");
}

return Page();
}

public async Task<IActionResult> OnGet()
public async Task<IActionResult> OnPostAsync()
{
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}

if (!await _userManager.GetTwoFactorEnabledAsync(user))
{
throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled.");
}

return Page();
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}

public async Task<IActionResult> OnPostAsync()
var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false);
if (!disable2faResult.Succeeded)
{
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}

var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false);
if (!disable2faResult.Succeeded)
{
throw new InvalidOperationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'.");
}

_logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User));
StatusMessage = "2fa has been disabled. You can reenable 2fa when you setup an authenticator app";
return RedirectToPage("./TwoFactorAuthentication");
throw new InvalidOperationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'.");
}

_logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User));
StatusMessage = "2fa has been disabled. You can reenable 2fa when you setup an authenticator app";
return RedirectToPage("./TwoFactorAuthentication");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.AspNetCore.WebUtilities;
using System.Text.Encodings.Web;
using System.Text;
using Logistics.Application.Core.Services;
using Logistics.Domain.Entities;

namespace Logistics.IdentityServer.Pages.Account.Manage.Email;

Expand Down
Loading

0 comments on commit 87e6593

Please sign in to comment.