π IrbyImaging/Views/Employees/ResetPassword.cshtml Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model & Data Flow
- Key Functional Areas
- Client-Side Logic & Helpers
- Error Handling & Validation
- UML Diagrams
- Usage Examples
- Conclusion
π Overview & Purpose
The ResetPassword.cshtml Razor view provides an interactive interface for administrators to:
- π Search and select an employee.
- π΅οΈββοΈ Display employee personal details.
- β Verify identity via three security questions (Mobile, Email, SSN).
- π οΈ Confirm and submit a password reset transaction.
It is part of the Employees module and uses the _HDLayout master page.
βοΈ Dependencies & Technologies
| Category | Details |
|---|---|
| Framework | ASP.NET Core MVC (Razor Pages / MVC View) |
| Model | IrbyImaging.DomainClasses.Employee |
| Layout | Layout = "_HDLayout" |
| Client Libraries | jQuery 3.6.0, jQuery UI, Select2, Bootstrap 5 |
| Styling | Dropzone CSS (unused but referenced), custom <style> for spacing |
| Scripting | Plain JavaScript for form validation & interactivity |
| Icons | Bootstrap Glyphicons (glyphicon-chevron-left) |
π View Model & Data Flow
- @model:
@model IrbyImaging.DomainClasses.Employee - ViewBag Usage:
ViewBag.Employees(IEnumerable) for the search dropdown.ViewBag.SelectedEmployee(Employee) when an employee is selected.ViewBag.SubmissionError(string) to display server-side validation errors.
Data Flow:
- GET /Employees/ResetPassword β Render search form.
- GET /Employees/ResetPassword?EmployeeId=123 β Populate
SelectedEmployee, show details. - POST /Employees/ResetPassword β Receive hidden
employeeId,PWResetflag,PWResetDate, selected security question β Controller handles reset logic.
π Key Functional Areas
1. Employee Search
@if (ViewBag.SelectedEmployee == null) {
<form id="search-form" method="get">
<select id="EmployeeId" name="EmployeeId" asp-items="@ViewBag.Employees" class="form-select">
<option>Select an Employee</option>
</select>
<button type="submit" class="btn btn-primary">Search</button>
</form>
}
- Select2 plugin enhances the
<select>. - Submits via GET to load employee details.
2. Display Employee Details & Security Questions
Once ViewBag.SelectedEmployee is not null:
- Left Column:
- JDE Number, First, Middle, Last names (readonly inputs).
- Right Column:
- Three security attributes:
- Mobile Phone
- Work Email
- Last Four SSN
- Each has a checkbox overlay for selection.
- Rule: Only one security question may be selected at a time.
- Three security attributes:
<input type="text" value="@ViewBag.SelectedEmployee.WorkEmail" readonly />
<input type="checkbox" name="securityQuestionEmail" ... />
3. Password Reset Confirmation Form
<form method="post" asp-action="ResetPassword">
<input type="hidden" name="employeeId" value="@ViewBag.SelectedEmployee.EmployeeId" />
<!-- Confirm Checkbox -->
<input type="checkbox" id="PWReset" name="PWReset" value="true" />
<label for="PWReset">Confirm</label>
<!-- Date Picker -->
<input type="date" id="PWResetDate" name="PWResetDate" value="@DateTime.Now:yyyy-MM-dd" />
<button type="submit" id="submitBtn" class="btn btn-success" disabled>Submit</button>
</form>
- Confirmation: Admin must check βConfirmβ and pick a date.
- Submit button: Enabled only if:
- One security question is selected.
- Confirm checkbox is ticked.
- Date is provided.
π§ Client-Side Logic & Helpers
function handleSecurityQuestionChange(cb) {
// Disable other checkboxes when one is selected
['securityQuestionMobile', 'securityQuestionEmail', 'securityQuestionSSN']
.forEach(name => {
let other = document.getElementsByName(name)[0];
if (other && other !== cb) other.disabled = cb.checked;
});
validateForm();
}
function validateForm() {
let confirmChecked = document.getElementById("PWReset").checked;
let dateValue = document.getElementById("PWResetDate").value;
let secChecked = Array.from(document.querySelectorAll('input[name^="securityQuestion"]'))
.some(x => x.checked);
document.getElementById("submitBtn").disabled = !(confirmChecked && dateValue && secChecked);
}
- Event Listeners: Attached to each security checkbox, the confirm checkbox, and date input.
- Select2 Initialization:
$(document).ready(() => $('#EmployeeId').select2());
β οΈ Error Handling & Validation
- Server-Side:
- On error,
ViewBag.SubmissionErroris set. - Rendered as:
<div class="alert alert-danger">@ViewBag.SubmissionError</div>
- On error,
- Client-Side:
- Ensures form cannot be submitted until all prerequisites are met.
π UML Diagrams
Mermaid Sequence Diagram
sequenceDiagram
participant Admin
participant Browser
participant Server (MVC)
Admin->>Browser: GET /Employees/ResetPassword
Browser->>Server: Render View (Search Dropdown)
Admin->>Browser: Select Employee & Submit
Browser->>Server: GET /Employees/ResetPassword?EmployeeId=123
Server-->>Browser: Render View (Employee Details + Form)
Admin->>Browser: Check Security, Confirm & Pick Date
Browser->>Server: POST ResetPassword
Server-->>Browser: Redirect / Show Success or Error
Mermaid Class Diagram
classDiagram
class Employee {
+int EmployeeId
+string JdeNumber
+string FirstName
+string MiddleName
+string LastName
+string WorkEmail
+string PhoneNumberFromAssignedMobile
+string LastFourSSN
}
class ResetPasswordView {
+SelectList Employees
+Employee SelectedEmployee
+string SubmissionError
}
Employee <|-- ResetPasswordView
π‘ Usage Examples
-
Initial Visit
- Navigate to /Employees/ResetPassword.
- Search dropdown appears.
-
Select & Load Employee
- Choose an employee β Click Search.
- Details & security questions appear.
-
Confirm & Reset
- Tick one security checkbox.
- Tick Confirm.
- Pick a date.
- Click Submit.
Note: The controller action must validate the posted
employeeId,PWReset,PWResetDate, and onesecurityQuestionβ¦field.
π Conclusion
This Razor view implements a secure, step-by-step password reset workflow for employees. It leverages both server-side and rich client-side validation to ensure:
- Only authenticated admins perform resets.
- Employee identity is proven via one chosen security attribute.
- Administrators explicitly confirm and timestamp the reset.
With reusable components (Select2, Bootstrap) and clear UI sections, this view can be extended or themed according to your enterprise layout needs. π