solved the conflicts

This commit is contained in:
ashutosh.nehete 2025-08-12 11:57:37 +05:30
parent 44614f475b
commit 6f1a9cd892
2 changed files with 17 additions and 10 deletions

View File

@ -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; }
}
}

View File

@ -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")]
/// <summary>
/// Handles mobile user login, validates credentials, sends a test push notification,
/// and generates JWT, Refresh, and MPIN tokens upon successful authentication.
/// </summary>
/// <param name="loginDto">Data Transfer Object containing the user's login credentials and device token.</param>
/// <returns>An IActionResult containing the authentication tokens or an error response.</returns>
[HttpPost("login-mobile")]
public async Task<IActionResult> 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<object>.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<object>.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<object>.ErrorResponse("An internal server error occurred.", "Server Error", 500));
@ -917,6 +918,13 @@ namespace MarcoBMS.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(mpinToken, "MPIN updated successfully", 200));
}
}
//[Authorize]
//[HttpPost("set/device-token")]
//public async Task<IActionResult> StoreDeviceToken([FromBody] DeviceTokenDto model)
//{
//}
private static string ComputeSha256Hash(string rawData)
{
using (SHA256 sha256 = SHA256.Create())