From fffd6bd5705203a475eaec48e69e7067d4540a78 Mon Sep 17 00:00:00 2001
From: Adiv <asifadiv@gmail.com>
Date: Tue, 9 May 2023 14:06:14 +0100
Subject: [PATCH] changes to setting passwords

---
 .../Models/DTOs/UserDTO.cs                     | 18 ++++--------------
 .../AuthenticationMicroservice/Program.cs      |  2 +-
 .../Services/AuthService.cs                    |  7 +++----
 Frontend/API/Group17AuthApi.cs                 | 17 -----------------
 4 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/AuthenticationMicroservice/AuthenticationMicroservice/Models/DTOs/UserDTO.cs b/AuthenticationMicroservice/AuthenticationMicroservice/Models/DTOs/UserDTO.cs
index a119119..0e3d51b 100644
--- a/AuthenticationMicroservice/AuthenticationMicroservice/Models/DTOs/UserDTO.cs
+++ b/AuthenticationMicroservice/AuthenticationMicroservice/Models/DTOs/UserDTO.cs
@@ -34,27 +34,21 @@ public class UserRegisterRequestDTO : UserDTO
     [Required]
     [StringLength(100, MinimumLength = 8)]
     public string? ConfirmPassword { get; set; }
-
-    public string? CallbackUrl { get; set; }
 }
 
-public abstract class ChangeEmailRequestDTO
+public class ChangeEmailRequestDTO
 {
     [Required] public string? NewEmail { get; set; }
 
     [Required] public string? ConfirmEmail { get; set; }
-
-    [Required] public string? CallbackUrl { get; set; }
 }
 
-public abstract class ForgotPasswordRequestDTO
+public class ForgotPasswordRequestDTO
 {
     [Required] public string? EmailAddress { get; set; }
-
-    [Required] public string? CallbackUrl { get; set; }
 }
 
-public abstract class SetPasswordRequestDTO
+public class SetPasswordRequestDTO
 {
     [Required] public string? Token { get; set; }
 
@@ -67,7 +61,7 @@ public abstract class SetPasswordRequestDTO
     public string? ConfirmPassword { get; set; }
 }
 
-public abstract class ChangePasswordRequestDTO
+public class ChangePasswordRequestDTO
 {
     [Required] public string? OldPassword { get; set; }
 
@@ -96,8 +90,4 @@ public class AuthenticatedUserDTO
     public string? RefreshToken { get; set; }
 
     public long RefreshTokenExpires { get; set; }
-
-    public string? ProfilePictureUrl { get; set; }
-
-    public string? ProfilePictureSas { get; set; }
 }
