121 lines
No EOL
3.7 KiB
Text
121 lines
No EOL
3.7 KiB
Text
@page "/sys/register"
|
|
@using ImageBoardServerApp.Util
|
|
@using ImageBoardServerApp.Data.Repository
|
|
@using ImageBoardServerApp.Auth
|
|
@inject IJSRuntime js
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
@inject NavigationManager navManager
|
|
|
|
<PageTitle>Register - BulletBoards</PageTitle>
|
|
|
|
<div class="login">
|
|
<form>
|
|
<RadzenFormField Text="Email" Variant="Variant.Outlined">
|
|
<RadzenTextBox @bind-Value="@Email"/>
|
|
</RadzenFormField>
|
|
<br/>
|
|
<RadzenFormField Text="Password" Variant="Variant.Outlined">
|
|
<RadzenPassword @bind-Value="@Password"/>
|
|
</RadzenFormField>
|
|
<br/>
|
|
<RadzenCheckBox @bind-Value=@is18 Name="is_18"/>
|
|
<RadzenLabel Text="I am atleast 18 Years old and I agree to the TOS and privacy policy." Component="is_18"/>
|
|
<br/>
|
|
<br/>
|
|
<RadzenButton Click=@login Text="register" ButtonStyle="ButtonStyle.Secondary"/>
|
|
</form>
|
|
<br/>
|
|
<br/>
|
|
<p>
|
|
Read the <a href="/sys/tos" target="_blank">TOS here</a> and the <a href="/sys/privacy" target="_blank">privacy policy here</a>.
|
|
</p>
|
|
<br/>
|
|
@if (msg != null)
|
|
{
|
|
<div>
|
|
<span class="msg">@msg</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
|
|
@code {
|
|
private string Email { get; set; }
|
|
private string Password { get; set; }
|
|
private bool is18 { get; set; }
|
|
|
|
public string msg { get; set; } = "";
|
|
|
|
private bool verified;
|
|
|
|
private async Task login()
|
|
{
|
|
msg = "Checking...";
|
|
if (!is18)
|
|
{
|
|
msg = "You have to be 18+ and agree to the TOS and Privacy Policy.";
|
|
return;
|
|
}
|
|
if (!Email.Contains("@") || !Email.Contains("."))
|
|
{
|
|
msg = "This Email address is not valid!";
|
|
return;
|
|
}
|
|
if (Password.Length < 6)
|
|
{
|
|
msg = "Your password has to be longer then 6 characters.";
|
|
return;
|
|
}
|
|
Console.WriteLine("Registering...");
|
|
msg = "Generating...";
|
|
var hash = TheManager.getmd5Hash();
|
|
msg = "Saving...";
|
|
UserData userToCreate = new UserData()
|
|
{
|
|
Email = Email,
|
|
ProposedEmail = Email,
|
|
Password = BCrypt.Net.BCrypt.HashPassword(Password),
|
|
Role = "User",
|
|
TimeBanned = -1,
|
|
LastUsedName = "Anonymous",
|
|
BanReason = "Not banned",
|
|
ConfirmedEmail = false,
|
|
ResetPasswordExpiresAt = -1,
|
|
ConfirmEmailToken = hash,
|
|
ResetPasswordToken = "-1"
|
|
};
|
|
if (await UsersRepository.getUserByEmailAsync(Email) != null)
|
|
{
|
|
msg = "This Email is already registered.";
|
|
return;
|
|
}
|
|
|
|
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. If this happens, please notify developer.");
|
|
return;
|
|
}
|
|
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
|
if (verified)
|
|
{
|
|
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(user);
|
|
navManager.NavigateTo("/", true);
|
|
return;
|
|
}
|
|
await js.InvokeVoidAsync("alert", $"Wrong Password");
|
|
}
|
|
|
|
} |