feat: finished login system
This commit is contained in:
parent
7c0cef6f65
commit
08e54e7036
5 changed files with 21 additions and 16 deletions
|
@ -25,7 +25,8 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
||||||
return await Task.FromResult(new AuthenticationState(_anonymous));
|
return await Task.FromResult(new AuthenticationState(_anonymous));
|
||||||
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
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)
|
new Claim(ClaimTypes.Role, userSession.Role)
|
||||||
}, "CustomAuth"));
|
}, "CustomAuth"));
|
||||||
return await Task.FromResult(new AuthenticationState(claimsPrincipal));
|
return await Task.FromResult(new AuthenticationState(claimsPrincipal));
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
namespace ImageBoardServerApp.Auth;
|
|
||||||
|
|
||||||
public class UserSession
|
|
||||||
{
|
|
||||||
public string Email { get; set; }
|
|
||||||
public string Role { get; set; }
|
|
||||||
}
|
|
|
@ -1,24 +1,34 @@
|
||||||
@page "/"
|
@page "/"
|
||||||
@using ImageBoardServerApp.Data.Repository
|
@using ImageBoardServerApp.Data.Repository
|
||||||
|
@using ImageBoardServerApp.Auth
|
||||||
|
@inject AuthenticationStateProvider authStateProvider
|
||||||
|
|
||||||
<h1>BulletBoard</h1>
|
<h1>BulletBoard</h1>
|
||||||
<span>This is a simple Imageboard made in Razor.</span>
|
<span>This is a simple Imageboard made in Razor.</span>
|
||||||
<br/>
|
<br/>
|
||||||
<span>We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users.</span>
|
<span>We're currently hosting @amountOfPosts Threads with @amountOfComments Comments from @amountOfUsers Users.</span>
|
||||||
<br/>
|
<br/>
|
||||||
<div class="loginwrapper">
|
<span>@Details</span>
|
||||||
<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>
|
|
||||||
|
|
||||||
@code{
|
@code{
|
||||||
|
private string Details { get; set; }
|
||||||
|
|
||||||
private int amountOfPosts = -1;
|
private int amountOfPosts = -1;
|
||||||
private int amountOfComments = -1;
|
private int amountOfComments = -1;
|
||||||
private int amountOfUsers = -1;
|
private int amountOfUsers = -1;
|
||||||
protected override async Task OnInitializedAsync()
|
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();
|
var posts = await PostsRepository.getPostsAsync();
|
||||||
amountOfPosts = posts.Count;
|
amountOfPosts = posts.Count;
|
||||||
var comments = await CommentsRepository.getCommentsAsync();
|
var comments = await CommentsRepository.getCommentsAsync();
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<label for="password">Password:</label>
|
<label for="password">Password:</label>
|
||||||
<input type="password" id="password" @bind="Password" />
|
<input type="password" id="password" @bind="Password" />
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" href="javascript:void(0)" @onclick="login">Submit</button>
|
<a @onclick="login" href="javascript:void(0)">[Login]</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<div class="top-row px-4">
|
<div class="top-row px-4">
|
||||||
<a href="/faq">[FAQ]</a>
|
<a href="/faq">[FAQ]</a>
|
||||||
<a href="/rules">[Rules]</a>
|
<a href="/rules">[Rules]</a>
|
||||||
|
|
Loading…
Reference in a new issue