πŸ“„ IrbyImaging/Views/Employees/ResetPassword.cshtml Documentation


πŸš€ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Flow
  4. Key Functional Areas
  5. Client-Side Logic & Helpers
  6. Error Handling & Validation
  7. UML Diagrams
  8. Usage Examples
  9. 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:

  1. GET /Employees/ResetPassword β†’ Render search form.
  2. GET /Employees/ResetPassword?EmployeeId=123 β†’ Populate SelectedEmployee, show details.
  3. POST /Employees/ResetPassword β†’ Receive hidden employeeId, PWReset flag, PWResetDate, selected security question β†’ Controller handles reset logic.

πŸ”‘ Key Functional Areas

@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:
      1. Mobile Phone
      2. Work Email
      3. Last Four SSN
    • Each has a checkbox overlay for selection.
    • Rule: Only one security question may be selected at a time.
<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:
    1. One security question is selected.
    2. Confirm checkbox is ticked.
    3. 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.SubmissionError is set.
    • Rendered as:
      <div class="alert alert-danger">@ViewBag.SubmissionError</div>
      
  • 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

  1. Initial Visit

    • Navigate to /Employees/ResetPassword.
    • Search dropdown appears.
  2. Select & Load Employee

    • Choose an employee β†’ Click Search.
    • Details & security questions appear.
  3. 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 one securityQuestion… 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. πŸš€