From a45c2125924daad5e96d038977751dde61851097 Mon Sep 17 00:00:00 2001 From: code liturgy Date: Wed, 16 Nov 2022 21:17:44 +0000 Subject: [PATCH] Api controller using cookie auth --- .gitmodules | 6 +- BlueWest.Frontend | 1 - CodeLiturgy.Dashboard.Frontend | 1 + .../Session/SessionConstants.cs | 3 +- CodeLiturgy.Data.Auth/Users/Constants.cs | 12 ++ CodeLiturgy.Data.Capital/EnvironmentType.cs | 8 ++ CodeLiturgy.Data.Capital/Sites/Site.cs | 30 +++++ CodeLiturgy.Data.Capital/Sites/SiteCreate.cs | 16 +++ CodeLiturgy.Data.Capital/Sites/SiteUnique.cs | 19 +++ .../ApplicationUserDbContext.cs | 1 - CodeLiturgy.Domain/SiteDbContext.cs | 26 ++++ CodeLiturgy.Views/CodeLiturgy.Views.csproj | 15 ++- .../Controllers/AccountController.cs | 23 +--- .../Controllers/AuthController.cs | 7 ++ .../Controllers/EnvironmentsController.cs | 39 ++++++ .../Controllers/EnvironmentsPageController.cs | 34 ++++++ .../Controllers/HomeController.cs | 10 +- .../Controllers/System/SystemController.cs | 2 +- .../Controllers/UserController.cs | 24 +++- .../{SiteContent.cs => Translations.cs} | 75 ++---------- CodeLiturgy.Views/StartupExtensions.cs | 23 ++++ CodeLiturgy.Views/Utils/LayoutCache.cs | 101 +++++++--------- CodeLiturgy.Views/Utils/RouteRecord.cs | 33 ++++-- CodeLiturgy.Views/Utils/Routes.cs | 45 ++----- CodeLiturgy.Views/Utils/ViewType.cs | 2 +- .../Views/Account/ChangePassword.cshtml | 111 ------------------ .../Views/Account/Curriculums/Index.cshtml | 10 -- .../Views/Account/Curriculums/Upload.cshtml | 0 CodeLiturgy.Views/Views/Account/Index.cshtml | 111 ------------------ CodeLiturgy.Views/Views/Auth/Account.cshtml | 1 + CodeLiturgy.Views/Views/Auth/Index.cshtml | 5 - CodeLiturgy.Views/Views/Auth/Signup.cshtml | 2 +- CodeLiturgy.Views/Views/Banks/Index.cshtml | 18 --- .../Views/EnvironmentsPage/Index.cshtml | 5 + .../Views/Shared/_FooterMenu.cshtml | 3 +- .../Views/Shared/_HeaderMenu.cshtml | 50 +++++++- CodeLiturgy.Views/Views/Shared/_Layout.cshtml | 7 +- CodeLiturgy.Views/wwwroot/static/main.css | 2 + CodeLiturgy.Views/wwwroot/static/site.css | 16 +++ 39 files changed, 424 insertions(+), 473 deletions(-) delete mode 160000 BlueWest.Frontend create mode 160000 CodeLiturgy.Dashboard.Frontend create mode 100644 CodeLiturgy.Data.Capital/EnvironmentType.cs create mode 100644 CodeLiturgy.Data.Capital/Sites/Site.cs create mode 100644 CodeLiturgy.Data.Capital/Sites/SiteCreate.cs create mode 100644 CodeLiturgy.Data.Capital/Sites/SiteUnique.cs create mode 100644 CodeLiturgy.Domain/SiteDbContext.cs create mode 100644 CodeLiturgy.Views/Controllers/EnvironmentsController.cs create mode 100644 CodeLiturgy.Views/Controllers/EnvironmentsPageController.cs rename CodeLiturgy.Views/Languages/{SiteContent.cs => Translations.cs} (55%) delete mode 100644 CodeLiturgy.Views/Views/Account/ChangePassword.cshtml delete mode 100644 CodeLiturgy.Views/Views/Account/Curriculums/Index.cshtml delete mode 100644 CodeLiturgy.Views/Views/Account/Curriculums/Upload.cshtml delete mode 100644 CodeLiturgy.Views/Views/Account/Index.cshtml create mode 100644 CodeLiturgy.Views/Views/Auth/Account.cshtml delete mode 100644 CodeLiturgy.Views/Views/Auth/Index.cshtml delete mode 100644 CodeLiturgy.Views/Views/Banks/Index.cshtml create mode 100644 CodeLiturgy.Views/Views/EnvironmentsPage/Index.cshtml create mode 100644 CodeLiturgy.Views/wwwroot/static/site.css diff --git a/.gitmodules b/.gitmodules index 03d7a25..639cfda 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,9 @@ [submodule "include/Math-Expression-Evaluator"] path = include/Math-Expression-Evaluator url = git@git.codeliturgy.com:P0/Math-Expression-Evaluator.git -[submodule "BlueWest.Frontend"] - path = BlueWest.Frontend - url = git@git.codeliturgy.com:P0/BlueWest.Frontend.git +[submodule "CodeLiturgy.Dashboard.Frontend"] + path = CodeLiturgy.Dashboard.Frontend + url = git@git.codeliturgy.com:P0/CodeLiturgy.Dashboard.Frontend.git [submodule "include/BlueWest.EfMethods"] path = include/BlueWest.EfMethods url = git@git.codeliturgy.com:P0/BlueWest.EfGenerator.git diff --git a/BlueWest.Frontend b/BlueWest.Frontend deleted file mode 160000 index 8b2e541..0000000 --- a/BlueWest.Frontend +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8b2e541cfe92c7bfaada6a95e427a3d6c92ce768 diff --git a/CodeLiturgy.Dashboard.Frontend b/CodeLiturgy.Dashboard.Frontend new file mode 160000 index 0000000..d8e4df2 --- /dev/null +++ b/CodeLiturgy.Dashboard.Frontend @@ -0,0 +1 @@ +Subproject commit d8e4df2c5d247b02accbbd5c668c4427145806d3 diff --git a/CodeLiturgy.Data.Auth/Session/SessionConstants.cs b/CodeLiturgy.Data.Auth/Session/SessionConstants.cs index 97cd2e7..01a98d3 100644 --- a/CodeLiturgy.Data.Auth/Session/SessionConstants.cs +++ b/CodeLiturgy.Data.Auth/Session/SessionConstants.cs @@ -12,7 +12,8 @@ namespace BlueWest.Data.Auth /// /// API User policy Key /// - public const string ApiNamePolicy = "ApiUser"; + public const string ApiNamePolicy = "Bearer"; + public const string CookieNamePolicy = "Cookies"; public const string SessionTokenHeaderName = "x-bw2-auth"; public const string CookieDomain = "https://localhost:7022"; diff --git a/CodeLiturgy.Data.Auth/Users/Constants.cs b/CodeLiturgy.Data.Auth/Users/Constants.cs index 9a70796..95f2ade 100644 --- a/CodeLiturgy.Data.Auth/Users/Constants.cs +++ b/CodeLiturgy.Data.Auth/Users/Constants.cs @@ -3,6 +3,8 @@ namespace BlueWest.Data.Auth.Context.Users; public static class Constants { + public const string CorsPolicyName = "_myAllowSpecificOrigins"; + /// /// JwtClaimIdentifiers /// @@ -21,4 +23,14 @@ public static class Constants /// public const string ApiAccess = "api_access"; } + + public static class CookieClaims + { + /// + /// JwtClaims.ApiAccess + /// + public const string CookieAccess = "cookie_access"; + } + + } \ No newline at end of file diff --git a/CodeLiturgy.Data.Capital/EnvironmentType.cs b/CodeLiturgy.Data.Capital/EnvironmentType.cs new file mode 100644 index 0000000..bf421d3 --- /dev/null +++ b/CodeLiturgy.Data.Capital/EnvironmentType.cs @@ -0,0 +1,8 @@ +namespace CodeLiturgy.Data.Capital; + +public enum EnvironmentType +{ + Development, + Staging, + Production +} diff --git a/CodeLiturgy.Data.Capital/Sites/Site.cs b/CodeLiturgy.Data.Capital/Sites/Site.cs new file mode 100644 index 0000000..03236d9 --- /dev/null +++ b/CodeLiturgy.Data.Capital/Sites/Site.cs @@ -0,0 +1,30 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; +using MapTo; + +namespace CodeLiturgy.Data.Capital +{ + + [MapFrom(new [] + { + typeof(SiteUnique), + typeof(SiteCreate) + })] + public partial class Site + { + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public string Id { get; set; } + + public string Name { get; set; } + + public string Domain { get; set; } + + public string Ip { get; set; } + + public DateTime CreatedDate { get; set; } + + public DateTime LastChanged { get; set; } + + } +} + diff --git a/CodeLiturgy.Data.Capital/Sites/SiteCreate.cs b/CodeLiturgy.Data.Capital/Sites/SiteCreate.cs new file mode 100644 index 0000000..a4ba989 --- /dev/null +++ b/CodeLiturgy.Data.Capital/Sites/SiteCreate.cs @@ -0,0 +1,16 @@ +using MapTo; + +namespace CodeLiturgy.Data.Capital +{ + [MapFrom(typeof(Site))] + public partial class SiteCreate + { + public string Id { get; set; } + + public string Name { get; set; } + + public string Domain { get; set; } + + public string Ip { get; set; } + } +} diff --git a/CodeLiturgy.Data.Capital/Sites/SiteUnique.cs b/CodeLiturgy.Data.Capital/Sites/SiteUnique.cs new file mode 100644 index 0000000..9a9f147 --- /dev/null +++ b/CodeLiturgy.Data.Capital/Sites/SiteUnique.cs @@ -0,0 +1,19 @@ +using System; +using MapTo; + +namespace CodeLiturgy.Data.Capital +{ + + [MapFrom(typeof(Site))] + public partial class SiteUnique + { + public string Id { get; set; } + + public string Name { get; set; } + + public string Domain { get; set; } + + public string Ip { get; set; } + } +} + diff --git a/CodeLiturgy.Domain/ApplicationUserDbContext.cs b/CodeLiturgy.Domain/ApplicationUserDbContext.cs index 82596fc..1cfb3f3 100644 --- a/CodeLiturgy.Domain/ApplicationUserDbContext.cs +++ b/CodeLiturgy.Domain/ApplicationUserDbContext.cs @@ -53,7 +53,6 @@ namespace CodeLiturgy.Domain { base.OnModelCreating(builder); - builder.ConfigureCurrentDbModel(); diff --git a/CodeLiturgy.Domain/SiteDbContext.cs b/CodeLiturgy.Domain/SiteDbContext.cs new file mode 100644 index 0000000..928216f --- /dev/null +++ b/CodeLiturgy.Domain/SiteDbContext.cs @@ -0,0 +1,26 @@ +using CodeLiturgy.Data.Capital; +using Microsoft.EntityFrameworkCore; +using BlueWest.EfMethods; + +namespace CodeLiturgy.Domain; + +public class SiteDbContext: DbContext +{ + [EfGetOneBy(nameof(Site.Id), typeof(SiteUnique))] + [EfGetOne(typeof(SiteUnique))] + [EfAddMethods(createType: typeof(SiteCreate), returnType: typeof(SiteUnique))] + [EfGetMany(typeof(SiteUnique))] + + public DbSet Sites { get; set; } + + /// + /// SiteDbContext Constructor. + /// + /// + public SiteDbContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } + + +} \ No newline at end of file diff --git a/CodeLiturgy.Views/CodeLiturgy.Views.csproj b/CodeLiturgy.Views/CodeLiturgy.Views.csproj index 0bf4100..5cdfc61 100644 --- a/CodeLiturgy.Views/CodeLiturgy.Views.csproj +++ b/CodeLiturgy.Views/CodeLiturgy.Views.csproj @@ -2,7 +2,7 @@ net7.0 - enable + disable enable Linux @@ -79,10 +79,10 @@ <_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.min.map" /> <_ContentIncludedByDefault Remove="wwwroot\lib\jquery\LICENSE.txt" /> <_ContentIncludedByDefault Remove="Views\Data\Roles\Index.cshtml" /> - - - - + <_ContentIncludedByDefault Remove="Views\Account\ChangePassword.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\Curriculums\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\Curriculums\Upload.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\Index.cshtml" /> @@ -109,4 +109,9 @@ + + + + + diff --git a/CodeLiturgy.Views/Controllers/AccountController.cs b/CodeLiturgy.Views/Controllers/AccountController.cs index 490c179..040141e 100644 --- a/CodeLiturgy.Views/Controllers/AccountController.cs +++ b/CodeLiturgy.Views/Controllers/AccountController.cs @@ -11,8 +11,7 @@ namespace CodeLiturgy.Views.Controllers; public class AccountController : UserController { private readonly ILogger _logger; - - + public AccountController(ApplicationUserManager userManager, ILogger logger) : base(userManager, logger) { _userManager = userManager; @@ -27,19 +26,9 @@ public class AccountController : UserController public override void OnInitialization() { - SetFooterMenu(LayoutCache.AccountRouteRecord.Children); + SetFooterMenu(LayoutCache.AccountRouteRecord.ChildrenToUrl()); } - - - public async Task Curriculums() - { - await OnEveryAction(); - - return View("Curriculums/Index"); - } - - public async Task Change() { await OnEveryAction(); @@ -47,14 +36,6 @@ public class AccountController : UserController } - [Microsoft.AspNetCore.Mvc.Route("[controller]/upload")] - public async Task UploadCurriculum() - { - await OnEveryAction(); - return View("Curriculums/Upload"); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public async Task Error() { diff --git a/CodeLiturgy.Views/Controllers/AuthController.cs b/CodeLiturgy.Views/Controllers/AuthController.cs index 7a3d8a7..42abf89 100644 --- a/CodeLiturgy.Views/Controllers/AuthController.cs +++ b/CodeLiturgy.Views/Controllers/AuthController.cs @@ -62,6 +62,13 @@ namespace CodeLiturgy.Views.Controllers return View(); } + public async Task Account() + { + await OnEveryAction(); + this.HandleGlobalization(); + return View(); + } + public async Task Logout() { diff --git a/CodeLiturgy.Views/Controllers/EnvironmentsController.cs b/CodeLiturgy.Views/Controllers/EnvironmentsController.cs new file mode 100644 index 0000000..191aeba --- /dev/null +++ b/CodeLiturgy.Views/Controllers/EnvironmentsController.cs @@ -0,0 +1,39 @@ +using BlueWest.Data.Auth.Context.Users; +using CodeLiturgy.Data.Capital; +using CodeLiturgy.Domain; +using CodeLiturgy.Views.Utils; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; + + +namespace CodeLiturgy.Views.Controllers +{ + [Route("api/envs")] + [ApiController] + [Authorize] + + public class EnvironmentsController : ControllerBase + { + private ApplicationUserManager _userManager; + private ILogger _logger; + private SiteDbContext _siteDbContext; + + public EnvironmentsController(ApplicationUserManager userManager, ILogger logger, SiteDbContext siteDbContext) + { + _logger = logger; + _userManager = userManager; + _siteDbContext = siteDbContext; + } + + [HttpGet] + public async Task> GetSites() + { + return Ok(new Site()); + } + + } +} + diff --git a/CodeLiturgy.Views/Controllers/EnvironmentsPageController.cs b/CodeLiturgy.Views/Controllers/EnvironmentsPageController.cs new file mode 100644 index 0000000..a153d68 --- /dev/null +++ b/CodeLiturgy.Views/Controllers/EnvironmentsPageController.cs @@ -0,0 +1,34 @@ +using BlueWest.Data.Auth.Context.Users; +using CodeLiturgy.Views.Utils; +using Duende.IdentityServer.Extensions; +using Microsoft.AspNetCore.Mvc; + +namespace CodeLiturgy.Views.Controllers; + + +public class EnvironmentsPageController : UserController +{ + public EnvironmentsPageController(ApplicationUserManager userManager, ILogger logger) : base(userManager, logger) { } + + public override void OnInitialization() + { + base.OnInitialization(); + SetHeaderMenu(new List() + { + }); + } + + public async Task Index() + { + await OnEveryAction(); + + + if (!User.IsAuthenticated()) + { + return Redirect("/auth/login"); + } + + + return View(); + } +} \ No newline at end of file diff --git a/CodeLiturgy.Views/Controllers/HomeController.cs b/CodeLiturgy.Views/Controllers/HomeController.cs index 86afbf4..e234a59 100644 --- a/CodeLiturgy.Views/Controllers/HomeController.cs +++ b/CodeLiturgy.Views/Controllers/HomeController.cs @@ -17,8 +17,14 @@ public class HomeController : UserController _userManager = userManager; _logger = logger; } - - + + public override void OnInitialization() + { + var menu = LayoutCache.Root.ChildrenToUrl(); + SetHeaderMenu(menu); + } + + [AllowAnonymous] public async Task Index() { diff --git a/CodeLiturgy.Views/Controllers/System/SystemController.cs b/CodeLiturgy.Views/Controllers/System/SystemController.cs index 3ee07d9..5662d67 100644 --- a/CodeLiturgy.Views/Controllers/System/SystemController.cs +++ b/CodeLiturgy.Views/Controllers/System/SystemController.cs @@ -21,7 +21,7 @@ namespace CodeLiturgy.Views.Controllers public override void OnInitialization() { - SetFooterMenu(LayoutCache.SystemRoute.Children); + SetFooterMenu(LayoutCache.SystemRoute.ChildrenToUrl()); } public async Task Users() diff --git a/CodeLiturgy.Views/Controllers/UserController.cs b/CodeLiturgy.Views/Controllers/UserController.cs index 1ddc745..a5d64e4 100644 --- a/CodeLiturgy.Views/Controllers/UserController.cs +++ b/CodeLiturgy.Views/Controllers/UserController.cs @@ -15,22 +15,24 @@ public class UserController : Controller protected ILogger _logger; protected ApplicationUserManager _userManager; - private List _footerMenu; + private List _footerMenu; + private List _headerMenu; public UserController(ApplicationUserManager userManager, ILogger logger) { _logger = logger; _userManager = userManager; - _footerMenu = new List(); + _footerMenu = new List(); + _headerMenu = new List(); } public async Task OnEveryAction() { HandleGlobalization(); - SetFooterMenuViewData(); await SetUserProfileViewData(); OnInitialization(); SetFooterMenuViewData(); + SetHeaderMenuViewData(); } public virtual void OnInitialization() @@ -42,9 +44,21 @@ public class UserController : Controller ViewData[FooterMenuViewDataId] = _footerMenu; } - public void SetFooterMenu(List routeRecords) + protected void SetHeaderMenuViewData() { - _footerMenu = routeRecords; + ViewData[HeaderMenuId] = _headerMenu; + } + + + public void SetFooterMenu(List urls) + { + _footerMenu = urls; + } + + + public void SetHeaderMenu(List urls) + { + _headerMenu = urls; } public async Task SetUserProfileViewData() diff --git a/CodeLiturgy.Views/Languages/SiteContent.cs b/CodeLiturgy.Views/Languages/Translations.cs similarity index 55% rename from CodeLiturgy.Views/Languages/SiteContent.cs rename to CodeLiturgy.Views/Languages/Translations.cs index f80fa7b..fdd3d80 100644 --- a/CodeLiturgy.Views/Languages/SiteContent.cs +++ b/CodeLiturgy.Views/Languages/Translations.cs @@ -1,6 +1,6 @@ namespace CodeLiturgy.Views.Languages; -public static class SiteContent +public static class Translations { internal static readonly Dictionary> RouteTitle = new Dictionary> @@ -21,14 +21,6 @@ public static class SiteContent {"en-gb", "System"}, } }, - { - DataKeyName, new Dictionary() - { - {"pt", "Dados"}, - {"eng", "Data"}, - {"en-gb", "Data"} - } - }, { RolesKeyName, new Dictionary() @@ -62,68 +54,23 @@ public static class SiteContent {"en-gb", "Settings"}, } }, - { - CompaniesKeyName, new Dictionary() - { - {"pt", "Empresas"}, - {"eng", "Companies"}, - {"en-gb", "Companies"}, - } - }, { - IndustriesKeyName, new Dictionary() + AuthAccountKeyName, new Dictionary() { - {"pt", "Indústrias"}, - {"en-gb", "Industries"}, - {"eng", "Industries"}, - } - }, - - { - CurrenciesKeyName, new Dictionary() - { - {"pt", "Moedas"}, - {"en-gb", "Currencies"}, - {"eng", "Currencies"}, - } - }, - { - CountriesKeyName, new Dictionary() - { - {"pt", "Países"}, - {"eng", "Countries"}, - {"en-gb", "Countries"} - } - }, - - { - BanksKeyName, new Dictionary() - { - {"pt", "Bancos"}, - {"eng", "Banks"}, - {"en-gb", "Banks"}, - } - }, - - - { - DataUsersKeyName, new Dictionary() - { - {"pt", "Utilizadores"}, - {"eng", "Users"}, - {"en-gb", "Users"}, - } - }, - - { - AccountKeyName, new Dictionary() - { - {"pt", "Perfil"}, + {"pt", "Conta"}, {"eng", "Account"}, {"en-gb", "Account"}, } }, + { + EnvironmentsKeyName, new Dictionary() + { + {"pt", "Ambientes"}, + {"eng", "Environments"}, + {"en-gb", "Environments"}, + } + }, { ChangePasswordKeyName, new Dictionary() diff --git a/CodeLiturgy.Views/StartupExtensions.cs b/CodeLiturgy.Views/StartupExtensions.cs index f01d9ed..1195e3f 100644 --- a/CodeLiturgy.Views/StartupExtensions.cs +++ b/CodeLiturgy.Views/StartupExtensions.cs @@ -112,6 +112,24 @@ public static class StartupExtensions { options.LoginPath = Routes.AuthLoginRoute; options.LogoutPath = Routes.AuthLogoutRoute; + }) + .AddJwtBearer(configureOptions => + { + configureOptions.ClaimsIssuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)]; + configureOptions.TokenValidationParameters = tokenValidationParameters; + configureOptions.SaveToken = true; + configureOptions.Events = new JwtBearerEvents + { + OnAuthenticationFailed = context => + { + if (context.Exception.GetType() == typeof(SecurityTokenExpiredException)) + { + context.Response.Headers.Add("Token-Expired", "true"); + } + + return Task.CompletedTask; + }, + }; }); @@ -121,6 +139,10 @@ public static class StartupExtensions options.AddPolicy(SessionConstants.ApiNamePolicy, policy => policy.RequireClaim(Constants.JwtClaimIdentifiers.Rol, Constants.JwtClaims.ApiAccess)); + options.AddPolicy(SessionConstants.CookieNamePolicy, policy => + { + policy.RequireClaim(Constants.CookieClaims.CookieAccess); + }); }); // add identity @@ -168,6 +190,7 @@ public static class StartupExtensions { return serviceCollection .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)) + .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)) .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)) .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)); diff --git a/CodeLiturgy.Views/Utils/LayoutCache.cs b/CodeLiturgy.Views/Utils/LayoutCache.cs index ed36421..a7048a8 100644 --- a/CodeLiturgy.Views/Utils/LayoutCache.cs +++ b/CodeLiturgy.Views/Utils/LayoutCache.cs @@ -10,16 +10,22 @@ internal class LayoutCache #region Route Tree private static readonly RouteRecord NonLoggedInRoot = new RouteRecord( + "Login", AuthLoginRoute, AuthLoginKeyName, nameof(AuthController), new List()); - - private static readonly RouteRecord Root = new RouteRecord( + + internal static readonly RouteRecord Root = new RouteRecord( + "Code Liturgy - Dashboard", RootKeyName, RootLocation, nameof(HomeController), - new List(), ViewType.Root); + new List() + { + new RouteRecord("Environments", EnvironmentsKeyName, EnvironmentsRouteLocation, nameof(EnvironmentsPageController), new List(), ViewType.Environments) + + }, ViewType.Root); #endregion Route Tree @@ -28,9 +34,6 @@ internal class LayoutCache internal static readonly RouteRecord SystemRoute = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.System)!; - internal static readonly RouteRecord DataRouteRecord = - Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Data)!; - internal static readonly RouteRecord AccountRouteRecord = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Account)!; @@ -38,70 +41,48 @@ internal class LayoutCache #region Internal Menus - internal static List GetDefaultFooterMenu(ViewDataDictionary dictionary) + + internal static List GetDefaultHeaderMenu(ViewDataDictionary dictionary, bool userAuthenticated = false) { - var location = GetUserLanguage(dictionary); + var menuToShow = new List(); - var menu = LayoutCache - .Root - .Children; - - if (dictionary[FooterMenuViewDataId] is List footerMenu) - { - menu = footerMenu; - } + menuToShow.Add(Root.ToUrl()); - return menu - .Select(x => - { - if (SiteContent.RouteTitle[x.routeKey].ContainsKey(location)) - { - return new RouteView(SiteContent.RouteTitle[x.routeKey][location], - location); - } - return new RouteView(SiteContent.RouteTitle[x.routeKey][DefaultCultureName], - x.location); - - }) - - .ToList(); - - } - - internal static List GetDefaultHeaderMenu(ViewDataDictionary dictionary, bool userAuthenticated = false) - { if (!userAuthenticated) { - var menuToShow = new List(); - menuToShow.Add(new RouteView("CodeLiturgy Dashboard", "/")); return menuToShow; } - - var location = GetUserLanguage(dictionary); - - var menu = LayoutCache - .Root - .Children; - - if (dictionary[HeaderMenuId] is List footerMenu) + + if (dictionary[HeaderMenuId] is List headerMenu) { - menu = footerMenu; + menuToShow = menuToShow + .Concat(headerMenu) + .ToList(); } + + return menuToShow; + } + + + internal static List GetDefaultFooterMenu(ViewDataDictionary dictionary, bool userAuthenticated) + { + var menuToShow = new List(); - return menu - .Select(x => - { - if (SiteContent.RouteTitle[x.routeKey].ContainsKey(location)) - { - return new RouteView(SiteContent.RouteTitle[x.routeKey][location], - x.Location); - } - return new RouteView(SiteContent.RouteTitle[x.routeKey][DefaultCultureName], - x.location); - - }) - - .ToList(); + menuToShow.Add(Root.ToUrl()); + + if (!userAuthenticated) + { + return menuToShow; + } + + if (dictionary[FooterMenuViewDataId] is List footerMenu) + { + menuToShow = menuToShow + .Concat(footerMenu) + .ToList(); + } + + return menuToShow; } diff --git a/CodeLiturgy.Views/Utils/RouteRecord.cs b/CodeLiturgy.Views/Utils/RouteRecord.cs index aab6a6c..428306f 100644 --- a/CodeLiturgy.Views/Utils/RouteRecord.cs +++ b/CodeLiturgy.Views/Utils/RouteRecord.cs @@ -1,14 +1,33 @@ namespace CodeLiturgy.Views.Utils { - public record RouteRecord(string routeKey, string location, string controllerName, List children, ViewType viewType = ViewType.Undefined) + public class Url { - public string RouteKey = routeKey; - public string Location = location; - public string ControllerName; - public List Children = children; - public ViewType ViewType = viewType; + public string Name; + public string Location; + + public Url(string name, string location) + { + Name = name; + Location = location; + } + } + public record RouteRecord(string Name, string RouteKey, string Location, string ControllerName, List Children, ViewType ViewType = ViewType.Undefined) + { + + public List ChildrenToUrl() + { + return Children.Select(x => x.ToUrl()).ToList(); + } + public Url ToUrl() + { + return new Url(Name, Location); + } + public Url ToUrl(string name) + { + return new Url(name, Location); + } + } - public record RouteView(string Name, string Location); } diff --git a/CodeLiturgy.Views/Utils/Routes.cs b/CodeLiturgy.Views/Utils/Routes.cs index b56e7bc..e083c14 100644 --- a/CodeLiturgy.Views/Utils/Routes.cs +++ b/CodeLiturgy.Views/Utils/Routes.cs @@ -45,48 +45,23 @@ namespace CodeLiturgy.Views.Utils internal const string SettingsRouteLocation = $"{SystemRouteLocation}/settings"; internal const string SettingsKeyName = "settings"; - - internal const string DataLocation = $"/data"; - internal const string DataKeyName = "data"; - - internal const string DataUsersLocation = "/data/users"; - internal const string DataUsersKeyName = "users"; - internal const string SystemRouteLocation = $"/system"; internal const string SystemKeyName = "system"; - internal const string BanksKeyName = "banks"; - internal const string BanksLocation = $"{DataLocation}/banks"; - internal const string CountriesLocation = $"{DataLocation}/countries"; - internal const string CountriesKeyName = "countries"; - - internal const string CurrenciesLocation = $"{DataLocation}/currencies"; - internal const string CurrenciesKeyName = "currencies"; - - internal const string IndustriesKeyName = "industries"; - internal const string IndustriesLocation = $"{DataLocation}/industries"; - - internal const string CompaniesLocation = $"{DataLocation}/companies"; - internal const string CompaniesKeyName = "companies"; - - - // Jobs - internal const string Curriculums = "curriculums"; - internal const string Proposals = "proposals"; - internal const string Offers = "offers"; - internal const string Processes = "processes"; internal const string AuthLogoutRoute = "/auth/logout"; - - // Account - internal const string AccountRouteLocation = "/account"; - internal const string AccountKeyName = "profile"; - internal const string ChangePasswordKeyName = "changepwd"; - internal const string ChangePasswordRouteLocation = $"{AccountRouteLocation}/change"; + internal const string AuthAccountRoute = "/auth/account"; + internal const string AuthAccountKeyName = "account"; - - + // Account + + internal const string ChangePasswordKeyName = "changepwd"; + internal const string ChangePasswordRouteLocation = $"{AuthAccountRoute}/change"; + + // Environments + internal const string EnvironmentsRouteLocation = "/environments"; + internal const string EnvironmentsKeyName = "envs"; } } \ No newline at end of file diff --git a/CodeLiturgy.Views/Utils/ViewType.cs b/CodeLiturgy.Views/Utils/ViewType.cs index 83bcb2b..07eab08 100644 --- a/CodeLiturgy.Views/Utils/ViewType.cs +++ b/CodeLiturgy.Views/Utils/ViewType.cs @@ -5,8 +5,8 @@ namespace CodeLiturgy.Views public enum ViewType { System, - Data, Account, + Environments, Root, Undefined diff --git a/CodeLiturgy.Views/Views/Account/ChangePassword.cshtml b/CodeLiturgy.Views/Views/Account/ChangePassword.cshtml deleted file mode 100644 index caedb60..0000000 --- a/CodeLiturgy.Views/Views/Account/ChangePassword.cshtml +++ /dev/null @@ -1,111 +0,0 @@ -@using CodeLiturgy.Views.Utils -@model BlueWest.Data.Application.Users.ApplicationUserUnique -@{ - var user = @Model; -} - -
-
- - - - - - -
- - -
-
-
- - -@await Html.PartialAsync("_FooterMenu") \ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Account/Curriculums/Index.cshtml b/CodeLiturgy.Views/Views/Account/Curriculums/Index.cshtml deleted file mode 100644 index ab78453..0000000 --- a/CodeLiturgy.Views/Views/Account/Curriculums/Index.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@{ - ViewData["Title"] = "Home Page"; -} - -
-