\ No newline at end of file
diff --git a/AuthenticationMicroservice/AuthenticationMicroservice/Program.cs b/AuthenticationMicroservice/AuthenticationMicroservice/Program.cs
index c6ad4e2..1cfba12 100644
--- a/AuthenticationMicroservice/AuthenticationMicroservice/Program.cs
+++ b/AuthenticationMicroservice/AuthenticationMicroservice/Program.cs
@@ -98,7 +98,7 @@ builder.Services.AddCors(options =>
     options.AddDefaultPolicy(
         corsPolicyBuilder =>
         {
-            corsPolicyBuilder.WithOrigins(builder.Configuration.GetSection("Group17Website")["BaseUrl"] ?? string.Empty)
+            corsPolicyBuilder.WithOrigins(builder.Configuration.GetSection("FrontendStrings")["BaseUrl"] ?? string.Empty)
                 .AllowAnyHeader()
                 .AllowAnyMethod()
                 .AllowCredentials();
diff --git a/AuthenticationMicroservice/AuthenticationMicroservice/Services/AuthService.cs b/AuthenticationMicroservice/AuthenticationMicroservice/Services/AuthService.cs
index f766974..2c2dce2 100644
--- a/AuthenticationMicroservice/AuthenticationMicroservice/Services/AuthService.cs
+++ b/AuthenticationMicroservice/AuthenticationMicroservice/Services/AuthService.cs
@@ -127,7 +127,7 @@ public class AuthService : IAuthService
             throw new AuthenticationException("User not found.", HttpStatusCode.Unauthorized);
         if (string.IsNullOrWhiteSpace(user.UnconfirmedEmail))
             throw new AuthenticationException("Email already confirmed.", HttpStatusCode.BadRequest);
-        var tryParse = TryParse(token, out var parsedToken);
+        var tryParse = TryParse(token[1..], out var parsedToken);
         if (!tryParse)
             throw new AuthenticationException("Token in request is not valid.");
         if (user.EmailConfirmationToken != parsedToken)
@@ -155,8 +155,7 @@ public class AuthService : IAuthService
 
     public async Task ForgotPassword(ForgotPasswordRequestDTO request)
     {
-        var user = await _context.User.FirstOrDefaultAsync(u =>
-            string.Equals(u.EmailAddress, request.EmailAddress, StringComparison.CurrentCultureIgnoreCase));
+        var user = await _context.User.FirstOrDefaultAsync(u => u.EmailAddress == request.EmailAddress);
         if (user == null)
             throw new AuthenticationException($"User with email: {request.EmailAddress} does not exist.",
                 HttpStatusCode.Unauthorized);
@@ -175,7 +174,7 @@ public class AuthService : IAuthService
     {
         if (string.IsNullOrWhiteSpace(request.Password))
             throw new SecurityHelper.InvalidPasswordException("Please enter a password.");
-        var tryParse = TryParse(request.Token, out var token);
+        var tryParse = TryParse(request.Token?[1..], out var token);
         if (!tryParse)
             throw new AuthenticationException("Token in request is not valid.");
         var user = _context.User.FirstOrDefault(u => u.PasswordResetToken == token);
diff --git a/Frontend/API/Group17AuthApi.cs b/Frontend/API/Group17AuthApi.cs
index 8012efb..2cea8ed 100644
--- a/Frontend/API/Group17AuthApi.cs
+++ b/Frontend/API/Group17AuthApi.cs
@@ -1525,12 +1525,6 @@ namespace Group17.Auth
         [Newtonsoft.Json.JsonProperty("refreshTokenExpires", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
         public long RefreshTokenExpires { get; set; }
 
-        [Newtonsoft.Json.JsonProperty("profilePictureUrl", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
-        public string ProfilePictureUrl { get; set; }
-
-        [Newtonsoft.Json.JsonProperty("profilePictureSas", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
-        public string ProfilePictureSas { get; set; }
-
     }
 
     [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
@@ -1598,10 +1592,6 @@ namespace Group17.Auth
         [System.ComponentModel.DataAnnotations.Required]
         public string ConfirmEmail { get; set; }
 
-        [Newtonsoft.Json.JsonProperty("callbackUrl", Required = Newtonsoft.Json.Required.Always)]
-        [System.ComponentModel.DataAnnotations.Required]
-        public string CallbackUrl { get; set; }
-
     }
 
     [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
@@ -1739,10 +1729,6 @@ namespace Group17.Auth
         [System.ComponentModel.DataAnnotations.Required]
         public string EmailAddress { get; set; }
 
-        [Newtonsoft.Json.JsonProperty("callbackUrl", Required = Newtonsoft.Json.Required.Always)]
-        [System.ComponentModel.DataAnnotations.Required]
-        public string CallbackUrl { get; set; }
-
     }
 
     [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
@@ -1868,9 +1854,6 @@ namespace Group17.Auth
         [System.ComponentModel.DataAnnotations.StringLength(100, MinimumLength = 8)]
         public string ConfirmPassword { get; set; }
 
-        [Newtonsoft.Json.JsonProperty("callbackUrl", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
-        public string CallbackUrl { get; set; }
-
         [Newtonsoft.Json.JsonProperty("firstName", Required = Newtonsoft.Json.Required.Always)]
         [System.ComponentModel.DataAnnotations.Required]
         public string FirstName { get; set; }
-- 
GitLab