diff --git a/Marco.Pms.Model/Dtos/ForgotPasswordDto.cs b/Marco.Pms.Model/Dtos/ForgotPasswordDto.cs index 518c1b5..8019d50 100644 --- a/Marco.Pms.Model/Dtos/ForgotPasswordDto.cs +++ b/Marco.Pms.Model/Dtos/ForgotPasswordDto.cs @@ -6,6 +6,6 @@ namespace Marco.Pms.Model.Dtos { [Required] [EmailAddress] - public string? Email { get; set; } + public string Email { get; set; } = string.Empty; } } diff --git a/Marco.Pms.Model/Dtos/ResetPasswordDto.cs b/Marco.Pms.Model/Dtos/ResetPasswordDto.cs index 5ae11a5..9c3d2e9 100644 --- a/Marco.Pms.Model/Dtos/ResetPasswordDto.cs +++ b/Marco.Pms.Model/Dtos/ResetPasswordDto.cs @@ -9,7 +9,7 @@ namespace Marco.Pms.Model.Dtos public string? Email { get; set; } [Required] - public string? Token { get; set; } + public string Token { get; set; }= string.Empty; [Required] [MinLength(6)] diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index c5ddd43..b499fba 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -26,7 +26,7 @@ namespace MarcoBMS.Services.Controllers private readonly IConfiguration _configuration; private readonly EmployeeHelper _employeeHelper; //string tenentId = "1"; - public AuthController(UserManager userManager,ApplicationDbContext context, JwtSettings jwtSettings, RefreshTokenService refreshTokenService, + public AuthController(UserManager userManager, ApplicationDbContext context, JwtSettings jwtSettings, RefreshTokenService refreshTokenService, IEmailSender emailSender, IConfiguration configuration, EmployeeHelper employeeHelper) { _userManager = userManager; @@ -42,7 +42,7 @@ namespace MarcoBMS.Services.Controllers public async Task Login([FromBody] LoginDto loginDto) { var user = await _context.ApplicationUsers.FirstOrDefaultAsync(u => u.Email == loginDto.Username || u.PhoneNumber == loginDto.Username); - + if (user != null && await _userManager.CheckPasswordAsync(user, loginDto.Password)) { if (!user.IsActive) @@ -62,7 +62,7 @@ namespace MarcoBMS.Services.Controllers var refreshToken = await _refreshTokenService.CreateRefreshToken(user.Id, emp.TenantId.ToString(), _jwtSettings); return Ok(ApiResponse.SuccessResponse(new { token = token, refreshToken = refreshToken }, "User logged in successfully.", 200)); - + } return Unauthorized(ApiResponse.ErrorResponse("Invalid username or password.", "Invalid username or password.", 401)); @@ -92,7 +92,7 @@ namespace MarcoBMS.Services.Controllers { await _refreshTokenService.BlacklistJwtTokenAsync(jwtToken); } - return Ok(ApiResponse.SuccessResponse(new { }, "Logged out successfully", 200)); + return Ok(ApiResponse.SuccessResponse(new { }, "Logged out successfully", 200)); } catch (Exception ex) { @@ -119,8 +119,8 @@ namespace MarcoBMS.Services.Controllers return BadRequest(ApiResponse.ErrorResponse("Invalid request.", "Invalid request.", 400)); Employee emp = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id); - - if (user.UserName == null) return NotFound(ApiResponse.ErrorResponse("UserName Not found", "UserName Not found", 404)); + + if (user.UserName == null) return NotFound(ApiResponse.ErrorResponse("UserName Not found", "UserName Not found", 404)); var newJwtToken = _refreshTokenService.GenerateJwtToken(user.UserName, emp.TenantId.ToString(), _jwtSettings); var newRefreshToken = await _refreshTokenService.CreateRefreshToken(user.Id, emp.TenantId.ToString(), _jwtSettings); @@ -132,7 +132,7 @@ namespace MarcoBMS.Services.Controllers public async Task ForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto) { var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email); - if (user == null) + if (user == null) return NotFound(ApiResponse.ErrorResponse("User not found.", "User not found.", 404)); /* SEND USER REGISTRATION MAIL*/ @@ -159,7 +159,7 @@ namespace MarcoBMS.Services.Controllers user, TokenOptions.DefaultProvider, // This is the token provider UserManager.ResetPasswordTokenPurpose, - WebUtility.UrlDecode( model.Token) + WebUtility.UrlDecode(model.Token) ); string token = ""; @@ -171,7 +171,7 @@ namespace MarcoBMS.Services.Controllers UserManager.ResetPasswordTokenPurpose, model.Token ); - if(!isDecodedTokenValid) + if (!isDecodedTokenValid) return BadRequest(ApiResponse.ErrorResponse("Invalid request.", "Invalid request.", 400)); token = model.Token; @@ -182,18 +182,28 @@ namespace MarcoBMS.Services.Controllers } - var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword); + var result = await _userManager.ResetPasswordAsync(user, token, model.NewPassword); if (!result.Succeeded) { var errors = result.Errors.Select(e => e.Description).ToList(); return BadRequest(ApiResponse.ErrorResponse("Failed to Change password", errors, 400)); } + try + { + Employee emp = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id); + await _emailSender.SendResetPasswordSuccessEmail(user.Email, emp.FirstName + " " + emp.LastName); + } + catch (Exception ex) { + + } + + return Ok(ApiResponse.SuccessResponse(result.Succeeded, "Password reset successfully.", 200)); } - + [HttpPost("sendmail")] public async Task SendEmail([FromBody] EmailDot emailDot) { @@ -211,10 +221,10 @@ namespace MarcoBMS.Services.Controllers //var resetLink = $"{_configuration["AppSettings:WebFrontendUrl"]}/reset-password?token={WebUtility.UrlEncode(token)}"; //await _emailSender.SendResetPasswordEmailOnRegister(emailDot.ToEmail, "Vikas", resetLink); - + /* Forget password*/ - // var token = await _userManager.GeneratePasswordResetTokenAsync(user); + // var token = await _userManager.GeneratePasswordResetTokenAsync(user); var token = await _userManager.GenerateUserTokenAsync(user, TokenOptions.DefaultProvider, "ResetPassword"); @@ -226,7 +236,7 @@ namespace MarcoBMS.Services.Controllers await _emailSender.SendResetPasswordEmail(user.Email, "", resetLink); - return Ok(ApiResponse.SuccessResponse(new {}, "Password reset link sent.", 200)); + return Ok(ApiResponse.SuccessResponse(new { }, "Password reset link sent.", 200)); } } } diff --git a/Marco.Pms.Services/EmailTemplates/forgot-password.html b/Marco.Pms.Services/EmailTemplates/forgot-password.html index a944fd4..1db4a08 100644 --- a/Marco.Pms.Services/EmailTemplates/forgot-password.html +++ b/Marco.Pms.Services/EmailTemplates/forgot-password.html @@ -352,7 +352,7 @@
-
+
@@ -361,9 +361,11 @@ @@ -387,7 +389,7 @@ @@ -532,7 +534,7 @@
-