Curriculums Module

-
- - -@Html.Partial("_FooterMenu"); \ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Account/Curriculums/Upload.cshtml b/CodeLiturgy.Views/Views/Account/Curriculums/Upload.cshtml deleted file mode 100644 index e69de29..0000000 diff --git a/CodeLiturgy.Views/Views/Account/Index.cshtml b/CodeLiturgy.Views/Views/Account/Index.cshtml deleted file mode 100644 index caedb60..0000000 --- a/CodeLiturgy.Views/Views/Account/Index.cshtml +++ /dev/null @@ -1,111 +0,0 @@ -@using CodeLiturgy.Views.Utils -@model BlueWest.Data.Application.Users.ApplicationUserUnique -@{ - var user = @Model; -} - -
-
- - - - - - -
- - -
-
-
- - -@await Html.PartialAsync("_FooterMenu") \ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Auth/Account.cshtml b/CodeLiturgy.Views/Views/Auth/Account.cshtml new file mode 100644 index 0000000..e0b1a46 --- /dev/null +++ b/CodeLiturgy.Views/Views/Auth/Account.cshtml @@ -0,0 +1 @@ +

Account

\ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Auth/Index.cshtml b/CodeLiturgy.Views/Views/Auth/Index.cshtml deleted file mode 100644 index 7bdba35..0000000 --- a/CodeLiturgy.Views/Views/Auth/Index.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@model BlueWest.Data.Auth.Context.Users.LoginRequest -@using (Html.BeginForm()){ - @Html.LabelFor(x => x.Password, "Password") - @Html.PasswordFor(x => x.Password); -} \ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Auth/Signup.cshtml b/CodeLiturgy.Views/Views/Auth/Signup.cshtml index 88ad010..7bebed3 100644 --- a/CodeLiturgy.Views/Views/Auth/Signup.cshtml +++ b/CodeLiturgy.Views/Views/Auth/Signup.cshtml @@ -101,7 +101,7 @@ + + + + + } + \ No newline at end of file diff --git a/CodeLiturgy.Views/Views/Shared/_Layout.cshtml b/CodeLiturgy.Views/Views/Shared/_Layout.cshtml index ed27679..040dbf7 100644 --- a/CodeLiturgy.Views/Views/Shared/_Layout.cshtml +++ b/CodeLiturgy.Views/Views/Shared/_Layout.cshtml @@ -10,10 +10,9 @@ @ViewData["Title"] - CodeLiturgy.Views - - @* - - *@ + + +