fix: started to fix the register and email confirm process
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
5282054cae
commit
2fa9ca826e
3 changed files with 58 additions and 27 deletions
|
@ -1,12 +1,12 @@
|
|||
@page "/sys/click/confirmmail/{userid}/{email}/{token}"
|
||||
@page "/sys/click/confirmmail/{userid}/{oldmail}/{proposedemail}/{token}"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
<h3>Confirm your Email</h3>
|
||||
|
||||
<span>@msg</span>
|
||||
<span>Confirmed email. Check Account Settings.</span>
|
||||
|
||||
@code {
|
||||
private string msg { get; set; } = "Loading...";
|
||||
private string msg { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
|
@ -14,36 +14,48 @@
|
|||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string email { get; set; }
|
||||
public string proposedemail { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string oldmail { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[Required]
|
||||
public string token { get; set; }
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnParametersSetAsync();
|
||||
|
||||
if (!int.TryParse(userid, out _))
|
||||
{
|
||||
msg = "malformed userid.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
|
||||
|
||||
if (user.ConfirmedEmail)
|
||||
return;
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
msg = "Could not find user.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.Email != email)
|
||||
if (user.Email != oldmail)
|
||||
{
|
||||
msg = "This email is not specified to this account.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.ProposedEmail != proposedemail)
|
||||
{
|
||||
msg = "This is not the specified new mail to this account.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.ConfirmEmailToken != token)
|
||||
{
|
||||
msg = "This token is not associated with the specified account.";
|
||||
|
|
|
@ -61,9 +61,11 @@
|
|||
return;
|
||||
}
|
||||
Console.WriteLine("Registering...");
|
||||
var hash = TheManager.getmd5Hash();
|
||||
UserData userToCreate = new UserData()
|
||||
{
|
||||
Email = Email,
|
||||
ProposedEmail = Email,
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(Password),
|
||||
Role = "User",
|
||||
TimeBanned = -1,
|
||||
|
@ -71,7 +73,7 @@
|
|||
BanReason = "Not banned",
|
||||
ConfirmedEmail = false,
|
||||
ResetPasswordExpiresAt = -1,
|
||||
ConfirmEmailToken = TheManager.getmd5Hash(),
|
||||
ConfirmEmailToken = hash,
|
||||
ResetPasswordToken = "-1"
|
||||
};
|
||||
if (await UsersRepository.getUserByEmailAsync(Email) != null)
|
||||
|
@ -80,9 +82,12 @@
|
|||
return;
|
||||
}
|
||||
|
||||
await UsersRepository.createUserAsync(userToCreate);
|
||||
int uid = await UsersRepository.createUserAsync(userToCreate);
|
||||
|
||||
Postman.sendMail(Email, "Confirm Email", "");
|
||||
Postman.sendMail(Email,
|
||||
"Confirm email",
|
||||
"Confirm you email:\n" +
|
||||
$"https://bulletboards.xyz/sys/click/confirmmail/{uid}/{Email}/{Email}/{hash}");
|
||||
|
||||
var user = await UsersRepository.getUserByEmailRawAsync(Email);
|
||||
if (user == null)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
@page "/sys/you"
|
||||
@using ImageBoardServerApp.Auth
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
@using ImageBoardServerApp.Util
|
||||
@inject AuthenticationStateProvider authStateProvider
|
||||
@inject NavigationManager navManager
|
||||
|
||||
|
@ -12,6 +13,11 @@
|
|||
<br/>
|
||||
<span>Email: @userid</span>
|
||||
<br/>
|
||||
@if (isMailConfirmedMsg != null)
|
||||
{
|
||||
<span>@isMailConfirmedMsg</span>
|
||||
<br/>
|
||||
}
|
||||
<form>
|
||||
<RadzenFormField Text="Enter new email address" Variant="Variant.Outlined">
|
||||
<RadzenTextBox @bind-Value="@newMail"/>
|
||||
|
@ -45,10 +51,9 @@
|
|||
|
||||
private string userid { get; set; } = "";
|
||||
private string newMail { get; set; }
|
||||
private string msg { get; set; }
|
||||
private string msg { get; set; } = "";
|
||||
|
||||
private UserData u { get; set; }
|
||||
private string isMailConfirmedMsg { get; set; }
|
||||
private string isMailConfirmedMsg { get; set; } = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
@ -58,10 +63,14 @@
|
|||
{
|
||||
userid = user.User.Identity.Name;
|
||||
}
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(user.User.Identity.Name);
|
||||
if (foundusr != null)
|
||||
isMailConfirmedMsg = foundusr.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
|
||||
}
|
||||
|
||||
private async Task changeEmail()
|
||||
{
|
||||
msg = "Checking...";
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
|
@ -71,6 +80,7 @@
|
|||
msg = "Could not find user.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (newMail == null || newMail == "" || !newMail.Contains("@") || !newMail.Contains("."))
|
||||
{
|
||||
msg = "The new email is not valid.";
|
||||
|
@ -82,20 +92,24 @@
|
|||
msg = "This email is already in use.";
|
||||
return;
|
||||
}
|
||||
|
||||
msg = "Generating...";
|
||||
var hash = TheManager.getmd5Hash();
|
||||
|
||||
foundusr.Email = newMail;
|
||||
foundusr.ConfirmEmailToken = hash;
|
||||
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);
|
||||
Postman.sendMail(newMail,
|
||||
"Confirm email",
|
||||
"Confirm you email:\n" +
|
||||
$"https://bulletboards.xyz/sys/click/confirmmail/{foundusr.UserID}/{foundusr.Email}/{newMail}/{hash}");
|
||||
|
||||
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(foundusr);
|
||||
navManager.NavigateTo("/sys/you", true, true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue