!feat: removed the direct editing of passwords

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-12 12:25:48 +02:00
parent 22e9090057
commit 9c93f9d10c

View file

@ -16,9 +16,7 @@
<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>
<a href="/sys/resetpw">[Change Password]</a>
<br/>
<a href="/sys/logout">[Logout]</a>
</Authorized>
@ -32,7 +30,6 @@
private string mail { get; set; } = "";
private string newMail { get; set; }
private string newPassword { get; set; }
protected override async Task OnInitializedAsync()
{
@ -63,24 +60,4 @@
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.getUserByIdAsync(int.Parse(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);
}
}