Firebase_Implementation #135

Merged
ashutosh.nehete merged 62 commits from Firebase_Implementation into main 2025-09-20 12:11:54 +00:00
2 changed files with 1 additions and 35 deletions
Showing only changes of commit da787cfe43 - Show all commits

View File

@ -5,11 +5,4 @@
public required string Username { get; set; }
public required string Password { get; set; }
}
public class MobileLoginDto
{
public required string Username { get; set; }
public required string Password { get; set; }
public required string FcmToken { get; set; }
}
}

View File

@ -127,7 +127,7 @@ namespace MarcoBMS.Services.Controllers
/// <returns>An IActionResult containing the authentication tokens or an error response.</returns>
[HttpPost("login-mobile")]
public async Task<IActionResult> LoginMobile([FromBody] MobileLoginDto loginDto)
public async Task<IActionResult> LoginMobile([FromBody] LoginDto loginDto)
{
// Log the start of the login attempt for traceability.
_logger.LogInfo("Login attempt initiated for user: {Username}", loginDto.Username ?? "N/A");
@ -225,33 +225,6 @@ namespace MarcoBMS.Services.Controllers
// Return a successful response with the generated tokens.
_logger.LogInfo("User {Username} logged in successfully.", user.UserName);
var existingFCMTokenMapping = await _context.FCMTokenMappings.Where(ft => ft.FcmToken == loginDto.FcmToken).ToListAsync();
if (existingFCMTokenMapping.Any())
{
_context.FCMTokenMappings.RemoveRange(existingFCMTokenMapping);
}
var fcmTokenMapping = new FCMTokenMapping
{
EmployeeId = emp.Id,
FcmToken = loginDto.FcmToken,
ExpiredAt = DateTime.UtcNow.AddDays(6),
TenantId = emp.TenantId
};
_context.FCMTokenMappings.Add(fcmTokenMapping);
_logger.LogInfo("New FCM Token registering for employee {EmployeeId}", emp.Id);
_ = Task.Run(async () =>
{
// --- Push Notification Section ---
// This section attempts to send a test push notification to the user's device.
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
await _firebase.SendLoginOnAnotherDeviceMessageAsync(emp.Id, loginDto.FcmToken, tenantId);
});
try
{
await _context.SaveChangesAsync();