Refactor error modal into its own partial (#785)

* Refactor error modal into its own partial

* Fix unresolved error string in TwoFactorPartial

* Use tuple model instead of ViewData for error title and message

* Apply suggestions from code review
This commit is contained in:
koko 2023-06-08 00:01:59 -04:00 committed by GitHub
parent af6fdb457b
commit 77e46a0721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 94 deletions

View file

@ -12,12 +12,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
<form class="ui form" onsubmit="return onSubmit(this)" method="post">

View file

@ -29,14 +29,9 @@
<div class="ui middle aligned center aligned grid">
<form class="ui form" onsubmit="return onSubmit(this)" method="post">
@if (!string.IsNullOrWhiteSpace(Model.Error))
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
@Html.AntiForgeryToken()
<input type="hidden" id="redirect" name="redirect">

View file

@ -1,5 +1,4 @@
@page "/passwordReset"
@using LBPUnion.ProjectLighthouse.Configuration
@using LBPUnion.ProjectLighthouse.Localization.StringLists
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login.PasswordResetPage
@ -27,46 +26,41 @@
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p>@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
<div class="ui middle aligned center aligned grid">
<form onsubmit="return onSubmit(this)" method="post">
@Html.AntiForgeryToken()
<form onsubmit="return onSubmit(this)" method="post">
@Html.AntiForgeryToken()
<div class="column">
<h2 class="ui black image header centered">
<div class="content">
@Model.Title
</div>
</h2>
<div class="ui form">
<div class="ui field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" id="password" placeholder="Password" >
<input type="hidden" name="password" id="password-submit">
<i class="lock icon"></i>
<div class="column">
<h2 class="ui black image header centered">
<div class="content">
@Model.Title
</div>
</div>
</h2>
<div class="ui field">
<label>Confirm Password</label>
<div class="ui left icon input">
<input type="password" id="confirmPassword" placeholder="Confirm Password">
<input type="hidden" name="confirmPassword" id="confirmPassword-submit">
<i class="lock icon"></i>
<div class="ui form">
<div class="ui field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" id="password" placeholder="Password">
<input type="hidden" name="password" id="password-submit">
<i class="lock icon"></i>
</div>
</div>
<div class="ui field">
<label>Confirm Password</label>
<div class="ui left icon input">
<input type="password" id="confirmPassword" placeholder="Confirm Password">
<input type="hidden" name="confirmPassword" id="confirmPassword-submit">
<i class="lock icon"></i>
</div>
</div>
<input type="submit" value="Reset password" id="submit" class="ui fluid blue button"><br>
<div class="ui divider hidden"></div>
</div>
<input type="submit" value="Reset password" id="submit" class="ui fluid blue button"><br>
<div class="ui divider hidden"></div>
</div>
</div>
</form>
</form>
</div>

View file

@ -9,12 +9,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
@if (!string.IsNullOrWhiteSpace(Model.Status))

View file

@ -25,17 +25,14 @@
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p>@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
@if (Model.Username == null)
{
<p><b>@Model.Translate(RegisterStrings.UsernameNotice)</b></p>
<p>
<b>@Model.Translate(RegisterStrings.UsernameNotice)</b>
</p>
}
<form class="ui form" onsubmit="return onSubmit(this)" method="post">

View file

@ -12,12 +12,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
@await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
}
<input type="hidden" name="type" value="@((int)Model.Type)"/>

View file

@ -0,0 +1,8 @@
@model (string Title, string Message)
<div class="ui negative message">
<div class="header">
@Model.Title
</div>
<p style="white-space: pre-line">@Model.Message</p>
</div>

View file

@ -10,14 +10,9 @@
@Html.AntiForgeryToken()
<div class="digits" id="2fa">
@if (!string.IsNullOrWhiteSpace(error))
{
<div class="ui negative message">
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
}
{
@await Html.PartialAsync("Partials/ErrorModalPartial", ((string)Model.Translate(GeneralStrings.Error), error), ViewData)
}
<input type="text" pattern="\d*" maxlength="1" id="digit1"/>
<input type="text" pattern="\d*" maxlength="1" id="digit2"/>
<input type="text" pattern="\d*" maxlength="1" id="digit3" class="middleDigit"/>
@ -45,16 +40,16 @@
@if (allowBackupCodes)
{
<text>
document.getElementById("backup-link").addEventListener("click", function (){
let backupInput = document.getElementById("backup");
if (backupInput.style.display === "none"){
backupInput.style.display = "";
} else {
backupInput.style.display = "none";
}
});
</text>
<text>
document.getElementById("backup-link").addEventListener("click", function (){
let backupInput = document.getElementById("backup");
if (backupInput.style.display === "none"){
backupInput.style.display = "";
} else {
backupInput.style.display = "none";
}
});
</text>
}
document.querySelector(".digits").addEventListener("keydown", function(event){