Contact

-

1912  Mcwhorter Road, FL 11223

-

+111 222 333 | info [@] marcoaiot.com

+ + +

Contact Us: info@marcoaiot.com

+ +
-
+
@@ -408,8 +410,8 @@
- - Twitter + + Twitter
- + + +
+
You're receiving this email because you have a MarcoPMS account. This email is not a marketing or promotional email. That is why this email does not contain an unsubscribe link. You will receive this email even if you have unsubscribed from MarcoPMS's marketing emails diff --git a/Marco.Pms.Services/EmailTemplates/full-template.html b/Marco.Pms.Services/EmailTemplates/full-template.html index 925de8f..320d532 100644 --- a/Marco.Pms.Services/EmailTemplates/full-template.html +++ b/Marco.Pms.Services/EmailTemplates/full-template.html @@ -352,7 +352,7 @@
-
+
@@ -361,9 +361,11 @@ @@ -387,7 +389,7 @@ @@ -452,19 +454,18 @@
-

Contact

-

1912  Mcwhorter Road, FL 11223

-

+111 222 333 | info [@] marcoaiot.com

+ + +

Contact Us: info@marcoaiot.com

+ +
-
+
@@ -408,8 +410,8 @@
- - Twitter + + Twitter
+
+

Marco AIoT Technologies Pvt. Ltd. ©  All Rights Reserved

+
+
-->
@@ -496,14 +497,14 @@

Marco AIoT Technologies Pvt. Ltd. ©  All Rights Reserved

+ + + + --> @@ -532,7 +533,7 @@ - + + +
+
You're receiving this email because you have a MarcoPMS account. This email is not a marketing or promotional email. That is why this email does not contain an unsubscribe link. You will receive this email even if you have unsubscribed from MarcoPMS's marketing emails diff --git a/Marco.Pms.Services/EmailTemplates/new-user-email.html b/Marco.Pms.Services/EmailTemplates/new-user-email.html index aac8df2..3a9ef3c 100644 --- a/Marco.Pms.Services/EmailTemplates/new-user-email.html +++ b/Marco.Pms.Services/EmailTemplates/new-user-email.html @@ -352,7 +352,7 @@
-
+
@@ -361,9 +361,11 @@ @@ -387,7 +389,7 @@ @@ -408,8 +410,8 @@ @@ -422,7 +424,7 @@ @@ -435,7 +437,7 @@ @@ -452,18 +454,18 @@
-

Contact

-

1912  Mcwhorter Road, FL 11223

-

+111 222 333 | info [@] marcoaiot.com

+ + +

Contact Us: info@marcoaiot.com

