@page "/sys/you" @using ImageBoardServerApp.Auth @using ImageBoardServerApp.Data.Repository @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navManager

YOU


Email: @mail
Email: [Change Email]
Password: [Change Password]
[Logout]
You are not logged in. Please login first.
@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); } }