mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 21:11:10 +00:00
160 lines
7.5 KiB
Plaintext
160 lines
7.5 KiB
Plaintext
@*
|
|
/auth/register/
|
|
*@
|
|
|
|
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
|
@using Lumina.Presentation.Web.Common.Services
|
|
|
|
@{
|
|
string? registrationType = ViewData["RegistrationType"] as string;
|
|
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
|
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
|
}
|
|
|
|
@inject IUrlService _urlService
|
|
|
|
@model RegisterRequestModel
|
|
|
|
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
|
<div class="shine-effect"></div>
|
|
<form asp-controller="Auth" asp-action="Register" method="post" id="register-account-form" class="inline">
|
|
@Html.AntiForgeryToken()
|
|
<!-- section for determining registration type (regular user/admin) -->
|
|
<input type="hidden" name="RegistrationType" value="@registrationType" />
|
|
<div class="form-container">
|
|
@if (registrationType == "Admin")
|
|
{
|
|
<div class="form-row">
|
|
<p class="invalid-feedback w-95 text-center f-18">Admin account registration</p>
|
|
</div>
|
|
}
|
|
<!-- Username -->
|
|
<div class="form-row">
|
|
<div class="form-label">
|
|
<label asp-for="Username">Username</label>
|
|
<span class="mandatory-field">*</span>:
|
|
</div>
|
|
<div class="form-field">
|
|
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
|
</div>
|
|
<small class="form-label text-disabled form-description">DescriptionUsername</small>
|
|
</div>
|
|
<!-- Password -->
|
|
<div class="form-row">
|
|
<div class="form-label">
|
|
<label asp-for="Password">Password</label>
|
|
<span class="mandatory-field">*</span>:
|
|
</div>
|
|
<div class="form-field">
|
|
<input type="password" asp-for="Password" autocomplete="new-password" class="enlightenment-input" />
|
|
</div>
|
|
<small class="form-label text-disabled form-description">DescriptionPassword</small>
|
|
</div>
|
|
<!-- Password Confirm-->
|
|
<div class="form-row">
|
|
<div class="form-label">
|
|
<label asp-for="PasswordConfirm">Password Confirm</label>
|
|
<span class="mandatory-field">*</span>:
|
|
</div>
|
|
<div class="form-field">
|
|
<input type="password" asp-for="PasswordConfirm" autocomplete="new-password" class="enlightenment-input" />
|
|
</div>
|
|
<small class="form-label text-disabled form-description">DescriptionPasswordConfirm</small>
|
|
</div>
|
|
<!-- 2FA -->
|
|
<input type="hidden" id="hidden-use-two-fa" name="use2fa" value="true">
|
|
<div class="form-row">
|
|
<div class="form-field">
|
|
<label class="enlightenment-checkbox-label">
|
|
<input type="checkbox" asp-for="Use2fa" class="enlightenment-checkbox-hidden" value="true" checked/>
|
|
<span class="enlightenment-checkbox"></span>
|
|
Enable two factor authentication
|
|
</label>
|
|
</div>
|
|
<small class="form-label text-disabled form-description">Description2Fa</small>
|
|
</div>
|
|
<div class="form-row">
|
|
<span id="register-two-fa-attention" class="invalid-feedback w-95 text-center hidden">Password recovery is allowed only if two factor authentication is enabled!</span>
|
|
</div>
|
|
<div class="form-row" style="justify-content: center;">
|
|
<button type="submit" class="confirm-button h-22px w-100px">Register</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<!-- section registration success -->
|
|
<div class="text-center w-100">
|
|
<p id="register-success" class="text-light-one w-100 hidden">Account Created</p>
|
|
<img id="totp-image" class="w-200px h-200px h-align-m mx-auto mt-10 hidden" />
|
|
<p id="totp-message" class="text-light-one w-100 hidden">Scan Totp Code</p>
|
|
@if (User?.Identity?.IsAuthenticated == false)
|
|
{
|
|
<button id="btn-login" type="button" class="confirm-button h-22px w-80px mx-auto mt-10 hidden">Login</button>
|
|
}
|
|
</div>
|
|
</div>
|
|
@section Scripts {
|
|
<script type="text/javascript" data-form="@scriptId" defer>
|
|
const btnLogin = document.getElementById('btn-login');
|
|
document.getElementById('register-account-form').addEventListener('keypress', async (event) => {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault();
|
|
const form = event.target.closest('form');
|
|
await handleRegisterAccount(form);
|
|
}
|
|
});
|
|
|
|
document.getElementById('register-account-form').addEventListener('submit', async (event) => {
|
|
event.preventDefault();
|
|
await handleRegisterAccount(event.target);
|
|
});
|
|
|
|
async function handleRegisterAccount(form) {
|
|
const txtUsername = form.querySelector('[name="Username"]');
|
|
const txtPassword = form.querySelector('[name="Password"]');
|
|
const txtPasswordConfirm = form.querySelector('[name="PasswordConfirm"]');
|
|
const chkUse2FA = form.querySelector('[name="Use2fa"]');
|
|
const registerSuccess = document.getElementById('register-success');
|
|
const totpMessage = document.querySelector('#totp-message');
|
|
const totpImage = document.querySelector('#totp-image');
|
|
const formData = {
|
|
Username: txtUsername.value,
|
|
Password: txtPassword.value,
|
|
PasswordConfirm: txtPasswordConfirm.value,
|
|
Use2fa: chkUse2FA.checked,
|
|
RegistrationType: form.querySelector('[name="RegistrationType"]').value
|
|
};
|
|
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Register", "Auth")', formData);
|
|
if (data) {
|
|
txtUsername.value = '';
|
|
txtPassword.value = '';
|
|
txtPasswordConfirm.value = '';
|
|
form.classList.replace('inline', 'hidden');
|
|
registerSuccess.classList.replace('hidden', 'inline');
|
|
if (btnLogin)
|
|
btnLogin.classList.replace('hidden', 'block');
|
|
if (chkUse2FA.checked) {
|
|
totpMessage.classList.remove('hidden');
|
|
totpMessage.classList.add('block');
|
|
|
|
totpImage.classList.remove('hidden');
|
|
totpImage.classList.add('block');
|
|
totpImage.setAttribute('src', data.totpSecret);
|
|
}
|
|
}
|
|
}
|
|
document.querySelector('[name="Use2fa"]').addEventListener('change', function () {
|
|
const isChecked = this.checked;
|
|
document.getElementById('#register-two-fa-attention').classList.replace(
|
|
isChecked ? 'inline' : 'hidden',
|
|
isChecked ? 'hidden' : 'inline'
|
|
);
|
|
document.getElementById('#hidden-use-two-fa').value = isChecked.toString();
|
|
});
|
|
if (btnLogin) {
|
|
btnLogin.addEventListener('click', () => {
|
|
window.location.href = '@_urlService.GetAbsoluteUrl("Login", "Auth")';
|
|
});
|
|
}
|
|
</script>
|
|
}
|