+ +
-
+
@@ -396,7 +398,7 @@
- Facebook + Facebook
- - Twitter + + Twitter
- Instagram + Instagram
- LinkedIn + LinkedIn
+
-->
@@ -476,6 +478,7 @@ +
@@ -495,14 +498,14 @@

Marco AIoT Technologies Pvt. Ltd. ©  All Rights Reserved

+ + + + --> @@ -531,7 +534,7 @@ -
+
You're receiving this email because you have a MarcoPMS account. This email is not a marketing or promotional email. That is why this email does not contain an unsubscribe link. You will receive this email even if you have unsubscribed from MarcoPMS's marketing emails diff --git a/Marco.Pms.Services/EmailTemplates/password-change-success.html b/Marco.Pms.Services/EmailTemplates/password-change-success.html new file mode 100644 index 0000000..4a9c4e6 --- /dev/null +++ b/Marco.Pms.Services/EmailTemplates/password-change-success.html @@ -0,0 +1,573 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+ + +
+
+
+ + + + + + + + +
+ + + + + + + +
+ Sita +
+ +
+ + +
+
+
+ + +
+
+
+ + + + + +
+
+
+ + +
+
+
+ + + + + + + + +
+ + + + + +
+ + Image + +
+ +
+ + +
+
+
+ + +
+
+
+ + + + + +
+
+
+ + +
+
+
+ + + + + + + + +
+ + + + + +
+ + Image + +
+ +
+ + + + + + + +
+ +
+

{{MAIL_TITLE}}

+
+ +
+ + +
+
+
+ + +
+
+
+ + + + + +
+
+
+ + +
+
+
+ + + + + + + + +
+ +
+

Hi {{RECEIVER_NAME}},

+

 

+

We wanted to let you know that your account password was changed successfully.

+

 

+

+ + If you made this change, no further action is needed. + + However, if you did not request this change, please contact our support team immediately or reset your password. + +

+

 

+

+ + Security Tip: + For your safety, make sure to use a strong, unique password and avoid sharing your credentials with anyone. + +

+

 

+

+ + Thank you,
+ Marco AIoT Technologies Pvt. Ltd.
+ Support Team +
+

+
+ + + + + + +
+ + + + + + + +
+ +
+

Please ignore this email if you did not request a password change.
 

+
+ +
+ + +
+
+
+ + +
+
+
+ + + + + +
+
+
+ + +
+
+
+ + + + + + + + +
+ +
+ + +

Contact Us: info@marcoaiot.com

+ + +
+ +
+ + +
+
+
+ + +
+
+
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ + Facebook + +
+ + + + + + + + +
+ + Twitter + +
+ + + + + + + + +
+ + Instagram + +
+ + + + + + + + +
+ + LinkedIn + +
+ + +
+
+ +
+ + + +
+
+
+ + +
+
+
+ + + + + +
+
+
+ + +
+
+
+ + + + + + + + +
+

Marco AIoT Technologies Pvt. Ltd. ©  All Rights Reserved

+ + + +
+ + +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+ + + + + + + + +
+ +
+ You're receiving this email because you have a MarcoPMS account. This email is not a marketing or promotional email. That is why this email does not contain an unsubscribe link. You will receive this email even if you have unsubscribed from MarcoPMS's marketing emails + +
+ +
+ + +
+
+
+ + +
+
+
+ +
+ + + + + diff --git a/Marco.Pms.Services/Service/EmailSender.cs b/Marco.Pms.Services/Service/EmailSender.cs index fd357cf..2c21f41 100644 --- a/Marco.Pms.Services/Service/EmailSender.cs +++ b/Marco.Pms.Services/Service/EmailSender.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Options; using MailKit.Net.Smtp; using MimeKit; +using System.Xml.Linq; namespace MarcoBMS.Services.Service @@ -62,6 +63,21 @@ namespace MarcoBMS.Services.Service } + public async Task SendResetPasswordSuccessEmail(string toEmail, string toName) + { + var replacements = new Dictionary + { + { "MAIL_TITLE", "Reset Password Successful" }, + { "RECEIVER_NAME", toName } + }; + + string emailBody = await GetEmailTemplate("password-change-success", replacements); + + + await SendEmailAsync(toEmail, "Password Changed Successfully", emailBody); + + } + public async Task SendEmailAsync(string toEmail, string subject, string body) { var email = new MimeMessage(); diff --git a/Marco.Pms.Services/Service/IEmailSender.cs b/Marco.Pms.Services/Service/IEmailSender.cs index 7ede524..8c47eff 100644 --- a/Marco.Pms.Services/Service/IEmailSender.cs +++ b/Marco.Pms.Services/Service/IEmailSender.cs @@ -4,7 +4,7 @@ { Task SendResetPasswordEmail(string toEmail, string userName, string resetLink); Task SendResetPasswordEmailOnRegister(string toEmail, string toName, string resetLink); - + Task SendResetPasswordSuccessEmail(string toEmail, string userName); Task SendEmailAsync(string toEmail, string subject, string body); } }