mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
feat: adds FastEndpoints endpoints, views and resources to the web project
This commit is contained in:
1 parent
733e174cac
commit
d3b1c681dc
341 files changed
+44018
-113
No files matched your search
@@ -0,0 +1,17 @@
|
||||
@*
|
||||
/auth/access-denied/
|
||||
*@
|
||||
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-55 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<div class="text-center w-100">
|
||||
<p class="invalid-feedback f-18 w-100"><b>@_localizer["NotAllowedToAccessResource"]</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,136 @@
|
||||
@*
|
||||
/auth/change-password/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Requests.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// 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
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
@model ChangePasswordRequest
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-55 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="change-password-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="text" name="username" autocomplete="username" value="@User.Identity!.Name" hidden />
|
||||
<div class="form-container">
|
||||
<!-- Current Password -->
|
||||
<div class="form-row" id="div-current-password">
|
||||
<div class="form-label">
|
||||
<label asp-for="CurrentPassword">@_localizer["CurrentPassword"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="CurrentPassword" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionCurrentPassword"]</small>
|
||||
</div>
|
||||
<!-- New Password -->
|
||||
<div class="form-row" id="div-new-password">
|
||||
<div class="form-label">
|
||||
<label asp-for="NewPassword">@_localizer["NewPassword"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="NewPassword" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionNewPassword"]</small>
|
||||
</div>
|
||||
<!-- New Password Confirm-->
|
||||
<div class="form-row" id="div-new-password-confirm">
|
||||
<div class="form-label">
|
||||
<label asp-for="NewPasswordConfirm">@_localizer["NewPasswordConfirm"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="NewPasswordConfirm" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionNewPasswordConfirm"]</small>
|
||||
</div>
|
||||
<div class="form-row" id="div-change-password-submit" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px">@_localizer["ChangePasswordKey"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="change-password-success" class="text-light-one w-100 hidden">@_localizer["PasswordChanged"]</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const form = document.getElementById('change-password-form');
|
||||
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
|
||||
const txtNewPassword = form.querySelector('[name="NewPassword"]');
|
||||
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
|
||||
|
||||
const changePasswordSuccess = document.getElementById('change-password-success');
|
||||
const divCurrentPassword = document.getElementById('div-current-password');
|
||||
const divNewPassword = document.getElementById('div-new-password');
|
||||
const divNewPasswordConfirm = document.getElementById('div-new-password-confirm');
|
||||
const divChangePasswordSubmit = document.getElementById('div-change-password-submit');
|
||||
|
||||
// perform the password change
|
||||
async function handleChangePasswordAsync() {
|
||||
const formData = {
|
||||
CurrentPassword: txtCurrentPassword.value,
|
||||
NewPassword: txtNewPassword.value,
|
||||
NewPasswordConfirm: txtNewPasswordConfirm.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.CHANGE_PASSWORD)', formData);
|
||||
if (data && data.isPasswordChanged === true) {
|
||||
changePasswordSuccess.classList.replace('hidden', 'block');
|
||||
divCurrentPassword.classList.add('hidden');
|
||||
divNewPassword.classList.add('hidden');
|
||||
divNewPasswordConfirm.classList.add('hidden');
|
||||
divChangePasswordSubmit.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleChangePasswordAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleChangePasswordAsync();
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
@*
|
||||
/auth/login/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Requests.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// 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
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
@model LoginRequest
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"> <!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style ="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="login-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="ReturnUrl" value="@ViewData["ReturnUrl"]" />
|
||||
<div class="form-container">
|
||||
<!-- Username -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">@_localizer["Username"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- Password -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Password">@_localizer["Password"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="Password" autocomplete="current-password" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button id="btn-recover-password" type="button" class="abort-button h-22px">@_localizer["RecoverPassword"]</button>
|
||||
<button id="btn-login" type="submit" class="confirm-button h-22px">@_localizer["LoginKey"]</button>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<div class="form-row mt-10 hidden" id="div-totp-code">
|
||||
<div class="form-label">
|
||||
<label asp-for="TotpCode">@_localizer["TotpCode"]</label>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="number" asp-for="TotpCode" autocomplete="one-time-code" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button type="submit" id="btn-validate-totp" class="confirm-button h-22px hidden">@_localizer["ValidateCode"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const form = document.getElementById('login-form');
|
||||
const returnUrlInput = form.querySelector('[name="ReturnUrl"]');
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
const divTotpCode = document.getElementById('div-totp-code');
|
||||
const btnLogin = document.getElementById('btn-login');
|
||||
const btnRecoverPassword = document.getElementById('btn-recover-password');
|
||||
const btnValidateTotp = document.getElementById('btn-validate-totp');
|
||||
|
||||
// perform the authentication
|
||||
async function handleLoginAsync() {
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
Password: txtPassword.value,
|
||||
TotpCode: txtTotpCode.value,
|
||||
ReturnUrl: returnUrlInput.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGIN)', formData);
|
||||
if (data && data.isTotpRequired === true) {
|
||||
txtUsername.disabled = true;
|
||||
txtPassword.disabled = true;
|
||||
btnLogin.disabled = true;
|
||||
btnRecoverPassword.disabled = true;
|
||||
divTotpCode.classList.replace('hidden', 'inline');
|
||||
btnValidateTotp.classList.replace('hidden', 'block');
|
||||
txtTotpCode.focus();
|
||||
}
|
||||
else if (data)
|
||||
window.location.href = data;
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleLoginAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleLoginAsync();
|
||||
};
|
||||
|
||||
// on recover password button click
|
||||
const handleBtnRecoverPasswordClick = function() {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.RECOVER_PASSWORD_VIEW)';
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
btnRecoverPassword.addEventListener('click', handleBtnRecoverPasswordClick);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
btnRecoverPassword.removeEventListener('click', handleBtnRecoverPasswordClick);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
@*
|
||||
/auth/recover-password/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Requests.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// 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
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
@model RecoverPasswordRequest
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="recover-password-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<div class="form-container">
|
||||
<!-- Username -->
|
||||
<div class="form-row" id="div-username">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">@_localizer["Username"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<div class="form-row" id="div-totp-code">
|
||||
<div class="form-label">
|
||||
<label asp-for="TotpCode">@_localizer["TotpCode"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="number" asp-for="TotpCode" autocomplete="one-time-code" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button id="btn-login" type="button" class="abort-button h-22px">@_localizer["BackToLogin"]</button>
|
||||
<button type="submit" id="btn-validate-totp" class="confirm-button h-22px">@_localizer["ValidateCode"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="recover-password-success" class="text-light-one w-100 hidden">@_localizer["PasswordTemporarilyReset"]</p>
|
||||
<button id="btn-redirect-login" type="submit" class="confirm-button h-22px hidden">@_localizer["Login"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const form = document.getElementById('recover-password-form');
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
const recoverPasswordSuccess = document.getElementById('recover-password-success');
|
||||
const btnRedirectLogin = document.getElementById('btn-redirect-login');
|
||||
const btnLogin = document.getElementById('btn-login');
|
||||
const btnValidateTotp = document.getElementById('btn-validate-totp');
|
||||
const divUsername = document.getElementById('div-username');
|
||||
const divTotpCode = document.getElementById('div-totp-code');
|
||||
|
||||
// perform the password recovery
|
||||
async function handleRecoverPasswordAsync() {
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
TotpCode: txtTotpCode.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.RECOVER_PASSWORD)', formData);
|
||||
if (data && data.isPasswordReset === true) {
|
||||
divUsername.classList.add('hidden');
|
||||
btnValidateTotp.classList.add('hidden');
|
||||
btnLogin.classList.add('hidden');
|
||||
divTotpCode.classList.add('hidden');
|
||||
btnRedirectLogin.classList.replace('hidden', 'inline');
|
||||
recoverPasswordSuccess.classList.replace('hidden', 'block');
|
||||
}
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleRecoverPasswordAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleRecoverPasswordAsync();
|
||||
};
|
||||
|
||||
// on login button click
|
||||
const handleBtnLoginClick = function() {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGIN_VIEW)';
|
||||
};
|
||||
|
||||
// on login redirect button click
|
||||
const handleBtnRedirectLoginClick = function() {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGIN_VIEW)';
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
btnLogin.addEventListener('click', handleBtnLoginClick);
|
||||
btnRedirectLogin.addEventListener('click', handleBtnRedirectLoginClick);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
btnLogin.removeEventListener('click', handleBtnLoginClick);
|
||||
btnRedirectLogin.removeEventListener('click', handleBtnRedirectLoginClick);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
@*
|
||||
/auth/register/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Requests.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
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
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
@model RegisterRequest
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form 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">@_localizer["AdminAccountRegistration"]</p>
|
||||
</div>
|
||||
}
|
||||
<!-- Username -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">@_localizer["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">@_localizer["DescriptionUsername"]</small>
|
||||
</div>
|
||||
<!-- Password -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Password">@_localizer["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">@_localizer["DescriptionPassword"]</small>
|
||||
</div>
|
||||
<!-- Password Confirm-->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="PasswordConfirm">@_localizer["PasswordConfirm"]</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">@_localizer["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>
|
||||
@_localizer["EnableTwoFactorAuthentication"]
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["Description2Fa"]</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span id="register-two-fa-attention" class="invalid-feedback w-95 text-center hidden">@_localizer["DisclaimerTwoFactor"]</span>
|
||||
</div>
|
||||
<div class="form-row" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px">@_localizer["RegisterKey"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="register-success" class="text-light-one w-100 hidden">@_localizer["AccountCreated"]</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">@_localizer["ScanTotpCode"]</p>
|
||||
@if (User?.Identity?.IsAuthenticated == false)
|
||||
{
|
||||
<button id="btn-login" type="button" class="confirm-button h-22px mx-auto mt-10 hidden">@_localizer["Login"]</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const form = document.getElementById('register-account-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 btnLogin = document.getElementById('btn-login');
|
||||
const spnTwoFaAttention = document.getElementById('register-two-fa-attention');
|
||||
const useTwoFaInput = document.getElementById('hidden-use-two-fa');
|
||||
|
||||
// perform the account registration
|
||||
async function handleRegisterAccountAsync() {
|
||||
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(WebRoutes.Authentication.REGISTER)', 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleRegisterAccountAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleRegisterAccountAsync();
|
||||
};
|
||||
|
||||
// on use 2FA change event
|
||||
const handleChkUse2FAChange = function() {
|
||||
const isChecked = this.checked;
|
||||
spnTwoFaAttention.classList.replace(
|
||||
isChecked ? 'inline' : 'hidden',
|
||||
isChecked ? 'hidden' : 'inline'
|
||||
);
|
||||
useTwoFaInput.value = isChecked.toString();
|
||||
};
|
||||
|
||||
// on login button click
|
||||
const handleBtnLoginClick = function() {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl(WebRoutes.Authentication.LOGIN_VIEW)';
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
chkUse2FA.addEventListener('click', handleChkUse2FAChange);
|
||||
btnLogin.addEventListener('click', handleBtnLoginClick);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
chkUse2FA.removeEventListener('click', handleChkUse2FAChange);
|
||||
btnLogin.removeEventListener('click', handleBtnLoginClick);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
Reference in new issue
Block a user