From 6f1a9cd8926238fe45f9acea1e3edcd4a6a5057a Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Tue, 12 Aug 2025 11:57:37 +0530 Subject: [PATCH] solved the conflicts --- .../Dtos/Authentication/LoginDto.cs | 7 +++---- .../Controllers/AuthController.cs | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs index 536ac5d..ea7869c 100644 --- a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs +++ b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs @@ -2,9 +2,8 @@ { public class LoginDto { - public string? Username { get; set; } - public string? Password { get; set; } - public string? DeviceToken { get; set; } - + public required string Username { get; set; } + public required string Password { get; set; } + public required string DeviceToken { get; set; } } } diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index aa064ee..0bfa285 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -69,7 +69,7 @@ namespace MarcoBMS.Services.Controllers } catch (FirebaseMessagingException ex) { - _logger.LogError("Error sending push notification. : {Error}", ex.Message); + _logger.LogError(ex, "Error sending push notification."); // Check for the specific error codes that indicate an invalid token if (ex.MessagingErrorCode == MessagingErrorCode.Unregistered || @@ -145,13 +145,14 @@ namespace MarcoBMS.Services.Controllers } } - [HttpPost("login-mobile")] /// /// Handles mobile user login, validates credentials, sends a test push notification, /// and generates JWT, Refresh, and MPIN tokens upon successful authentication. /// /// Data Transfer Object containing the user's login credentials and device token. /// An IActionResult containing the authentication tokens or an error response. + + [HttpPost("login-mobile")] public async Task LoginMobile([FromBody] LoginDto loginDto) { // Log the start of the login attempt for traceability. @@ -179,7 +180,7 @@ namespace MarcoBMS.Services.Controllers catch (FirebaseMessagingException ex) { // Log the specific Firebase error. - _logger.LogError("Error sending push notification: {Error}", ex.Message); + _logger.LogError(ex, "Error sending push notification"); // Check for specific error codes that indicate an invalid or unregistered token. if (ex.MessagingErrorCode == MessagingErrorCode.Unregistered || @@ -245,7 +246,7 @@ namespace MarcoBMS.Services.Controllers if (string.IsNullOrWhiteSpace(user.UserName)) { // This is an unlikely edge case, but good to handle. - _logger.LogError("Login failed: User object for ID {UserId} is missing a UserName.", user.Id); + _logger.LogWarning("Login failed: User object for ID {UserId} is missing a UserName.", user.Id); return NotFound(ApiResponse.ErrorResponse("UserName not found", "Username is missing", 404)); } @@ -255,7 +256,7 @@ namespace MarcoBMS.Services.Controllers var emp = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id); if (emp == null) { - _logger.LogError("Login failed: Could not find associated employee record for user ID {UserId}", user.Id); + _logger.LogWarning("Login failed: Could not find associated employee record for user ID {UserId}", user.Id); return NotFound(ApiResponse.ErrorResponse("Employee not found", "Employee details missing", 404)); } _logger.LogInfo("Successfully found employee details for tenant ID: {TenantId}", emp.TenantId); @@ -290,7 +291,7 @@ namespace MarcoBMS.Services.Controllers { // --- Global Exception Handling --- // Catch any unexpected exceptions during the login process. - _logger.LogError("An unexpected error occurred during the LoginMobile process for user: {Username} : {Error}", loginDto?.Username ?? "N/A", ex.Message); + _logger.LogError(ex, "An unexpected error occurred during the LoginMobile process for user: {Username}", loginDto?.Username ?? "N/A"); // Return a generic 500 Internal Server Error to avoid leaking implementation details. return StatusCode(500, ApiResponse.ErrorResponse("An internal server error occurred.", "Server Error", 500)); @@ -917,6 +918,13 @@ namespace MarcoBMS.Services.Controllers return Ok(ApiResponse.SuccessResponse(mpinToken, "MPIN updated successfully", 200)); } } + + //[Authorize] + //[HttpPost("set/device-token")] + //public async Task StoreDeviceToken([FromBody] DeviceTokenDto model) + //{ + + //} private static string ComputeSha256Hash(string rawData) { using (SHA256 sha256 = SHA256.Create())