Removed the FCM token from login DTO and logic of adding FCM token to database from mobile login API
This commit is contained in:
parent
452f4a7e5a
commit
da787cfe43
@ -5,11 +5,4 @@
|
|||||||
public required string Username { get; set; }
|
public required string Username { get; set; }
|
||||||
public required string Password { 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; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
/// <returns>An IActionResult containing the authentication tokens or an error response.</returns>
|
/// <returns>An IActionResult containing the authentication tokens or an error response.</returns>
|
||||||
|
|
||||||
[HttpPost("login-mobile")]
|
[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.
|
// Log the start of the login attempt for traceability.
|
||||||
_logger.LogInfo("Login attempt initiated for user: {Username}", loginDto.Username ?? "N/A");
|
_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.
|
// Return a successful response with the generated tokens.
|
||||||
_logger.LogInfo("User {Username} logged in successfully.", user.UserName);
|
_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
|
try
|
||||||
{
|
{
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user