feat: finished login system

This commit is contained in:
limited_dev 2023-02-02 08:15:43 +01:00
parent 7c0cef6f65
commit 08e54e7036
5 changed files with 21 additions and 16 deletions

View file

@ -25,7 +25,8 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
return await Task.FromResult(new AuthenticationState(_anonymous));
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
{
new Claim(ClaimTypes.Email, userSession.Email),
//new Claim(ClaimTypes.Email, userSession.Email),
new Claim(ClaimTypes.Name, userSession.Email),
new Claim(ClaimTypes.Role, userSession.Role)
}, "CustomAuth"));
return await Task.FromResult(new AuthenticationState(claimsPrincipal));

View file

@ -1,7 +0,0 @@
namespace ImageBoardServerApp.Auth;
public class UserSession
{
public string Email { get; set; }
public string Role { get; set; }
}

View file

@ -1,24 +1,34 @@
@page "/"
@using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Auth
@inject AuthenticationStateProvider authStateProvider
<h1>BulletBoard</h1>
<span>This is a simple Imageboard made in Razor.</span>
<br/>
<span>We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users.</span>
<br/>
<div class="loginwrapper">
<span class="loginlink">If you are a member of the server team please log in</span>
<span> </span>
<a class="loginlink imblue" href="/login">[here]</a>
<span class="loginlink">.</span>
</div>
<span>@Details</span>
@code{
private string Details { get; set; }
private int amountOfPosts = -1;
private int amountOfComments = -1;
private int amountOfUsers = -1;
protected override async Task OnInitializedAsync()
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync();
if (user.User.Identity.IsAuthenticated)
{
var usr = user.User.Identity.Name;
Details = $"Welcome {usr}";
}
else
{
Details = "Please log in first.";
}
var posts = await PostsRepository.getPostsAsync();
amountOfPosts = posts.Count;
var comments = await CommentsRepository.getCommentsAsync();

View file

@ -17,7 +17,7 @@
<label for="password">Password:</label>
<input type="password" id="password" @bind="Password" />
</div>
<button type="submit" href="javascript:void(0)" @onclick="login">Submit</button>
<a @onclick="login" href="javascript:void(0)">[Login]</a>
</form>
</div>

View file

@ -11,6 +11,7 @@
</div>
<main>
<div class="top-row px-4">
<a href="/faq">[FAQ]</a>
<a href="/rules">[Rules]</a>