adding hidden basic asp.net core backend (#30)

Base functionality:

    DB
    email sending
    user registration & login
    storing new characters and reading them back

Notes:

    Functionality is "hidden" with no links pointing to it.
    Most pages are scaffolded and not reviewed at all :(
    local Dev db setup is pushed to git
    NO local email setup :(
This commit is contained in:
2023-12-19 19:03:57 +01:00
committed by GitHub
parent 19b002ff24
commit 7bb7ab6f13
154 changed files with 39394 additions and 1325 deletions
@@ -0,0 +1,41 @@
using Kemkas.Web.Db.Models;
using Microsoft.AspNetCore.Identity;
namespace Kemkas.Web.Services.Identity;
public interface ICurrentUserService
{
public Task<ApplicationUser?> GetCurrentUser();
public Task<ApplicationUser> GetCurrentUserOrThrow();
}
public class CurrentUserService(
IHttpContextAccessor httpContextAccessor,
UserManager<ApplicationUser> userManager
) : ICurrentUserService
{
private ApplicationUser? _user;
public async Task<ApplicationUser?> GetCurrentUser()
{
if (_user is not null)
{
return _user;
}
var userName = httpContextAccessor.HttpContext?.User.Identity?.Name;
if (userName is null)
{
return null;
}
_user = await userManager.FindByNameAsync(userName);
return _user;
}
public async Task<ApplicationUser> GetCurrentUserOrThrow()
{
return await GetCurrentUser() ?? throw new InvalidOperationException("no current user!");
}
}