Browse Source

ForgetPassword dtos

zinab_elgendy 8 months ago
parent
commit
7c103bf547

+ 17 - 14
MTWorkHR.API/Controllers/AuthController.cs

@@ -32,35 +32,38 @@ namespace MTWorkHR.API.Controllers
             return await _userService.Create(input);
         }
 
-      
-        //[HttpPost("IsExpiredToken")]
-        //[ProducesResponseType(StatusCodes.Status200OK)]
-        //public async Task<bool> IsExpiredToken([FromBody] ForgetPasswordDto model)
-        //{
-        //    return await _userService.IsExpiredToken(model);
-        //}
-
         [HttpGet("forgetPasswordMail")]
         //[ProducesResponseType(StatusCodes.Status200OK)]
-        public async Task<string> ForgetPasswordMail(string email)
+        public async Task<ActionResult<ForgetPasswordResponseDto>> ForgetPasswordMail([FromQuery] string email)
         {
-            return await _userService.ForgetPasswordMail(email);
+            var result = await _userService.ForgetPasswordMail(email);
+            return result;
         }
 
         [HttpPost("forgetPassword")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-        public async Task<bool> ForgetPassword([FromBody] ForgetPasswordDto model)
+        public async Task<ActionResult> ForgetPassword([FromBody] ForgetPasswordDto model)
         {
-            return await _userService.ForgetPassword(model);
+            return Ok( await _userService.ForgetPassword(model));
         }
+        [HttpPost("VerifyOTP")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
 
+        public async Task<ActionResult> VerifyOTP([FromBody] VerifyOTPDto model)
+        {
+            var result = await _userService.VerifyOTP(model);
+
+            return Ok(result);
+        }
+
+       
         [HttpGet("confirmEmail")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task<bool> ConfirmEmail([FromQuery] ForgetPasswordDto model)
+        public async Task<ActionResult> ConfirmEmail([FromQuery] ConfirmEmailDto model)
         {
             var result = await _userService.ConfirmEmail(model);
-            return result;
+            return Ok(result);
         }
     }
 }

+ 2 - 2
MTWorkHR.API/Controllers/UserController.cs

@@ -38,9 +38,9 @@ namespace MTWorkHR.API.Controllers
         }
 
         [HttpPost("Update")]
+        [Consumes("multipart/form-data")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-
-        public async Task Update([FromBody] UserDto input)
+        public async Task Update([FromForm] UserDto input)
         {
             await _userService.Update(input);
         }

+ 4 - 2
MTWorkHR.API/Controllers/UserTaskController.cs

@@ -59,13 +59,15 @@ namespace MTWorkHR.API.Controllers
         #region attachments
         [HttpPost("CreateAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-        public async Task<ActionResult<AttachmentDto>> CreateAttachment([FromBody] AttachmentDto input)
+        [Consumes("multipart/form-data")]
+        public async Task<ActionResult<AttachmentDto>> CreateAttachment([FromForm] AttachmentDto input)
         {
             return await _attachmentService.Create(input);
         }
         [HttpPost("UpdateAttachment")]
         [ProducesResponseType(StatusCodes.Status200OK)]
-        public async Task UpdateAttachment([FromBody] AttachmentDto input)
+        [Consumes("multipart/form-data")]
+        public async Task UpdateAttachment([FromForm] AttachmentDto input)
         {
             await _attachmentService.Update(input);
         }

+ 1 - 1
MTWorkHR.API/appsettings.json

@@ -31,7 +31,7 @@
     "ApiKey": "SendGrid-Key",
     "FromAddress": "eng_z@live.com",
     "FromName": "Hr Management System",
-    "Password": "111111",
+    "Password": "j,jij,ji",
     "Host": "smtp-mail.outlook.com",
     "Port": 587,
     "TemplatePath": "C:\\Attachment\\MailTemp\\EmailTemplate.html"

+ 15 - 0
MTWorkHR.Application/Dtos/Identity/ConfirmEmailDto.cs

@@ -0,0 +1,15 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace MTWorkHR.Application.Models
+{
+    public class ConfirmEmailDto
+    {
+        public string? UserId { get; set; }
+        public string? Token { get; set; }
+        
+        public string? Password { get; set; }
+        public string? Email { get; set; }
+        public string? OTP { get; set; }
+
+    }
+}

+ 3 - 3
MTWorkHR.Application/Dtos/Identity/ForgetPasswordDto.cs

@@ -5,11 +5,11 @@ namespace MTWorkHR.Application.Models
     public class ForgetPasswordDto
     {
         public string? UserId { get; set; }
-        public string? Token { get; set; }
+       // public string? Token { get; set; }
         
         public string? Password { get; set; }
-        public string? Email { get; set; }
-        public string? OTP { get; set; }
+      //  public string? Email { get; set; }
+     //   public string? OTP { get; set; }
 
     }
 }

+ 10 - 0
MTWorkHR.Application/Dtos/Identity/ForgetPasswordResponseDto.cs

@@ -0,0 +1,10 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace MTWorkHR.Application.Models
+{
+    public class ForgetPasswordResponseDto
+    {
+        public string? UserId { get; set; }
+
+    }
+}

+ 11 - 0
MTWorkHR.Application/Dtos/Identity/VerifyOTPDto.cs

@@ -0,0 +1,11 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace MTWorkHR.Application.Models
+{
+    public class VerifyOTPDto
+    {
+        public string? UserId { get; set; }
+        public string? OTP { get; set; }
+
+    }
+}

+ 1 - 1
MTWorkHR.Application/Services/Base/FileService.cs

@@ -27,7 +27,7 @@ namespace MTWorkHR.Application.Services
             if (!AttachmentsMust(files))
                 throw new AppException(ExceptionEnum.InvalidFileType);
 
-            string pathToSave = GetTempAttachmentPath();
+            string pathToSave = GetActualAttachmentPath();
             if (!Directory.Exists(pathToSave))
                 Directory.CreateDirectory(pathToSave);
 

+ 6 - 4
MTWorkHR.Application/Services/Interfaces/IUserService.cs

@@ -18,13 +18,15 @@ namespace MTWorkHR.Application.Identity
         Task Delete(string id);
         Task<UserDto> Create(UserDto input);
         Task<UserDto> Update(UserDto input);
-        Task<string> ForgetPasswordMail(string input);
+        Task<ForgetPasswordResponseDto> ForgetPasswordMail(string input);
         Task<bool> ResetPassword(ResetPasswordDto input);
 
         Task<bool> ForgetPassword(ForgetPasswordDto model);
-        Task<bool> ConfirmEmail(ForgetPasswordDto model);
-        Task<bool> IsExpiredToken(ForgetPasswordDto model);
+        Task<bool> ConfirmEmail(ConfirmEmailDto model);
+        Task<bool> IsExpiredToken(ConfirmEmailDto model);
+        Task<bool> VerifyOTP(VerifyOTPDto input);
+
+
 
-       
     }
 }

