Skip to content

Commit ccc0afe

Browse files
author
MPCoreDeveloper
committed
update nuget packages , added sharpdispatch as standalone package
1 parent 62c5000 commit ccc0afe

File tree

113 files changed

+3265
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+3265
-288
lines changed

Examples/CQRS/OrderManagement.CqrsDemo/OrderManagement.CqrsDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
24+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
2525
</ItemGroup>
2626

2727
</Project>

Examples/Desktop/SharpCoreDB.Examples.TimeSeries/SharpCoreDB.Examples.TimeSeries.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
<ItemGroup>
2424
<PackageReference Include="Serilog" Version="4.3.1" />
25-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
26-
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="10.0.5" />
25+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.6" />
26+
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="10.0.6" />
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
30+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
3131
</ItemGroup>
3232

3333
</Project>

Examples/EventSourcing/OrderManagement.PersistentDemo/OrderManagement.PersistentDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
31+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
3232
</ItemGroup>
3333

3434
</Project>

Examples/EventSourcing/OrderManagement.Tests/OrderManagement.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<Compile Include="..\OrderManagement\OrderAggregate.cs" Link="OrderAggregate.cs" />
3535
</ItemGroup>
3636
<ItemGroup>
37-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
37+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
3838
</ItemGroup>
3939

4040
</Project>

Examples/EventSourcing/OrderManagement/OrderManagement.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
24+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
2525
</ItemGroup>
2626

2727
</Project>

Examples/Web/Orchardcore/SharpCoreDb.Orchardcore/SharpCoreDb.Orchardcore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
2424
<PackageReference Include="MimeKit" Version="4.15.1" />
2525
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.4.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.5" />
27-
<PackageReference Include="AWSSDK.Core" Version="4.0.3.28" />
26+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.6" />
27+
<PackageReference Include="AWSSDK.Core" Version="4.0.3.29" />
2828
</ItemGroup>
2929

3030
<ItemGroup Condition="'$(UseLocalSharpCoreDbSources)' == 'true'">
@@ -40,7 +40,7 @@
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.201" />
43+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.202" />
4444
</ItemGroup>
4545

