From 1b47fbdcf0ff769479085f14f3cb088a0b5235af Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Tue, 12 Aug 2025 10:03:28 +0530 Subject: [PATCH] Testing the firebase notification added in login API --- .../Dtos/Authentication/LoginDto.cs | 2 ++ .../Controllers/AttendanceController.cs | 12 +------ .../Controllers/AuthController.cs | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs index 00bef12..711113b 100644 --- a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs +++ b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs @@ -4,5 +4,7 @@ { public string? Username { get; set; } public string? Password { get; set; } + public required string DeviceToken { get; set; } + } } diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index e54fca0..bc78ed7 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -808,17 +808,7 @@ namespace MarcoBMS.Services.Controllers PreSignedUrl = string.Empty }; } - var message = new Message() - { - Token = recordAttendanceDot.DeviceToken, - Notification = new Notification - { - Title = "Hello from .NET", - Body = "This is a test message" - } - }; - string response = await FirebaseMessaging.DefaultInstance.SendAsync(message); - _logger.LogInfo("Firebase push notification messageId: {MessageId}", response); + _logger.LogInfo("Attendance for employee {FirstName} {LastName} has been marked", employee.FirstName ?? string.Empty, employee.LastName ?? string.Empty); diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 1b45eb7..6d226d0 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -1,7 +1,4 @@ -using System.Net; -using System.Security.Claims; -using System.Security.Cryptography; -using System.Text; +using FirebaseAdmin.Messaging; using Marco.Pms.DataAccess.Data; using Marco.Pms.Model.Authentication; using Marco.Pms.Model.Dtos.Authentication; @@ -15,6 +12,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using System.Net; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; namespace MarcoBMS.Services.Controllers { @@ -51,6 +52,17 @@ namespace MarcoBMS.Services.Controllers { try { + var message = new Message() + { + Token = "ewjsd9zGTh6aS6Vg3Z_uxP:APA91bFZi1KzZdxlHUfBa_dX3PEJnDhX4R2dvFjD9Zf3WPSm957Hb53JPim7jrpjhpeOY61I9rfc11c3wpqWfW_06aSx-Yb8UfWpygV2YgZ8gbHtSku_PSQ", + Notification = new Notification + { + Title = "Hello from .NET", + Body = "This is a test message" + } + }; + string response = await FirebaseMessaging.DefaultInstance.SendAsync(message); + _logger.LogInfo("Firebase push notification messageId: {MessageId}", response); // Find user by email or phone number var user = await _context.ApplicationUsers .FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username); @@ -118,6 +130,17 @@ namespace MarcoBMS.Services.Controllers [HttpPost("login-mobile")] public async Task LoginMobile([FromBody] LoginDto loginDto) { + var message = new Message() + { + Token = loginDto.DeviceToken, + Notification = new Notification + { + Title = "Hello from .NET", + Body = "This is a test message" + } + }; + string response = await FirebaseMessaging.DefaultInstance.SendAsync(message); + _logger.LogInfo("Firebase push notification messageId: {MessageId}", response); // Validate input DTO if (loginDto == null || string.IsNullOrWhiteSpace(loginDto.Username) || string.IsNullOrWhiteSpace(loginDto.Password)) {