feat: finished email confirmation, finished Password Reset
!fix: The user auth system now uses the id, not the email Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
828f784fc8
commit
e8e97b2cd9
11 changed files with 89 additions and 20 deletions
|
@ -1,6 +1,61 @@
|
|||
@page "/sys/click/confirmmail/{userid}/{email}/{token}"
|
||||
<h3>Confirming your Email...</h3>
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
<h3>Confirm your Email</h3>
|
||||
|
||||
<span>@msg</span>
|
||||
|
||||
@code {
|
||||
private string msg { get; set; } = "Loading...";
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string userid { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string email { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string token { get; set; }
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await base.OnParametersSetAsync();
|
||||
|
||||
if (!int.TryParse(userid, out _))
|
||||
{
|
||||
msg = "This is not a valid id.";
|
||||
return;
|
||||
}
|
||||
|
||||
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
msg = "Could not find user.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.Email != email)
|
||||
{
|
||||
msg = "The email does not match.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.ConfirmEmailToken != token)
|
||||
{
|
||||
msg = "The token is not correct.";
|
||||
return;
|
||||
}
|
||||
|
||||
user.ConfirmEmailToken = "0";
|
||||
user.ConfirmedEmail = true;
|
||||
|
||||
await UsersRepository.updateUserAsync(user);
|
||||
|
||||
msg = "The email has been confirmed.";
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,18 @@
|
|||
<RadzenButton Click=@reset Text="reset" ButtonStyle="ButtonStyle.Secondary" />
|
||||
<br/>
|
||||
</form>
|
||||
@if (msg != null)
|
||||
{
|
||||
<span>@msg</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
private string Password { get; set; }
|
||||
|
||||
private string msg { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string userid { get; set; }
|
||||
|
@ -32,7 +38,7 @@
|
|||
|
||||
public async void reset()
|
||||
{
|
||||
if (int.TryParse(userid, out _))
|
||||
if (!int.TryParse(userid, out _))
|
||||
return;
|
||||
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
|
||||
if (user == null)
|
||||
|
@ -44,8 +50,11 @@
|
|||
Console.WriteLine("Resetting a password...");
|
||||
|
||||
user.Password = Password = BCrypt.Net.BCrypt.HashPassword(Password);
|
||||
user.ResetPasswordToken = "-1";
|
||||
|
||||
await UsersRepository.updateUserAsync(user);
|
||||
|
||||
|
||||
msg = "Your Password has been updated.";
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue