Skip to content

Commit

Permalink
Tidy up comments and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew committed Nov 29, 2024
1 parent 92827c9 commit fca63a7
Show file tree
Hide file tree
Showing 31 changed files with 1,193 additions and 104 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/_ReSharper.Caches/


do-not-commit.txt
18 changes: 18 additions & 0 deletions .idea/.idea.SecureDesignProject/.idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.SecureDesignProject/.idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.SecureDesignProject/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@

namespace SecureDesignProject.Controllers;

/// <summary>
/// Controller responsible for handling authentication-related actions such as login, registration, and logout.
/// </summary>
public class AuthController(ILogger<HomeController> logger, AuthService authService) : Controller
{

/// <summary>
/// Displays the login page to the user.
/// </summary>
/// <returns>A ViewResult displaying the login page.</returns>

public IActionResult Login()
{
TempData["hideLogout"] = true;

return View();
}

/// <summary>
/// Displays the registration page to the user.
/// </summary>
/// <returns>A ViewResult displaying the registration page.</returns>
public IActionResult Register()
{
TempData["hideLogout"] = true;

return View();
}

/// <summary>
/// Logs out the user by invalidating their session and removing the session cookie.
/// </summary>
/// <returns>Redirects to the Login Page.</returns>
public IActionResult Logout()
{
var sessionCookie = Request.GetSessionCookie();
Expand All @@ -39,6 +56,13 @@ public IActionResult Logout()
return RedirectToAction("Login", "Auth");
}

/// <summary>
/// Handles the login request by validating credentials and setting a session cookie upon success.
/// </summary>
/// <param name="loginDetails">The login details submitted by the user (email and password).</param>
/// <returns>
/// On success, redirects to the home page; otherwise, redisplays the login page with an error message.
/// </returns>
[HttpPost]
public IActionResult Login([FromForm] LoginDetails loginDetails)
{
Expand All @@ -57,6 +81,13 @@ public IActionResult Login([FromForm] LoginDetails loginDetails)
return RedirectToAction("Index", "Home");
}

/// <summary>
/// Handles the registration request by creating a new account and logging the user in upon success.
/// </summary>
/// <param name="registerDetails">The registration details submitted by the user.</param>
/// <returns>
/// On success, redirects to the home page; otherwise, redisplays the registration page with an error message.
/// </returns>
[HttpPost]
public IActionResult Register([FromForm] RegisterDetails registerDetails)
{
Expand All @@ -75,6 +106,10 @@ public IActionResult Register([FromForm] RegisterDetails registerDetails)
return RedirectToAction("Index", "Home");
}

/// <summary>
/// Displays an error page for unhandled exceptions or issues.
/// </summary>
/// <returns>A ViewResult displaying the error page with error details.</returns>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
Expand Down
63 changes: 63 additions & 0 deletions Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

namespace SecureDesignProject.Controllers;

/// <summary>
/// Controller responsible for handling dashboard functionality for patients and caregivers.
/// </summary>
public class DashboardController(PatientService patientService, CaregiverService caregiverService) : Controller
{
/// <summary>
/// Displays patient-specific dashboard information.
/// </summary>
/// <returns>A ViewResult containing patient information or redirects to an error page if not found.</returns>
public IActionResult Patient()
{
var patient = patientService.GetPatientInfoByAccountId(HttpContext.GetAccountId());
Expand All @@ -17,6 +24,10 @@ public IActionResult Patient()
return View(patient);
}

/// <summary>
/// Displays caregiver-specific dashboard information.
/// </summary>
/// <returns>A ViewResult containing caregiver overview or redirects to an error page if not found.</returns>
public IActionResult Caregiver()
{
var caregiverOverview = caregiverService.GetCaregiverOverview(HttpContext.GetAccountId());
Expand All @@ -27,6 +38,11 @@ public IActionResult Caregiver()
return View(caregiverOverview);
}

/// <summary>
/// Displays patient information for a specific patient, intended for caregiver view.
/// </summary>
/// <param name="patientId">The unique identifier of the patient.</param>
/// <returns>A ViewResult containing the patient's information.</returns>
[Route("dashboard/caregiverView/{patientId:guid}")]
public IActionResult CaregiverView([FromRoute] Guid patientId)
{
Expand All @@ -35,12 +51,23 @@ public IActionResult CaregiverView([FromRoute] Guid patientId)
return View(patientInfo);
}

/// <summary>
/// Displays the update address form for the logged-in patient.
/// </summary>
/// <returns>A ViewResult containing the patient's address.</returns>
public IActionResult UpdateAddress()
{
var address = patientService.GetAddressByAccountId(HttpContext.GetAccountId());
return View(address);
}

/// <summary>
/// Processes an update address request for the logged-in patient.
/// </summary>
/// <param name="address">The updated address information.</param>
/// <returns>
/// Redirects to the patient dashboard if successful; otherwise, redisplays the form with an error message.
/// </returns>
[HttpPost]
public IActionResult UpdateAddress(Address address)
{
Expand All @@ -55,6 +82,11 @@ public IActionResult UpdateAddress(Address address)
return RedirectToAction("Patient");
}

/// <summary>
/// Displays the update appointment form for a specific appointment.
/// </summary>
/// <param name="appointmentId">The unique identifier of the appointment.</param>
/// <returns>A ViewResult containing appointment information.</returns>
[Route("dashboard/updateAppointment/{appointmentId:guid}")]
public IActionResult UpdateAppointment([FromRoute] Guid appointmentId)
{
Expand All @@ -64,6 +96,11 @@ public IActionResult UpdateAppointment([FromRoute] Guid appointmentId)

}

/// <summary>
/// Creates a new appointment record and redirects to the update form.
/// </summary>
/// <param name="patientId">The unique identifier of the patient.</param>
/// <returns>A RedirectToRouteResult pointing to the update appointment form.</returns>
[Route("dashboard/updateAppointment/new/{patientId:guid}")]
public IActionResult NewAppointment([FromRoute] Guid patientId)
{
Expand All @@ -72,6 +109,14 @@ public IActionResult NewAppointment([FromRoute] Guid patientId)

}

/// <summary>
/// Processes an update appointment request.
/// </summary>
/// <param name="appointmentId">The unique identifier of the appointment being updated.</param>
/// <param name="appointment">The updated appointment information.</param>
/// <returns>
/// Redirects to the caregiver dashboard if successful; otherwise, redisplays the form with an error message.
/// </returns>
[HttpPost]
[Route("dashboard/updateAppointment/{appointmentId:guid}")]
public IActionResult UpdateAppointment([FromRoute] Guid appointmentId, AppointmentInfo appointment)
Expand All @@ -87,6 +132,11 @@ public IActionResult UpdateAppointment([FromRoute] Guid appointmentId, Appointme
return RedirectToAction("Caregiver");
}

/// <summary>
/// Displays the update record form for a specific patient record.
/// </summary>
/// <param name="recordId">The unique identifier of the record.</param>
/// <returns>A ViewResult containing the patient record.</returns>
[Route("dashboard/updateRecord/{recordId:guid}")]
public IActionResult UpdateRecord([FromRoute] Guid recordId)
{
Expand All @@ -96,13 +146,26 @@ public IActionResult UpdateRecord([FromRoute] Guid recordId)

}

/// <summary>
/// Creates a new patient record and redirects to the update form.
/// </summary>
/// <param name="patientId">The unique identifier of the patient.</param>
/// <returns>A RedirectToRouteResult pointing to the update record form.</returns>
[Route("dashboard/updateRecord/new/{patientId:guid}")]
public IActionResult NewRecord([FromRoute] Guid patientId)
{
var newId = Guid.NewGuid();
return RedirectToRoute($"Dashboard/UpdateAppointment/{newId}");
}

/// <summary>
/// Processes an update record request.
/// </summary>
/// <param name="recordId">The unique identifier of the record being updated.</param>
/// <param name="record">The updated patient record information.</param>
/// <returns>
/// Redirects to the caregiver dashboard if successful; otherwise, redisplays the form with an error message.
/// </returns>
[HttpPost]
[Route("dashboard/updateRecord/{recordId:guid}")]
public IActionResult UpdateRecord([FromRoute] Guid recordId, PatientRecord record)
Expand Down
18 changes: 13 additions & 5 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

namespace SecureDesignProject.Controllers;

/// <summary>
/// The `HomeController` class handles navigation to the appropriate dashboard based on the user's account type.
/// </summary>
public class HomeController(ILogger<HomeController> logger, DatabaseService dbService) : Controller
{
// Redirect to relevant dashboard depending on user type
/// <summary>
/// Determines the user's account type based on the session cookie and redirects to the appropriate dashboard.
/// </summary>
/// <returns>
/// A redirect to the patient's or caregiver's dashboard, or to the login page if the session is invalid.
/// </returns>
public IActionResult Index()
{
var sessionKey = Request.GetSessionCookie();
Expand All @@ -25,11 +33,11 @@ public IActionResult Index()
};
}

public IActionResult Privacy()
{
return View();
}

/// <summary>
/// Displays an error page when an exception or invalid state occurs.
/// </summary>
/// <returns>An `ErrorViewModel` with the current request's ID.</returns>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
Expand Down
22 changes: 22 additions & 0 deletions Extensions/HttpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
namespace SecureDesignProject.Extensions;


/// <summary>
/// A static class providing extension methods for handling HTTP-related functionality
/// such as cookies and retrieving account identifiers from the HTTP context.
/// </summary>
public static class HttpExtensions
{
/// <summary>
/// Sets a secure, HTTP-only cookie named "session_key" containing the session key as a hex string.
/// </summary>
/// <param name="response">The HTTP response object to set the cookie on.</param>
/// <param name="sessionKey">The session key to be stored in the cookie.</param>

public static void SetSessionKeyCookie(this HttpResponse response, byte[] sessionKey)
{
var options = new CookieOptions
Expand All @@ -13,12 +24,23 @@ public static void SetSessionKeyCookie(this HttpResponse response, byte[] sessio

}


/// <summary>
/// Retrieves the "session_key" cookie from the HTTP request, if it exists, and converts it to a byte array.
/// </summary>
/// <param name="request">The HTTP request object containing the cookies.</param>
/// <returns>The session key as a byte array, or null if the cookie is not present.</returns>
public static byte[]? GetSessionCookie(this HttpRequest request)
{
var cookie = request.Cookies["session_key"];
return cookie == null ? null : Convert.FromHexString(cookie!);
}

/// <summary>
/// Retrieves the account ID stored in the HTTP context's items collection.
/// </summary>
/// <param name="context">The HTTP context object containing the account ID.</param>
/// <returns>The account ID as a GUID, or Guid.Empty if not found.</returns>
public static Guid GetAccountId(this HttpContext context)
{
return context.Items["accountId"] as Guid? ?? Guid.Empty;
Expand Down
3 changes: 3 additions & 0 deletions Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace SecureDesignProject.Extensions;

/// <summary>
/// A static class providing extension methods for string related functionality
/// </summary>
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(this string? value) => string.IsNullOrWhiteSpace(value);
Expand Down
Loading

0 comments on commit fca63a7

Please sign in to comment.