NOTE: temp commit, started rolling back changes to auth system
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
e2ce6cbf37
commit
ce201207d4
13 changed files with 97 additions and 63 deletions
|
@ -27,15 +27,15 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
|||
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
//new Claim(ClaimTypes.Email, userSession.Email),
|
||||
new Claim(ClaimTypes.Name, userSession.UserID.ToString()),
|
||||
new Claim(ClaimTypes.Name, userSession.Email),
|
||||
new Claim(ClaimTypes.Role, userSession.Role)
|
||||
}, "CustomAuth"));
|
||||
return new AuthenticationState(claimsPrincipal);
|
||||
return await Task.FromResult(new AuthenticationState(claimsPrincipal));
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Returned Anon Auth due to err");
|
||||
return new AuthenticationState(_anonymous);
|
||||
Console.WriteLine("Resorting to Anon");
|
||||
return await Task.FromResult(new AuthenticationState(_anonymous));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
|||
await _sessionStorage.SetAsync("UserSession", session);
|
||||
claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
new Claim(ClaimTypes.Email, session.UserID.ToString()),
|
||||
new Claim(ClaimTypes.Email, session.Role)
|
||||
new Claim(ClaimTypes.Name, session.Email),
|
||||
new Claim(ClaimTypes.Role, session.Role)
|
||||
}));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</RadzenFormField>
|
||||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@reset Text="reset" ButtonStyle="ButtonStyle.Secondary" />
|
||||
<RadzenButton Click=@reset Text="reset" ButtonStyle="ButtonStyle.Secondary" ButtonType="ButtonType.Submit"/>
|
||||
<br/>
|
||||
</form>
|
||||
@if (msg != null)
|
||||
|
@ -55,7 +55,7 @@
|
|||
msg = "The token does not match the account.";
|
||||
return;
|
||||
}
|
||||
if (user.ResetPasswordExpiresAt == -1 || user.ResetPasswordToken == "-1")
|
||||
if (user.ResetPasswordExpiresAt < 0 || user.ResetPasswordToken == "-1")
|
||||
{
|
||||
msg = "There is currently no valid link to reset this accounts password.";
|
||||
return;
|
||||
|
@ -73,6 +73,6 @@
|
|||
await UsersRepository.updateUserAsync(user);
|
||||
|
||||
msg = "Your Password has been updated.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
</RadzenFormField>
|
||||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@login Text="login" ButtonStyle="ButtonStyle.Secondary" />
|
||||
<RadzenButton Click=@login Text="login" ButtonStyle="ButtonStyle.Secondary" ButtonType="ButtonType.Submit"/>
|
||||
<br/>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -34,7 +34,6 @@
|
|||
|
||||
private async Task login()
|
||||
{
|
||||
Console.WriteLine("loggin you in...");
|
||||
var user = await UsersRepository.getUserByEmailRawAsync(Email);
|
||||
if (user == null)
|
||||
{
|
||||
|
@ -42,10 +41,10 @@
|
|||
verified = false;
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("loggin you in...");
|
||||
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
||||
if (verified)
|
||||
{
|
||||
verified = true;
|
||||
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
|
||||
navManager.NavigateTo("/", true);
|
||||
|
@ -53,4 +52,5 @@
|
|||
}
|
||||
await js.InvokeVoidAsync("alert", $"Wrong Password");
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
<RadzenLabel Text="I am atleast 18 Years old." Component="is_18"/>
|
||||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@login Text="register" ButtonStyle="ButtonStyle.Secondary" />
|
||||
<RadzenButton Click=@login Text="register" ButtonStyle="ButtonStyle.Secondary" ButtonType="ButtonType.Submit"/>
|
||||
</form>
|
||||
<br/>
|
||||
<br/>
|
||||
|
@ -70,7 +70,7 @@
|
|||
LastUsedName = "Anonymous",
|
||||
BanReason = "Not banned",
|
||||
ConfirmedEmail = false,
|
||||
ResetPasswordExpiresAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 300000,
|
||||
ResetPasswordExpiresAt = -1,
|
||||
ConfirmEmailToken = TheManager.getmd5Hash(),
|
||||
ResetPasswordToken = "-1"
|
||||
};
|
||||
|
@ -88,13 +88,11 @@
|
|||
if (user == null)
|
||||
{
|
||||
await js.InvokeVoidAsync("alert", "User does not exist");
|
||||
verified = false;
|
||||
return;
|
||||
}
|
||||
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
||||
if (verified)
|
||||
{
|
||||
verified = true;
|
||||
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
|
||||
navManager.NavigateTo("/", true);
|
||||
|
@ -102,4 +100,5 @@
|
|||
}
|
||||
await js.InvokeVoidAsync("alert", $"Wrong Password");
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
</RadzenFormField>
|
||||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@resetPassword Text="Send reset Email" ButtonStyle="ButtonStyle.Secondary" />
|
||||
<RadzenButton Click=@resetPassword Text="Send reset email" ButtonStyle="ButtonStyle.Secondary" ButtonType="ButtonType.Submit"/>
|
||||
<br/>
|
||||
</form>
|
||||
@if (msg != null)
|
||||
|
@ -52,4 +52,5 @@
|
|||
$"https://bulletboards.xyz/sys/click/resetpw/{user.UserID}/{hash}");
|
||||
msg = "A reset email has been sent to the selected email, if that email is registered here. The link expires in 5 Minutes";
|
||||
}
|
||||
|
||||
}
|
|
@ -8,15 +8,36 @@
|
|||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<h3>YOU</h3>
|
||||
<h3>YOUR ACCOUNT</h3>
|
||||
<br/>
|
||||
<span>Email: @mail</span>
|
||||
<span>UserId: @userid</span>
|
||||
<br/>
|
||||
@if (u != null)
|
||||
{
|
||||
<span>Current email: @u.Email</span>
|
||||
<br/>
|
||||
}
|
||||
<span>Email: </span>
|
||||
<input type="email" id="email" @bind="newMail"/>
|
||||
<a @onclick="changeEmail" href="javascript:void(0)">[Change Email]</a>
|
||||
<form>
|
||||
<RadzenFormField Text="Enter new email address" Variant="Variant.Outlined">
|
||||
<RadzenTextBox @bind-Value="@newMail"/>
|
||||
</RadzenFormField>
|
||||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@changeEmail Text="Set Email" ButtonStyle="ButtonStyle.Secondary" ButtonType="ButtonType.Submit"/>
|
||||
<br/>
|
||||
</form>
|
||||
@if (msg != null)
|
||||
{
|
||||
<div>
|
||||
<span class="msg">@msg</span>
|
||||
</div>
|
||||
}
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="/sys/resetpw">[Click here to change your password]</a>
|
||||
<br/>
|
||||
<a href="/sys/resetpw">[Change Password]</a>
|
||||
<br/>
|
||||
<a href="/sys/logout">[Logout]</a>
|
||||
</Authorized>
|
||||
|
@ -28,8 +49,12 @@
|
|||
|
||||
@code {
|
||||
|
||||
private string mail { get; set; } = "";
|
||||
private string userid { get; set; } = "";
|
||||
private string newMail { get; set; }
|
||||
private string msg { get; set; }
|
||||
|
||||
private UserData u { get; set; }
|
||||
private string isMailConfirmedMsg { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
@ -37,7 +62,7 @@
|
|||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
if (user.User.Identity.IsAuthenticated)
|
||||
{
|
||||
mail = user.User.Identity.Name;
|
||||
userid = user.User.Identity.Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,18 +71,31 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
msg = "Could not find user.";
|
||||
return;
|
||||
}
|
||||
if (newMail == null || newMail == "" || !newMail.Contains("@"))
|
||||
if (newMail == null || newMail == "" || !newMail.Contains("@") || !newMail.Contains("."))
|
||||
{
|
||||
msg = "The new email is not valid.";
|
||||
return;
|
||||
}
|
||||
foundusr.Email = newMail;
|
||||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
foundusr.ConfirmedEmail = false;
|
||||
await UsersRepository.updateUserAsync(foundusr);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
u = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
isMailConfirmedMsg = u.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
}
|
0
ImageBoardServerApp/Pages/Accounts/UserPage.razor.css
Normal file
0
ImageBoardServerApp/Pages/Accounts/UserPage.razor.css
Normal file
|
@ -58,7 +58,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
return;
|
||||
|
@ -103,4 +103,5 @@
|
|||
await ReportsRepository.createReportAsync(reportData);
|
||||
js.InvokeVoidAsync("window.close");
|
||||
}
|
||||
|
||||
}
|
|
@ -31,9 +31,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
}
|
|
@ -121,7 +121,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr.Role != "User" || comment.UserID == foundusr.UserID)
|
||||
{
|
||||
await TheManager.deleteComment(comment);
|
||||
|
@ -186,7 +186,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr != null && (foundusr.Role != "User" || comment.UserID == foundusr.UserID))
|
||||
{
|
||||
canDel = true;
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
hasErr = true;
|
||||
|
@ -90,7 +90,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
hasErr = true;
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
hasErr = true;
|
||||
|
@ -97,7 +97,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
hasErr = true;
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByIdAsync(int.Parse(usr.Identity.Name));
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr.Role != "User" || post.UserID == foundusr.UserID)
|
||||
{
|
||||
await TheManager.deleteThread(post);
|
||||
|
|
Loading…
Reference in a new issue