Chnaged the login notification body and title
This commit is contained in:
parent
884efdce61
commit
9a9876b7ca
@ -1,5 +1,4 @@
|
|||||||
using FirebaseAdmin.Messaging;
|
using Marco.Pms.DataAccess.Data;
|
||||||
using Marco.Pms.DataAccess.Data;
|
|
||||||
using Marco.Pms.Model.Authentication;
|
using Marco.Pms.Model.Authentication;
|
||||||
using Marco.Pms.Model.Dtos.Authentication;
|
using Marco.Pms.Model.Dtos.Authentication;
|
||||||
using Marco.Pms.Model.Dtos.Util;
|
using Marco.Pms.Model.Dtos.Util;
|
||||||
@ -257,14 +256,8 @@ namespace MarcoBMS.Services.Controllers
|
|||||||
// --- Push Notification Section ---
|
// --- Push Notification Section ---
|
||||||
// This section attempts to send a test push notification to the user's device.
|
// 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.
|
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||||
|
var name = $"{emp.FirstName} {emp.LastName}";
|
||||||
var notification = new Notification
|
await _firebase.SendLoginMessageAsync(name);
|
||||||
{
|
|
||||||
Title = "Testing from API",
|
|
||||||
Body = "This messages comes from FireBase Services"
|
|
||||||
};
|
|
||||||
|
|
||||||
await _firebase.SendLoginMessageAsync(notification);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(responseData, "User logged in successfully.", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(responseData, "User logged in successfully.", 200));
|
||||||
|
@ -19,24 +19,19 @@ namespace Marco.Pms.Services.Service
|
|||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendDemoMessages(Notification notificationFirebase)
|
public async Task SendLoginMessageAsync(string name)
|
||||||
{
|
|
||||||
string deviceToken = "";
|
|
||||||
var message = new Message()
|
|
||||||
{
|
|
||||||
Token = deviceToken,
|
|
||||||
Notification = notificationFirebase
|
|
||||||
};
|
|
||||||
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendLoginMessageAsync(Notification notificationFirebase)
|
|
||||||
{
|
{
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
// List of device registration tokens to send the message to
|
// List of device registration tokens to send the message to
|
||||||
var registrationTokens = await _context.FCMTokenMappings.Select(ft => ft.FcmToken).ToListAsync();
|
var registrationTokens = await _context.FCMTokenMappings.Select(ft => ft.FcmToken).ToListAsync();
|
||||||
|
|
||||||
|
var notificationFirebase = new Notification
|
||||||
|
{
|
||||||
|
Title = "Login Alert",
|
||||||
|
Body = $"{name} has successfully logged in to the application"
|
||||||
|
};
|
||||||
|
|
||||||
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
||||||
}
|
}
|
||||||
public async Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId)
|
public async Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId)
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using FirebaseAdmin.Messaging;
|
using Marco.Pms.Model.Dtos.Attendance;
|
||||||
using Marco.Pms.Model.Dtos.Attendance;
|
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Service.ServiceInterfaces
|
namespace Marco.Pms.Services.Service.ServiceInterfaces
|
||||||
{
|
{
|
||||||
public interface IFirebaseService
|
public interface IFirebaseService
|
||||||
{
|
{
|
||||||
Task SendLoginMessageAsync(Notification notificationFirebase);
|
Task SendLoginMessageAsync(string name);
|
||||||
Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId);
|
Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user