Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Jul 14, 2023
1 parent fb0e6aa commit e7f711d
Show file tree
Hide file tree
Showing 46 changed files with 419 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<ItemGroup>
<PackageReference Include="Hangfire.EntityFrameworkCore" Version="0.5.0" />
<PackageReference Include="Serilog.Sinks.SQLite" Version="6.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.3.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.0.0" />

<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />

<PackageReference Include="Hangfire.Storage.SQLite" Version="0.3.4" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 7 additions & 1 deletion src/Corsinvest.AppHero.AppBss/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Corsinvest.AppHero.Core.SoftwareUpdater;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.HttpOverrides;
using Serilog;

//appsetting default
Expand Down Expand Up @@ -83,7 +84,12 @@
#endregion
}

app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

app.UseRouting();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<IResult<bool>> LoginAsync(LoginRequestAD loginRequestAD)
}

//redirect to login
if (ret.IsSuccess) { await _autentication.ExecuteLoginAsync(user!, loginRequestAD.RememberMe); }
if (ret.IsSuccess) { await _autentication.LoginAsync(loginRequestAD); }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.9" />
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.6.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public IActionResult Challenge(string provider)
["returnUrl"] = "/" ,
["scheme"] = provider ,
}
}, provider);
},
provider);


[AllowAnonymous]
Expand Down
3 changes: 3 additions & 0 deletions src/Corsinvest.AppHero.Authentication/OptionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
*/
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;

namespace Corsinvest.AppHero.Authentication;

public class OptionsBase
{
[Display(Name = "Default Roles New User must be separated with a comma character (\",\")")]
public string DefaultRolesNewUser { get; set; } = default!;
public bool AutoImportUser { get; set; } = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Fast.Components.FluentUI" Version="2.3.6" />
<PackageReference Include="Microsoft.Fast.Components.FluentUI" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="6.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="6.5.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
<PackageReference Include="MudBlazor" Version="6.7.0" />
<PackageReference Include="BlazorDownloadFile" Version="2.4.0.2" />
<PackageReference Include="MudBlazor.Extensions" Version="1.7.54" />
<PackageReference Include="MudBlazor.Extensions" Version="1.7.62" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="Toolbelt.Blazor.LoadingBar" Version="13.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Corsinvest.AppHero.Core.MudBlazorUI.Extensions;

public static class ModularityExtensions
{
public static string ToMBIcon(this IModularityService modularityService, string category)
=> MudBlazorHelper.ToMBIcon(modularityService.GetCategoryIcon(category)!);
public static string ToMBIcon(this IModularityService modularityService, string category)
=> MudBlazorHelper.ToMBIcon(modularityService.GetCategoryIcon(category));

public static string ToMBIcon(this IGroupableService groupableService) => MudBlazorHelper.ToMBIcon(groupableService.GetGroupIcon());
public static string ToMBIcon(this ModuleMenuItem menuItem) => MudBlazorHelper.ToMBIcon(menuItem.Icon);
Expand Down
1 change: 0 additions & 1 deletion src/Corsinvest.AppHero.Core.MudBlazorUI/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
services.AddScoped<IUINotifier, UINotifier>();
services.AddScoped<IUIMessageBox, UIMessageBox>();
services.AddMudExtensions();
services.AddMudServicesWithExtensions();
services.AddScoped<LayoutService>();
services.AddTransient(typeof(IDataGridManager<>), typeof(DataGridManager<>));
services.AddTransient(typeof(IDataGridManagerRepository<>), typeof(DataGridManagerRepository<>));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ private async Task UpdateUserAsync()
var result = await UserManager.UpdateAsync(User);
UINotifier.Show(result.Succeeded, L["Update successfully."], result.ToStringErrors());

if (result.Succeeded)
{
//reload page for change language
NavigationManager.NavigateTo(UrlHelper.SetParameter("/api/account/setculture",
new()
{
{ "culture", User.DefaultCulture},
{ "redirectUri", NavigationManager.Uri}
}), true);
}
if (result.Succeeded) { CurrentUserService.SetCulture(User.DefaultCulture, NavigationManager.Uri); }
}
}

Expand All @@ -57,14 +48,14 @@ private async Task ChangePasswordAsync()
}
}

