limited_dev
dcc7634f5e
fix: modmenu now checks for the permission, you now have to be 18yo to access the boards, images now get deleted when deleting threads / posts, fixed grammar error in the register page, other fixed which i forget
91 lines
No EOL
3.1 KiB
Text
91 lines
No EOL
3.1 KiB
Text
@page "/sys/you"
|
|
@using ImageBoardServerApp.Auth
|
|
@using ImageBoardServerApp.Data.Repository
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
@inject NavigationManager navManager
|
|
|
|
<AuthorizeView>
|
|
<Authorized>
|
|
<h3>YOU</h3>
|
|
<br/>
|
|
<span>Email: @mail</span>
|
|
<br/>
|
|
<span>Email: </span>
|
|
<input type="email" id="email" @bind="newMail" />
|
|
<a @onclick="changeEmail" href="javascript:void(0)">[Change Email]</a>
|
|
<br/>
|
|
<span>Password: </span>
|
|
<input type="password" id="password" @bind="newPassword" />
|
|
<a @onclick="changePassword" href="javascript:void(0)">[Change Password]</a>
|
|
<br/>
|
|
<a @onclick="logout" href="javascript:void(0)">[Logout]</a>
|
|
</Authorized>
|
|
<NotAuthorized>
|
|
<span>You are not logged in.</span>
|
|
<a class="navbar-brand" href="/sys/login">Please login first.</a>
|
|
</NotAuthorized>
|
|
</AuthorizeView>
|
|
|
|
@code {
|
|
|
|
private string mail { get; set; } = "";
|
|
private string newMail { get; set; }
|
|
private string newPassword { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
if (user.User.Identity.IsAuthenticated)
|
|
{
|
|
mail = user.User.Identity.Name;
|
|
}
|
|
}
|
|
|
|
private async Task logout()
|
|
{
|
|
var customAuthStateProvider = (CustomAuthenticationStateProvider) authStateProvider;
|
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
|
navManager.NavigateTo("/", true);
|
|
}
|
|
|
|
private async Task changeEmail()
|
|
{
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
var usr = user.User;
|
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
|
if (foundusr == null)
|
|
{
|
|
return;
|
|
}
|
|
int userID = foundusr.UserID;
|
|
if (newMail == null || newMail == "" || !newMail.Contains("@"))
|
|
{
|
|
return;
|
|
}
|
|
foundusr.Email = newMail;
|
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
await UsersRepository.updateUserAsync(foundusr);
|
|
}
|
|
|
|
private async Task changePassword()
|
|
{
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
var usr = user.User;
|
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
|
if (foundusr == null)
|
|
{
|
|
return;
|
|
}
|
|
int userID = foundusr.UserID;
|
|
if (newPassword == null || newPassword == "")
|
|
{
|
|
return;
|
|
}
|
|
foundusr.Password = BCrypt.Net.BCrypt.HashPassword(newPassword);
|
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
await UsersRepository.updateUserAsync(foundusr);
|
|
}
|
|
} |