4646
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace SharpCoreDB.CrudApp.Configuration;
2+
3+
/// <summary>
4+
/// Represents SharpCoreDB storage settings for the MVC demo application.
5+
/// </summary>
6+
public sealed class SharpCoreDbAppOptions
7+
{
8+
/// <summary>Configuration section name.</summary>
9+
public const string SectionName = "SharpCoreDb";
10+
11+
/// <summary>Gets or sets single-file database path.</summary>
12+
public string DatabaseFilePath { get; set; } = "App_Data/sharpcore-crud.scdb";
13+
14+
/// <summary>Gets or sets encryption password used to derive AES-256-GCM key.</summary>
15+
public string EncryptionPassword { get; set; } = string.Empty;
16+
17+
/// <summary>Gets or sets SharpCoreDB master password.</summary>
18+
public string MasterPassword { get; set; } = string.Empty;
19+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
using System.Security.Claims;
2+
using Microsoft.AspNetCore.Authentication;
3+
using Microsoft.AspNetCore.Authentication.Cookies;
4+
using Microsoft.AspNetCore.Mvc;
5+
using SharpCoreDB.CrudApp.Models.ViewModels;
6+
using SharpCoreDB.Identity;
7+
using SharpCoreDB.Identity.Entities;
8+
using SharpCoreDB.Identity.Options;
9+
10+
namespace SharpCoreDB.CrudApp.Controllers;
11+
12+
/// <summary>
13+
/// Handles authentication actions backed by SharpCoreDB.Identity.
14+
/// </summary>
15+
public sealed class AccountController(SharpCoreDbIdentityService identityService) : Controller
16+
{
17+
private readonly SharpCoreDbIdentityService _identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
18+
19+
/// <summary>
20+
/// Shows the registration page.
21+
/// </summary>
22+
[HttpGet]
23+
public IActionResult Register() => View(new RegisterViewModel());
24+
25+
/// <summary>
26+
/// Creates a new user account.
27+
/// </summary>
28+
[HttpPost]
29+
[ValidateAntiForgeryToken]
30+
public async Task<IActionResult> Register(RegisterViewModel model, CancellationToken cancellationToken)
31+
{
32+
ArgumentNullException.ThrowIfNull(model);
33+
34+
if (!ModelState.IsValid)
35+
{
36+
return View(model);
37+
}
38+
39+
try
40+
{
41+
var user = new SharpCoreUser
42+
{
43+
UserName = model.UserName,
44+
NormalizedUserName = string.Empty,
45+
Email = model.Email,
46+
NormalizedEmail = string.Empty,
47+
PasswordHash = string.Empty,
48+
FullName = model.FullName,
49+
BirthDate = model.BirthDate,
50+
IsActive = true,
51+
EmailConfirmed = true
52+
};
53+
54+
var createdUser = await _identityService.CreateUserAsync(user, model.Password, cancellationToken).ConfigureAwait(false);
55+
await SignInUserAsync(createdUser, isPersistent: false).ConfigureAwait(false);
56+
57+
TempData["SuccessMessage"] = "Registration successful.";
58+
return RedirectToAction("Index", "Products");
59+
}
60+
catch (ArgumentException ex)
61+
{
62+
ModelState.AddModelError(string.Empty, ex.Message);
63+
return View(model);
64+
}
65+
catch (InvalidOperationException ex)
66+
{
67+
ModelState.AddModelError(string.Empty, ex.Message);
68+
return View(model);
69+
}
70+
}
71+
72+
/// <summary>
73+
/// Shows the login page.
74+
/// </summary>
75+
[HttpGet]
76+
public IActionResult Login(string? returnUrl = null)
77+
{
78+
ViewData[nameof(returnUrl)] = returnUrl;
79+
return View(new LoginViewModel());
80+
}
81+
82+
/// <summary>
83+
/// Authenticates an existing account.
84+
/// </summary>
85+
[HttpPost]
86+
[ValidateAntiForgeryToken]
87+
public async Task<IActionResult> Login(LoginViewModel model, string? returnUrl = null, CancellationToken cancellationToken = default)
88+
{
89+
ArgumentNullException.ThrowIfNull(model);
90+
91+
if (!ModelState.IsValid)
92+
{
93+
ViewData[nameof(returnUrl)] = returnUrl;
94+
return View(model);
95+
}
96+
97+
var signInResult = await _identityService.PasswordSignInAsync(model.UserName, model.Password, true, cancellationToken).ConfigureAwait(false);
98+
if (!signInResult.Succeeded)
99+
{
100+
if (signInResult.IsLockedOut)
101+
{
102+
ModelState.AddModelError(string.Empty, "User is temporarily locked out.");
103+
}
104+
else if (signInResult.IsNotAllowed)
105+
{
106+
ModelState.AddModelError(string.Empty, "User is not allowed to sign in.");
107+
}
108+
else
109+
{
110+
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
111+
}
112+
113+
ViewData[nameof(returnUrl)] = returnUrl;
114+
return View(model);
115+
}
116+
117+
var user = await _identityService.FindByNameAsync(model.UserName, cancellationToken).ConfigureAwait(false);
118+
if (user is null)
119+
{
120+
ModelState.AddModelError(string.Empty, "User not found.");
121+
ViewData[nameof(returnUrl)] = returnUrl;
122+
return View(model);
123+
}
124+
125+
await SignInUserAsync(user, model.RememberMe).ConfigureAwait(false);
126+
127+
if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
128+
{
129+
return Redirect(returnUrl);
130+
}
131+
132+
return RedirectToAction("Index", "Products");
133+
}
134+
135+
/// <summary>
136+
/// Signs out the current user.
137+
/// </summary>
138+
[HttpPost]
139+
[ValidateAntiForgeryToken]
140+
public async Task<IActionResult> Logout(CancellationToken cancellationToken)
141+
{
142+
cancellationToken.ThrowIfCancellationRequested();
143+
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme).ConfigureAwait(false);
144+
return RedirectToAction("Index", "Home");
145+
}
146+
147+
private async Task SignInUserAsync(SharpCoreUser user, bool isPersistent)
148+
{
149+
var claims = new List<Claim>
150+
{
151+
new(ClaimTypes.NameIdentifier, user.Id.ToString("D")),
152+
new(ClaimTypes.Name, user.UserName),
153+
new(ClaimTypes.Email, user.Email ?? string.Empty)
154+
};
155+
156+
var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));
157+
158+
await HttpContext.SignInAsync(
159+
CookieAuthenticationDefaults.AuthenticationScheme,
160+
principal,
161+
new AuthenticationProperties { IsPersistent = isPersistent })
162+
.ConfigureAwait(false);
163+
}
164+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using SharpCoreDB.CrudApp.Services;
4+
5+
namespace SharpCoreDB.CrudApp.Controllers;
6+
7+
/// <summary>
8+
/// Provides development-only administrative actions.
9+
/// </summary>
10+
[Authorize]
11+
public sealed class AdminController(IWebHostEnvironment environment, SharpCoreCrudDatabaseService databaseService) : Controller
12+
{
13+
private readonly IWebHostEnvironment _environment = environment ?? throw new ArgumentNullException(nameof(environment));
14+
private readonly SharpCoreCrudDatabaseService _databaseService = databaseService ?? throw new ArgumentNullException(nameof(databaseService));
15+
16+
/// <summary>
17+
/// Displays reset confirmation page.
18+
/// </summary>
19+
[HttpGet]
20+
public IActionResult ResetDatabase()
21+
{
22+
if (!IsDevelopmentAdmin())
23+
{
24+
return NotFound();
25+
}
26+
27+
return View();
28+
}
29+
30+
/// <summary>
31+
/// Resets the encrypted database and seeds baseline records.
32+
/// </summary>
33+
[HttpPost]
34+
[ValidateAntiForgeryToken]
35+
public async Task<IActionResult> ResetDatabaseConfirmed(CancellationToken cancellationToken)
36+
{
37+
if (!IsDevelopmentAdmin())
38+
{
39+
return NotFound();
40+
}
41+
42+
await _databaseService.ResetDatabaseAsync(seedAdminUser: true, cancellationToken).ConfigureAwait(false);
43+
TempData["SuccessMessage"] = "Database reset completed. Default admin account was seeded.";
44+
return RedirectToAction(nameof(ResetDatabase));
45+
}
46+
47+
private bool IsDevelopmentAdmin()
48+
{
49+
if (!_environment.IsDevelopment())
50+
{
51+
return false;
52+
}
53+
54+
return string.Equals(User.Identity?.Name, "admin", StringComparison.OrdinalIgnoreCase);
55+
}
56+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace SharpCoreDB.CrudApp.Controllers;
4+
5+
/// <summary>
6+
/// Serves the home page for the CRUD showcase.
7+
/// </summary>
8+
public sealed class HomeController : Controller
9+
{
10+
/// <summary>
11+
/// Displays the home page.
12+
/// </summary>
13+
public IActionResult Index() => View();
14+
15+
/// <summary>
16+
/// Displays a generic error view.
17+
/// </summary>
18+
public IActionResult Error() => View();
19+
}

0 commit comments

Comments
 (0)