+ 16 - 16
MTWorkHR.Application/Services/User/UserService.cs

@@ -266,7 +266,7 @@ namespace MTWorkHR.Application.Services
 
             return input;
         }
-        public async Task<bool> ConfirmEmail(ForgetPasswordDto input)
+        public async Task<bool> ConfirmEmail(ConfirmEmailDto input)
         {
             var user = await _userManager.FindByIdAsync(input.UserId);
             if (user == null)
@@ -352,12 +352,9 @@ namespace MTWorkHR.Application.Services
         }
 
 
-        public Task<UserDto> UpdateWithoutChildren(UserDto input)
-        {
-            throw new NotImplementedException();
-        }
+       
 
-        public async Task<bool> IsExpiredToken(ForgetPasswordDto input)
+        public async Task<bool> IsExpiredToken(ConfirmEmailDto input)
         {
             var user = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(x => x.Id == input.UserId);
             if (user == null)
@@ -366,7 +363,7 @@ namespace MTWorkHR.Application.Services
             var result = await _userManager.VerifyUserTokenAsync(user, "Default", purpose, input.Token);
             return !result;
         }
-        public async Task<bool> ForgetPassword1(ForgetPasswordDto model)
+        public async Task<bool> ForgetPasswordxxxxxxxxxxxxxx(ConfirmEmailDto model)
         {
             var user = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(x => x.Id == model.UserId);
             if (user == null)
@@ -394,7 +391,7 @@ namespace MTWorkHR.Application.Services
 
             return true;
         }
-        public async Task ForgetPasswordMail1(string email)
+        public async Task ForgetPasswordMailxxxxxxxxxxxx(string email)
         {
 
             var foundUser = await _userManager.FindByEmailAsync(email);
@@ -424,30 +421,33 @@ namespace MTWorkHR.Application.Services
         }
 
 
-        public async Task<string> ForgetPasswordMail(string email) //Begin forget password
+        public async Task<ForgetPasswordResponseDto> ForgetPasswordMail(string email) //Begin forget password
         {
             var foundUser = await _userManager.FindByEmailAsync(email);
             if (foundUser != null)
             {
                 string oneTimePassword = await _oTPService.RandomOneTimePassword(foundUser.Id);
-                await _oTPService.SentOTPByMail(foundUser.Id,foundUser.Email, oneTimePassword);
-                return foundUser.Id;
+                await _oTPService.SentOTPByMail(foundUser.Id, foundUser.Email, oneTimePassword);
+                ForgetPasswordResponseDto res = new ForgetPasswordResponseDto { UserId = foundUser.Id};
+                return res;
             }
             else
             {
                 throw new AppException(ExceptionEnum.RecordNotExist);
             }
         }
-       
-
+        public async Task<bool> VerifyOTP(VerifyOTPDto input)
+        {
+            if (! await _oTPService.VerifyOTP(input.UserId, input.OTP))
+                throw new AppException(ExceptionEnum.WrongOTP);
+            return true;
+        }
         public async Task<bool> ForgetPassword(ForgetPasswordDto input)
         {
             var user = await _userManager.Users.IgnoreQueryFilters().FirstOrDefaultAsync(x => x.Id == input.UserId);
             if (user == null)
                 throw new AppException(ExceptionEnum.RecordNotExist);
-
-            if (!_oTPService.VerifyOTP(user.Id, input.OTP).Result)
-                throw new AppException(ExceptionEnum.WrongOTP);
+           
             string resetToken = await _userManager.GeneratePasswordResetTokenAsync(user);
 
             var result = await _userManager.ResetPasswordAsync(user, resetToken, input.Password);