From bd3a3ada3382fb76ba0094c8bc9bbf3ca12e0e6d Mon Sep 17 00:00:00 2001 From: Mahmoud Nasr <239.nasr@gmail.com> Date: Thu, 10 Jul 2025 23:28:15 +0300 Subject: [PATCH 1/2] Remove sentiment analysis method from IAiLayer The method `GetSetmenetAnalysis` has been removed from the interface `IAiLayer`, indicating that sentiment analysis functionality is no longer available. The methods `ScanAll` and `ScanContactToxic` remain unchanged. --- Dentizone.Infrastructure/ApiClient/IAILayer.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dentizone.Infrastructure/ApiClient/IAILayer.cs b/Dentizone.Infrastructure/ApiClient/IAILayer.cs index f744be5..37cc227 100644 --- a/Dentizone.Infrastructure/ApiClient/IAILayer.cs +++ b/Dentizone.Infrastructure/ApiClient/IAILayer.cs @@ -7,11 +7,9 @@ public interface IAiLayer { [Get("/all")] Task> ScanAll([AliasAs("text")] string text); - [Get("/contact-toxic")] Task> ScanContactToxic([AliasAs("text")] string text); [Get("/sentiment")] - Task> GetSetmenetAnalysis([AliasAs("text")] string text); } From c05a3b5634c09ba54cdfa19756dee25c4c629534 Mon Sep 17 00:00:00 2001 From: Mahmoud Nasr <239.nasr@gmail.com> Date: Thu, 10 Jul 2025 23:49:13 +0300 Subject: [PATCH 2/2] Refactor user activity logging to AuthenticationController Removed IUserActivityService dependency from AuthService. Added IUserActivityService to AuthenticationController to handle user activity logging for login, registration, email confirmation, and password reset. This change improves separation of concerns and maintainability of the code. --- .../Services/Authentication/AuthService.cs | 10 ++------ .../Controllers/AuthenticationController.cs | 23 +++++++++++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Dentizone.Application/Services/Authentication/AuthService.cs b/Dentizone.Application/Services/Authentication/AuthService.cs index a097b7b..5bd9bcc 100644 --- a/Dentizone.Application/Services/Authentication/AuthService.cs +++ b/Dentizone.Application/Services/Authentication/AuthService.cs @@ -14,7 +14,8 @@ public class AuthService( ITokenService tokenService, UserManager userManager, IMailService mailService, - IUserActivityService userActivityService + + ) : IAuthService { @@ -71,7 +72,6 @@ public async Task LoginWithEmailAndPassword(string email, string p if (isLockedOut) { - await userActivityService.CreateAsync(UserActivities.Lockedout, DateTime.Now, user.Id); throw new UserLockedOutException( "User is locked out due to too many failed login attempts. Please try again later."); @@ -107,7 +107,6 @@ public async Task LoginWithEmailAndPassword(string email, string p // 5. Generate token await userManager.ResetAccessFailedCountAsync(user); - await userActivityService.CreateAsync(UserActivities.Login, DateTime.Now, user.Id); return new LoggedInUser() { User = user, @@ -145,7 +144,6 @@ public async Task RegisterWithEmailAndPassword(RegisterRequestDto // 4. Send Verification Email await SendVerificationEmail(user.Email); - await userActivityService.CreateAsync(UserActivities.Registered, DateTime.Now, user.Id); return new LoggedInUser() { User = user, @@ -178,7 +176,6 @@ public async Task ConfirmEmail(string token, string userId) // 4. Assign verified role await AlternateUserRoleAsync(UserRoles.PartilyVerified, user); - await userActivityService.CreateAsync(UserActivities.EmailConfirmed, DateTime.Now, user.Id); // 4. Generate token return GenerateToken(user.Id, user.Email, UserRoles.PartilyVerified.ToString()); } @@ -212,7 +209,6 @@ await mailService.Send(

If you did not request this, please ignore this email.

""" ); - await userActivityService.CreateAsync(UserActivities.EmailVerificationSent, DateTime.Now, user.Id); } public async Task SendForgetPasswordEmail(string email) @@ -230,7 +226,6 @@ public async Task SendForgetPasswordEmail(string email) // 3. Send Reset Password Email await mailService.Send(email, "Dentizone: Reset your password", $"Please click the following link to reset your password: Reset Password"); - await userActivityService.CreateAsync(UserActivities.PasswordResetRequested, DateTime.Now, user.Id); } public async Task GetById(string userId) @@ -262,7 +257,6 @@ public async Task ResetPassword(string email, string token, string newPa throw new NotFoundException("User does not have any roles assigned"); } - await userActivityService.CreateAsync(UserActivities.PasswordReset, DateTime.Now, user.Id); // 3. Generate token return GenerateToken(user.Id, user.Email, roles.FirstOrDefault()); } diff --git a/Dentizone.Presentaion/Controllers/AuthenticationController.cs b/Dentizone.Presentaion/Controllers/AuthenticationController.cs index 5e10f39..8e664f7 100644 --- a/Dentizone.Presentaion/Controllers/AuthenticationController.cs +++ b/Dentizone.Presentaion/Controllers/AuthenticationController.cs @@ -2,11 +2,11 @@ using Dentizone.Application.DTOs.User; using Dentizone.Application.Interfaces; using Dentizone.Domain.Enums; +using Dentizone.Domain.Exceptions; using Dentizone.Domain.Interfaces; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; -using Dentizone.Domain.Exceptions; namespace Dentizone.Presentaion.Controllers { @@ -15,7 +15,7 @@ namespace Dentizone.Presentaion.Controllers public class AuthenticationController( IAuthService authenticationService, IUserService userService, - ITokenService tokenService) : ControllerBase + ITokenService tokenService, IUserActivityService userActivityService) : ControllerBase { [HttpPost("login")] [AllowAnonymous] @@ -31,6 +31,8 @@ public async Task Login([FromBody] LoginRequestDto loginPayload) var token = tokenService.GenerateAccessToken(loggedInUser.User.Id, loggedInUser.User.Email, loggedInUser.Role.ToString()); var refreshToken = tokenService.GenerateRefreshToken(loggedInUser.User.Id); + await userActivityService.CreateAsync(UserActivities.Login, DateTime.UtcNow, + loggedInUser.User.Id); return Ok(new RefreshTokenResponse() { AccessToken = token, @@ -60,6 +62,8 @@ public async Task Register([FromBody] RegisterRequestDto register var token = tokenService.GenerateAccessToken(loggedInUser.User.Id, registerPayloadDto.Email, loggedInUser.Role.ToString()); var refreshToken = tokenService.GenerateRefreshToken(loggedInUser.User.Id); + await userActivityService.CreateAsync(UserActivities.Register, DateTime.UtcNow, + loggedInUser.User.Id); return Ok(new RefreshTokenResponse() { AccessToken = token, @@ -75,6 +79,10 @@ public async Task ConfirmEmail([FromQuery] string token) var result = await authenticationService.ConfirmEmail(token, userId); + + await userActivityService.CreateAsync(UserActivities.EmailConfirmed, DateTime.UtcNow, userId); + + return Ok(new { Token = result }); } @@ -83,8 +91,11 @@ public async Task ConfirmEmail([FromQuery] string token) public async Task SendVerificationEmail() { var email = User.Claims.First(c => c.Type == ClaimTypes.Email).Value; + var userId = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value; await authenticationService.SendVerificationEmail(email); + await userActivityService.CreateAsync(UserActivities.EmailVerificationSent, DateTime.UtcNow, userId); + return Ok(); } @@ -94,6 +105,8 @@ public async Task SendVerificationEmail() public async Task SendForgetPasswordEmail([FromQuery] string email) { await authenticationService.SendForgetPasswordEmail(email); + + return Ok(); } @@ -105,6 +118,8 @@ public async Task ResetPassword([FromBody] ResetPasswordDto reset resetPasswordDto.NewPassword); + + return Ok(new { Message = result }); } @@ -186,6 +201,10 @@ public async Task Logout([FromBody] LogoutRequest request) await tokenService.BlacklistAccessTokenAsync(token); await tokenService.BlacklistRefreshTokenAsync(request.RefreshToken); + var userId = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value; + + await userActivityService.CreateAsync(UserActivities.Logout, DateTime.UtcNow, userId); + return Ok(); }