private class ChangePasswordModel
class ChangePasswordModel
{
public string CurrentPassword { get; set; } = string.Empty;
public string NewPassword { get; set; } = string.Empty;
public string ConfirmPassword { get; set; } = string.Empty;
}

private class PasswordFluentValidator : AbstractModelValidator<ChangePasswordModel>
class PasswordFluentValidator : AbstractModelValidator<ChangePasswordModel>
{
public PasswordFluentValidator(Core.Security.Identity.Options identityOptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class RolePermissions

[Inject] private IModularityService ModularityService { get; set; } = default!;

private class TreeDataPermission
class TreeDataPermission
{
public string? Key { get; set; }
public string Path { get; set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ protected override void OnInitialized()
DataGridManager.SaveAfterAsync = async (user, isNew) =>
{
await Task.CompletedTask;
if (user.Id == CurrentUserService.UserId)
{
//reload page for change language
NavigationManager.NavigateTo(UrlHelper.SetParameter("/api/account/setculture",
new()
{
{ "culture", user.DefaultCulture},
{ "redirectUri", NavigationManager.Uri}
}), true);
}
if (user.Id == CurrentUserService.UserId) { CurrentUserService.SetCulture(user.DefaultCulture, NavigationManager.Uri); }
};

DataGridManager.DeleteAsync = async (items) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class AHPasswordsInput
private PasswordModel Model { get; set; } = new();
private ResetPasswordFormModelValidator ModelValidator { get; set; } = default!;

private class PasswordModel
class PasswordModel
{
[Required]
public string Password { get; set; } = default!;
Expand All @@ -28,7 +28,7 @@ private class PasswordModel
public string ConfirmPassword { get; set; } = default!;
}

private class ResetPasswordFormModelValidator : AbstractModelValidator<PasswordModel>
class ResetPasswordFormModelValidator : AbstractModelValidator<PasswordModel>
{
public ResetPasswordFormModelValidator(PasswordOptions passwordOptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ protected override async Task OnInitializedAsync()
}
}

private void Logout() => AuthenticationService.Logout();
private void Logout() => AuthenticationService.LogoutAsync();
}
19 changes: 9 additions & 10 deletions src/Corsinvest.AppHero.Core.MudBlazorUI/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
<MudNavMenu Dense Margin="Margin.Dense" Color="Color.Primary">
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">@L["Home"]</MudNavLink>

@foreach (var category in ModularityService.GetCategories().OrderBy(a => a))
@foreach (var category in ModularityService.Categories.OrderBy(a => a.Order).ThenBy(a => a.Name))
{
if (Authorizations.Any(a => a.Module.Category == category))
if (Authorizations.Any(a => a.Module.Category == category.Name))
{
<MudNavGroup Title="@L[category]" Icon="@ModularityService.ToMBIcon(category)">
@foreach (var item in GetByCategory(category))
<MudNavGroup Title="@L[category.Name]" Icon="@ModularityService.ToMBIcon(category.Name)">
@foreach (var item in GetByCategory(category.Name))
{
@RenderLinkModule(item.Key.Link!, item.SelectMany(a => a.Links))
}
</MudNavGroup>

}
}
</MudNavMenu>
Expand All @@ -38,11 +37,11 @@
else
{
<MudNavLink Href="@link.RealUrl"
Icon="@link.ToMBIcon()"
IconColor="@link.IconColor.ToMBColor()"
Match="NavLinkMatch.All"
Target="@(link.IsExternal ? "_blank" : null)"
Disabled="@(!link.Enabled)">
Icon="@link.ToMBIcon()"
IconColor="@link.IconColor.ToMBColor()"
Match="NavLinkMatch.All"
Target="@(link.IsExternal ? "_blank" : null)"
Disabled="@(!link.Enabled)">
@link.Text
</MudNavLink>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Radzen.Blazor" Version="4.13.3" />
<PackageReference Include="Radzen.Blazor" Version="4.13.5" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 7 additions & 5 deletions src/Corsinvest.AppHero.Core/Corsinvest.AppHero.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@
<PackageReference Include="Ardalis.Specification" Version="7.0.0" />
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />

<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
<PackageReference Include="MiniExcel" Version="1.31.0" />
<PackageReference Include="RazorEngineCore" Version="2022.8.1" />

<PackageReference Include="CronExpressionDescriptor" Version="2.20.0" />
<PackageReference Include="cronos" Version="0.7.1" />
<PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.0" />

<PackageReference Include="Weikio.PluginFramework.Catalogs.NuGet" Version="1.5.1" />

<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.2" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.3" />
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Wangkanai.Detection" Version="7.4.0" />
<PackageReference Include="FluentValidation" Version="11.5.2" />
<PackageReference Include="Wangkanai.Detection" Version="8.1.0" />
<PackageReference Include="FluentValidation" Version="11.6.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Corsinvest.AppHero.Core/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Corsinvest.AppHero.Core.Extensions;

public static class LoggerExtensions
{
private class Operation : IDisposable
class Operation : IDisposable
{
private readonly Stopwatch _timer;
private readonly ILogger _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

namespace Corsinvest.AppHero.Core.Extensions;

public static class ModuleExtensions
public static class ModularityExtensions
{
#region Linq
public static IEnumerable<ModuleBase> IsType(this IEnumerable<ModuleBase> modules, ModuleType type) => modules.Where(a => a.Type == type);
public static IEnumerable<ModuleBase> IsCategory(this IEnumerable<ModuleBase> modules, string category) => modules.Where(a => a.Category == category);
public static IEnumerable<ModuleBase> IsEnabled(this IEnumerable<ModuleBase> modules) => modules.Where(a => a.Enabled);
public static IEnumerable<ModuleBase> IsConfigured(this IEnumerable<ModuleBase> modules) => modules.Where(a => a.Configurated);
public static IEnumerable<ModuleBase> Implements<T>(this IEnumerable<ModuleBase> modules) => modules.Where(a => typeof(T).IsAssignableFrom(a.GetType()));
public static IEnumerable<ModuleBase> NotImplements<T>(this IEnumerable<ModuleBase> modules) => modules.Where(a => !typeof(T).IsAssignableFrom(a.GetType()));
#endregion
}

public static string GetCategoryIcon(this IModularityService modularityService, string category)
=> modularityService.Categories.FirstOrDefault(a => a.Name == category)?.Icon + "";
}
1 change: 1 addition & 0 deletions src/Corsinvest.AppHero.Core/Helpers/ApplicationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Microsoft.AspNetCore.Components;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
Expand Down
27 changes: 16 additions & 11 deletions src/Corsinvest.AppHero.Core/Helpers/CryptographyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ public static string DecryptString(string encrypted, string? passphrase = null)
{
if (string.IsNullOrEmpty(encrypted)) { return string.Empty; }

var dataArray = Convert.FromBase64String(encrypted);

using var tDes = TripleDES.Create();
tDes.Mode = CipherMode.ECB;
tDes.Key = Encoding.UTF8.GetBytes(passphrase ?? Key);
tDes.Padding = PaddingMode.PKCS7;

using var cTransform = tDes.CreateDecryptor();
var resultArray = cTransform.TransformFinalBlock(dataArray, 0, dataArray.Length);
tDes.Clear();

var resultArray = Array.Empty<byte>();

try
{
var dataArray = Convert.FromBase64String(encrypted);

using var tDes = TripleDES.Create();
tDes.Mode = CipherMode.ECB;
tDes.Key = Encoding.UTF8.GetBytes(passphrase ?? Key);
tDes.Padding = PaddingMode.PKCS7;

using var cTransform = tDes.CreateDecryptor();
resultArray = cTransform.TransformFinalBlock(dataArray, 0, dataArray.Length);
tDes.Clear();
}
catch (Exception ex) { }
return Encoding.UTF8.GetString(resultArray);
}
}
2 changes: 1 addition & 1 deletion src/Corsinvest.AppHero.Core/Hubs/HubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task StartAsync()
.Build();

_hubConnection.ServerTimeout = TimeSpan.FromSeconds(30);
_hubConnection.On(SignalRConstants.ForceLogout, _authenticationService.Logout);
_hubConnection.On(SignalRConstants.ForceLogout, _authenticationService.LogoutAsync);
_hubConnection.On<string>(SignalRConstants.ConnectUser, (userId) =>
{
_sessionsInfoTracker.SetHubConnectionId(_hubConnection.ConnectionId!);
Expand Down
Loading

0 comments on commit e7f711d

Please sign in to comment.