fix: fixed issues with email confirmation
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
3abc1ba7ab
commit
712ac3c020
4 changed files with 63 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
@page "/sys/click/confirmmail/{userid}/{oldmail}/{proposedemail}/{token}"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using ImageBoardServerApp.Data.Repository
|
||||
@inject NavigationManager navManager
|
||||
<h3>Confirm your Email</h3>
|
||||
|
||||
<span>Confirmed email. Check Account Settings.</span>
|
||||
|
@ -62,12 +63,17 @@
|
|||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("");
|
||||
|
||||
user.ConfirmEmailToken = "-1";
|
||||
user.ConfirmedEmail = true;
|
||||
|
||||
user.Email = proposedemail;
|
||||
|
||||
await UsersRepository.updateUserAsync(user);
|
||||
|
||||
msg = "The email has been confirmed.";
|
||||
navManager.NavigateTo("/sys/click/red/_sys_logout");
|
||||
}
|
||||
|
||||
}
|
|
@ -21,8 +21,8 @@
|
|||
<RadzenButton Click=@login Text="login" ButtonStyle="ButtonStyle.Secondary"/>
|
||||
<br/>
|
||||
</form>
|
||||
<a href="/sys/resetpw">Reset Password</a>
|
||||
</div>
|
||||
<a href="/sys/resetpw">Reset Password</a>
|
||||
|
||||
@code {
|
||||
private bool verified;
|
||||
|
|
|
@ -27,7 +27,12 @@
|
|||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<span class="msg">@msg</span>
|
||||
@if (msg != null)
|
||||
{
|
||||
<div>
|
||||
<span class="msg">@msg</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -42,6 +47,7 @@
|
|||
|
||||
private async Task login()
|
||||
{
|
||||
msg = "Checking...";
|
||||
if (!is18)
|
||||
{
|
||||
msg = "You have to be atleast 18 years old to register.";
|
||||
|
@ -58,7 +64,9 @@
|
|||
return;
|
||||
}
|
||||
Console.WriteLine("Registering...");
|
||||
msg = "Generating...";
|
||||
var hash = TheManager.getmd5Hash();
|
||||
msg = "Saving...";
|
||||
UserData userToCreate = new UserData()
|
||||
{
|
||||
Email = Email,
|
||||
|
@ -81,15 +89,19 @@
|
|||
|
||||
int uid = await UsersRepository.createUserAsync(userToCreate);
|
||||
|
||||
msg = "Sending....";
|
||||
|
||||
Postman.sendMail(Email,
|
||||
"Confirm email",
|
||||
"Confirm you email:\n" +
|
||||
$"https://bulletboards.xyz/sys/click/confirmmail/{uid}/{Email}/{Email}/{hash}");
|
||||
|
||||
msg = "Done. Check email.";
|
||||
|
||||
var user = await UsersRepository.getUserByEmailRawAsync(Email);
|
||||
if (user == null)
|
||||
{
|
||||
await js.InvokeVoidAsync("alert", "User does not exist");
|
||||
await js.InvokeVoidAsync("alert", "User does not exist. If this happens, please notify developer.");
|
||||
return;
|
||||
}
|
||||
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<br/>
|
||||
<br/>
|
||||
<RadzenButton Click=@changeEmail Text="Set Email" ButtonStyle="ButtonStyle.Secondary"/>
|
||||
<RadzenButton Click=@resendEmail Text="Resend Email" ButtonStyle="ButtonStyle.Secondary"></RadzenButton>
|
||||
<br/>
|
||||
</form>
|
||||
@if (msg != null)
|
||||
|
@ -72,6 +73,43 @@
|
|||
isMailConfirmedMsg = foundusr.ConfirmedEmail ? "Email is confirmed" : "Email is NOT confirmed";
|
||||
}
|
||||
|
||||
|
||||
private async Task resendEmail()
|
||||
{
|
||||
msg = "Checking...";
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
var usr = user.User;
|
||||
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
||||
if (foundusr == null)
|
||||
{
|
||||
msg = "Could not find user.";
|
||||
return;
|
||||
}
|
||||
|
||||
UserData u2 = await UsersRepository.getUserByEmailRawAsync(newMail);
|
||||
if (u2 != null)
|
||||
{
|
||||
msg = "This email is already in use.";
|
||||
return;
|
||||
}
|
||||
|
||||
msg = "Generating...";
|
||||
var hash = TheManager.getmd5Hash();
|
||||
|
||||
foundusr.ConfirmEmailToken = hash;
|
||||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
foundusr.ConfirmedEmail = false;
|
||||
|
||||
msg = "Sending...";
|
||||
Postman.sendMail(foundusr.ProposedEmail,
|
||||
"Confirm email",
|
||||
"Confirm you email:\n" +
|
||||
$"https://bulletboards.xyz/sys/click/confirmmail/{foundusr.UserID}/{foundusr.Email}/{foundusr.ProposedEmail}/{hash}");
|
||||
await UsersRepository.updateUserAsync(foundusr);
|
||||
msg = "Done. Check mail";
|
||||
}
|
||||
|
||||
private async Task changeEmail()
|
||||
{
|
||||
msg = "Checking...";
|
||||
|
@ -100,12 +138,13 @@
|
|||
msg = "Generating...";
|
||||
var hash = TheManager.getmd5Hash();
|
||||
|
||||
foundusr.Email = newMail;
|
||||
foundusr.ProposedEmail = newMail;
|
||||
foundusr.ConfirmEmailToken = hash;
|
||||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
foundusr.ConfirmedEmail = false;
|
||||
await UsersRepository.updateUserAsync(foundusr);
|
||||
|
||||
msg = "Sending...";
|
||||
Postman.sendMail(newMail,
|
||||
"Confirm email",
|
||||
"Confirm you email:\n" +
|
||||
|
@ -113,7 +152,8 @@
|
|||
|
||||
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(foundusr);
|
||||
navManager.NavigateTo("/sys/you", true, true);
|
||||
msg = "Done. Check mail";
|
||||
navManager.NavigateTo("/sys/click/red/_sys_you", true, true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue