From ad3b8e0070c0abdf0b87bd50428e509e1bff2d8e Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Feb 2021 18:16:37 +0200 Subject: Restructure Successful --- .../Attributes/GoodPasswordModelValidation.cs | 24 ++++++++++++++++++++++ .../Attributes/OnlyLettersModelValidation.cs | 20 ++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs create mode 100644 src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs (limited to 'src/Web/DevHive.Web.Models/Attributes') diff --git a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs new file mode 100644 index 0000000..5ecb41a --- /dev/null +++ b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DevHive.Web.Models.Attributes +{ + public class GoodPassword : ValidationAttribute + { + public override bool IsValid(object value) + { + var stringValue = (string)value; + + for (int i = 0; i < stringValue.Length; i++) + { + if (Char.IsDigit(stringValue[i])) + { + base.ErrorMessage = "Password must be atleast 5 characters long!"; + return stringValue.Length >= 5; + } + } + base.ErrorMessage = "Password must contain atleast 1 digit!"; + return false; + } + } +} diff --git a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs new file mode 100644 index 0000000..0f6adb1 --- /dev/null +++ b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs @@ -0,0 +1,20 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DevHive.Web.Models.Attributes +{ + public class OnlyLetters : ValidationAttribute + { + public override bool IsValid(object value) + { + var stringValue = (string)value; + + foreach (char ch in stringValue) + { + if (!Char.IsLetter(ch)) + return false; + } + return true; + } + } +} -- cgit v1.2.3 From 4c03712af14c37718b7be5b23fcadeb86f2a2191 Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 15 Feb 2021 19:06:14 +0200 Subject: Code Analyzer added to all csproj; Removed unnessessary code; Fixed formatting --- .../DevHive.Common.Models/DevHive.Common.csproj | 1 + .../DevHive.Data.Models/DevHive.Data.Models.csproj | 1 + .../DevHive.Data.Tests/DevHive.Data.Tests.csproj | 13 +++--- src/Data/DevHive.Data/DevHive.Data.csproj | 1 + .../DevHive.Services.Models.csproj | 9 ++-- .../DevHive.Services.Tests.csproj | 13 +++--- .../DevHive.Services.Tests/UserService.Tests.cs | 8 ++-- .../Configurations/Mapping/PostMappings.cs | 1 - .../Configurations/Mapping/RatingMappings.cs | 2 - .../DevHive.Services/DevHive.Services.csproj | 17 +++---- .../DevHive.Services/Interfaces/ICloudService.cs | 2 - .../DevHive.Services/Interfaces/IRoleService.cs | 2 +- .../DevHive.Services/Options/JWTOptions.cs | 14 ------ .../DevHive.Services/Options/JwtOptions.cs | 14 ++++++ .../DevHive.Services/Services/FeedService.cs | 2 +- .../DevHive.Services/Services/PostService.cs | 15 +++--- .../DevHive.Services/Services/RateService.cs | 2 +- .../DevHive.Services/Services/RoleService.cs | 9 ++-- .../DevHive.Services/Services/UserService.cs | 15 +++--- .../Attributes/GoodPasswordAttribute.cs | 23 +++++++++ .../Attributes/GoodPasswordModelValidation.cs | 24 ---------- .../Attributes/OnlyLettersModelValidation.cs | 4 +- .../DevHive.Web.Models/DevHive.Web.Models.csproj | 8 ++-- .../DevHive.Web.Models/Post/ReadPostWebModel.cs | 1 - .../DevHive.Web.Tests/CommentController.Tests.cs | 35 +++++++------- src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj | 11 +++-- .../DevHive.Web.Tests/LanguageController.Tests.cs | 4 +- src/Web/DevHive.Web.Tests/PostController.Tests.cs | 29 ++++++------ src/Web/DevHive.Web.Tests/RoleController.Tests.cs | 4 +- .../TechnologyController.Tests.cs | 4 +- src/Web/DevHive.Web.Tests/UserController.Tests.cs | 46 ++++++++---------- .../Extensions/ConfigureAutoMapper.cs | 5 +- .../ConfigureExceptionHandlerMiddleware.cs | 2 - .../Configurations/Extensions/ConfigureJWT.cs | 54 ---------------------- .../Configurations/Extensions/ConfigureJwt.cs | 54 ++++++++++++++++++++++ src/Web/DevHive.Web/DevHive.Web.csproj | 21 +++++---- .../DevHive.Web/Middleware/ExceptionMiddleware.cs | 14 ++---- 37 files changed, 229 insertions(+), 255 deletions(-) delete mode 100644 src/Services/DevHive.Services/Options/JWTOptions.cs create mode 100644 src/Services/DevHive.Services/Options/JwtOptions.cs create mode 100644 src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs delete mode 100644 src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs delete mode 100644 src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs create mode 100644 src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs (limited to 'src/Web/DevHive.Web.Models/Attributes') diff --git a/src/Common/DevHive.Common.Models/DevHive.Common.csproj b/src/Common/DevHive.Common.Models/DevHive.Common.csproj index 4829c80..f6d662c 100644 --- a/src/Common/DevHive.Common.Models/DevHive.Common.csproj +++ b/src/Common/DevHive.Common.Models/DevHive.Common.csproj @@ -4,6 +4,7 @@ + true diff --git a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj index e58a6d8..e9dc644 100644 --- a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj +++ b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj index 568edda..2af369f 100644 --- a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -4,14 +4,15 @@ false - - - - - + + + + + + - + true diff --git a/src/Data/DevHive.Data/DevHive.Data.csproj b/src/Data/DevHive.Data/DevHive.Data.csproj index fac1581..46928c6 100644 --- a/src/Data/DevHive.Data/DevHive.Data.csproj +++ b/src/Data/DevHive.Data/DevHive.Data.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj index 3f0eadf..914efe0 100644 --- a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj +++ b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj @@ -2,12 +2,11 @@ net5.0 - - + + - - + - + \ No newline at end of file diff --git a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj index eb33d07..bdfb2bb 100644 --- a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -4,14 +4,15 @@ false - - - - - + + + + + + - + true diff --git a/src/Services/DevHive.Services.Tests/UserService.Tests.cs b/src/Services/DevHive.Services.Tests/UserService.Tests.cs index 8fddce7..ce997c1 100644 --- a/src/Services/DevHive.Services.Tests/UserService.Tests.cs +++ b/src/Services/DevHive.Services.Tests/UserService.Tests.cs @@ -29,7 +29,7 @@ namespace DevHive.Services.Tests private Mock LanguageRepositoryMock { get; set; } private Mock TechnologyRepositoryMock { get; set; } private Mock MapperMock { get; set; } - private JWTOptions JWTOptions { get; set; } + private JwtOptions JwtOptions { get; set; } private UserService UserService { get; set; } #region SetUps @@ -41,10 +41,10 @@ namespace DevHive.Services.Tests this.CloudServiceMock = new Mock(); this.LanguageRepositoryMock = new Mock(); this.TechnologyRepositoryMock = new Mock(); - this.JWTOptions = new JWTOptions("gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm"); + this.JwtOptions = new JwtOptions("gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm"); this.MapperMock = new Mock(); // TODO: give actual UserManager and RoleManager to UserService - this.UserService = new UserService(this.UserRepositoryMock.Object, this.LanguageRepositoryMock.Object, this.RoleRepositoryMock.Object, this.TechnologyRepositoryMock.Object, null, null, this.MapperMock.Object, this.JWTOptions, this.CloudServiceMock.Object); + this.UserService = new UserService(this.UserRepositoryMock.Object, this.LanguageRepositoryMock.Object, this.RoleRepositoryMock.Object, this.TechnologyRepositoryMock.Object, null, null, this.MapperMock.Object, this.JwtOptions, this.CloudServiceMock.Object); } #endregion @@ -364,7 +364,7 @@ namespace DevHive.Services.Tests #region HelperMethods private string WriteJWTSecurityToken(Guid userId, string username, HashSet roles) { - byte[] signingKey = Encoding.ASCII.GetBytes(this.JWTOptions.Secret); + byte[] signingKey = Encoding.ASCII.GetBytes(this.JwtOptions.Secret); HashSet claims = new() { new Claim("ID", $"{userId}"), diff --git a/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs index 9362f90..1d7d88b 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -12,7 +12,6 @@ namespace DevHive.Services.Configurations.Mapping public PostMappings() { CreateMap(); - // .ForMember(dest => dest.Files, src => src.Ignore()); CreateMap() .ForMember(dest => dest.Id, src => src.MapFrom(p => p.PostId)) // .ForMember(dest => dest.Files, src => src.Ignore()) diff --git a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs index 1dbb7b4..fefa6d8 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -8,8 +8,6 @@ namespace DevHive.Services.Configurations.Mapping { public RatingMappings() { - // CreateMap() - // .ForMember(dest => dest.PostId, src => src.MapFrom(p => p.Post.Id)); } } } diff --git a/src/Services/DevHive.Services/DevHive.Services.csproj b/src/Services/DevHive.Services/DevHive.Services.csproj index b09c46d..650a304 100644 --- a/src/Services/DevHive.Services/DevHive.Services.csproj +++ b/src/Services/DevHive.Services/DevHive.Services.csproj @@ -3,22 +3,23 @@ net5.0 - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - + + + + + - - + + true latest - + \ No newline at end of file diff --git a/src/Services/DevHive.Services/Interfaces/ICloudService.cs b/src/Services/DevHive.Services/Interfaces/ICloudService.cs index 3ae7a24..040729f 100644 --- a/src/Services/DevHive.Services/Interfaces/ICloudService.cs +++ b/src/Services/DevHive.Services/Interfaces/ICloudService.cs @@ -9,8 +9,6 @@ namespace DevHive.Services.Interfaces { Task> UploadFilesToCloud(List formFiles); - // Task> GetFilesFromCloud(List fileUrls); - Task RemoveFilesFromCloud(List fileUrls); } } diff --git a/src/Services/DevHive.Services/Interfaces/IRoleService.cs b/src/Services/DevHive.Services/Interfaces/IRoleService.cs index 2c31b06..05df917 100644 --- a/src/Services/DevHive.Services/Interfaces/IRoleService.cs +++ b/src/Services/DevHive.Services/Interfaces/IRoleService.cs @@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces { public interface IRoleService { - Task CreateRole(CreateRoleServiceModel roleServiceModel); + Task CreateRole(CreateRoleServiceModel createRoleServiceModel); Task GetRoleById(Guid id); diff --git a/src/Services/DevHive.Services/Options/JWTOptions.cs b/src/Services/DevHive.Services/Options/JWTOptions.cs deleted file mode 100644 index 95458f5..0000000 --- a/src/Services/DevHive.Services/Options/JWTOptions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Extensions.Options; - -namespace DevHive.Services.Options -{ - public class JWTOptions - { - public JWTOptions(string secret) - { - this.Secret = secret; - } - - public string Secret { get; init; } - } -} diff --git a/src/Services/DevHive.Services/Options/JwtOptions.cs b/src/Services/DevHive.Services/Options/JwtOptions.cs new file mode 100644 index 0000000..d973f45 --- /dev/null +++ b/src/Services/DevHive.Services/Options/JwtOptions.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.Options; + +namespace DevHive.Services.Options +{ + public class JwtOptions + { + public JwtOptions(string secret) + { + this.Secret = secret; + } + + public string Secret { get; init; } + } +} diff --git a/src/Services/DevHive.Services/Services/FeedService.cs b/src/Services/DevHive.Services/Services/FeedService.cs index 5feef6e..17cc43f 100644 --- a/src/Services/DevHive.Services/Services/FeedService.cs +++ b/src/Services/DevHive.Services/Services/FeedService.cs @@ -57,7 +57,7 @@ namespace DevHive.Services.Services /// /// This method is used in the profile pages. - /// See the FeedRepository "GetUsersPosts" menthod for more information on how it works. + /// See the FeedRepository "GetUsersPosts" method for more information on how it works. /// public async Task GetUserPage(GetPageServiceModel model) { diff --git a/src/Services/DevHive.Services/Services/PostService.cs b/src/Services/DevHive.Services/Services/PostService.cs index 0becd9f..a3d5117 100644 --- a/src/Services/DevHive.Services/Services/PostService.cs +++ b/src/Services/DevHive.Services/Services/PostService.cs @@ -41,7 +41,7 @@ namespace DevHive.Services.Services if (createPostServiceModel.Files.Count != 0) { List fileUrls = await _cloudService.UploadFilesToCloud(createPostServiceModel.Files); - post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); + post.Attachments = GetPostAttachmentsFromUrls(post, fileUrls); } post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId); @@ -105,8 +105,8 @@ namespace DevHive.Services.Services } List fileUrls = await _cloudService.UploadFilesToCloud(updatePostServiceModel.Files) ?? - throw new ArgumentNullException("Unable to upload images to cloud"); - post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); + throw new ArgumentException("Unable to upload images to cloud!"); + post.Attachments = GetPostAttachmentsFromUrls(post, fileUrls); } post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); @@ -202,8 +202,7 @@ namespace DevHive.Services.Services { JwtSecurityToken jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); - Guid jwtUserId = Guid.Parse(this.GetClaimTypeValues("ID", jwt.Claims).First()); - //HashSet jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); + Guid jwtUserId = Guid.Parse(GetClaimTypeValues("ID", jwt.Claims).First()); User user = await this._userRepository.GetByIdAsync(jwtUserId) ?? throw new ArgumentException("User does not exist!"); @@ -214,7 +213,7 @@ namespace DevHive.Services.Services /// /// Returns all values from a given claim type /// - private List GetClaimTypeValues(string type, IEnumerable claims) + private static List GetClaimTypeValues(string type, IEnumerable claims) { List toReturn = new(); @@ -227,9 +226,9 @@ namespace DevHive.Services.Services #endregion #region Misc - private List GetPostAttachmentsFromUrls(Post post, List fileUrls) + private static List GetPostAttachmentsFromUrls(Post post, List fileUrls) { - List postAttachments = new List(); + List postAttachments = new(); foreach (string url in fileUrls) postAttachments.Add(new PostAttachments { Post = post, FileUrl = url }); return postAttachments; diff --git a/src/Services/DevHive.Services/Services/RateService.cs b/src/Services/DevHive.Services/Services/RateService.cs index d423d8c..5e924ab 100644 --- a/src/Services/DevHive.Services/Services/RateService.cs +++ b/src/Services/DevHive.Services/Services/RateService.cs @@ -28,7 +28,7 @@ namespace DevHive.Services.Services { throw new NotImplementedException(); // if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId)) - // throw new ArgumentException("Post does not exist!"); + // throw new ArgumentException("Post does not exist!"); // if (!await this._userRepository.DoesUserExistAsync(ratePostServiceModel.UserId)) // throw new ArgumentException("User does not exist!"); diff --git a/src/Services/DevHive.Services/Services/RoleService.cs b/src/Services/DevHive.Services/Services/RoleService.cs index 5472e44..1285421 100644 --- a/src/Services/DevHive.Services/Services/RoleService.cs +++ b/src/Services/DevHive.Services/Services/RoleService.cs @@ -5,7 +5,6 @@ using DevHive.Data.Interfaces; using DevHive.Data.Models; using DevHive.Services.Interfaces; using DevHive.Services.Models.Role; -using DevHive.Services.Models.Language; namespace DevHive.Services.Services { @@ -20,17 +19,17 @@ namespace DevHive.Services.Services this._roleMapper = mapper; } - public async Task CreateRole(CreateRoleServiceModel roleServiceModel) + public async Task CreateRole(CreateRoleServiceModel createRoleServiceModel) { - if (await this._roleRepository.DoesNameExist(roleServiceModel.Name)) + if (await this._roleRepository.DoesNameExist(createRoleServiceModel.Name)) throw new ArgumentException("Role already exists!"); - Role role = this._roleMapper.Map(roleServiceModel); + Role role = this._roleMapper.Map(createRoleServiceModel); bool success = await this._roleRepository.AddAsync(role); if (success) { - Role newRole = await this._roleRepository.GetByNameAsync(roleServiceModel.Name); + Role newRole = await this._roleRepository.GetByNameAsync(createRoleServiceModel.Name); return newRole.Id; } else diff --git a/src/Services/DevHive.Services/Services/UserService.cs b/src/Services/DevHive.Services/Services/UserService.cs index 9a63853..e31eb8d 100644 --- a/src/Services/DevHive.Services/Services/UserService.cs +++ b/src/Services/DevHive.Services/Services/UserService.cs @@ -28,7 +28,7 @@ namespace DevHive.Services.Services private readonly UserManager _userManager; private readonly RoleManager _roleManager; private readonly IMapper _userMapper; - private readonly JWTOptions _jwtOptions; + private readonly JwtOptions _jwtOptions; private readonly ICloudService _cloudService; public UserService(IUserRepository userRepository, @@ -38,7 +38,7 @@ namespace DevHive.Services.Services UserManager userManager, RoleManager roleManager, IMapper mapper, - JWTOptions jwtOptions, + JwtOptions jwtOptions, ICloudService cloudService) { this._userRepository = userRepository; @@ -128,7 +128,7 @@ namespace DevHive.Services.Services User currentUser = await this._userRepository.GetByIdAsync(updateUserServiceModel.Id); await this.PopulateUserModel(currentUser, updateUserServiceModel); - if (updateUserServiceModel.Friends.Count() > 0) + if (updateUserServiceModel.Friends.Count > 0) await this.CreateRelationToFriends(currentUser, updateUserServiceModel.Friends.ToList()); else currentUser.Friends.Clear(); @@ -157,7 +157,7 @@ namespace DevHive.Services.Services } string fileUrl = (await this._cloudService.UploadFilesToCloud(new List { updateProfilePictureServiceModel.Picture }))[0] ?? - throw new ArgumentNullException("Unable to upload profile picture to cloud"); + throw new ArgumentException("Unable to upload profile picture to cloud"); bool successful = await this._userRepository.UpdateProfilePicture(updateProfilePictureServiceModel.UserId, fileUrl); @@ -201,16 +201,13 @@ namespace DevHive.Services.Services /* Check if user is trying to do something to himself, unless he's an admin */ /* Check roles */ - if (!jwtRoleNames.Contains(Role.AdminRole)) - if (user.Id != id) - return false; + if (!jwtRoleNames.Contains(Role.AdminRole) && user.Id != id) + return false; // Check if jwt contains all user roles (if it doesn't, jwt is either old or tampered with) foreach (var role in user.Roles) - { if (!jwtRoleNames.Contains(role.Name)) return false; - } // Check if jwt contains only roles of user if (jwtRoleNames.Count != user.Roles.Count) diff --git a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs new file mode 100644 index 0000000..c452499 --- /dev/null +++ b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; + +namespace DevHive.Web.Models.Attributes +{ + public class GoodPasswordAttribute : ValidationAttribute + { + public override bool IsValid(object value) + { + var stringValue = (string)value; + + for (int i = 0; i < stringValue.Length; i++) + { + if (char.IsDigit(stringValue[i])) + { + base.ErrorMessage = "Password must be atleast 5 characters long!"; + return stringValue.Length >= 5; + } + } + base.ErrorMessage = "Password must contain atleast 1 digit!"; + return false; + } + } +} diff --git a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs deleted file mode 100644 index 5ecb41a..0000000 --- a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; - -namespace DevHive.Web.Models.Attributes -{ - public class GoodPassword : ValidationAttribute - { - public override bool IsValid(object value) - { - var stringValue = (string)value; - - for (int i = 0; i < stringValue.Length; i++) - { - if (Char.IsDigit(stringValue[i])) - { - base.ErrorMessage = "Password must be atleast 5 characters long!"; - return stringValue.Length >= 5; - } - } - base.ErrorMessage = "Password must contain atleast 1 digit!"; - return false; - } - } -} diff --git a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs index 0f6adb1..faaeee4 100644 --- a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs +++ b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; namespace DevHive.Web.Models.Attributes { - public class OnlyLetters : ValidationAttribute + public class OnlyLettersAttribute : ValidationAttribute { public override bool IsValid(object value) { @@ -11,7 +11,7 @@ namespace DevHive.Web.Models.Attributes foreach (char ch in stringValue) { - if (!Char.IsLetter(ch)) + if (!char.IsLetter(ch)) return false; } return true; diff --git a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj index ca49b8c..64d0bd0 100644 --- a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj +++ b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj @@ -3,10 +3,10 @@ net5.0 - + - - + + - + \ No newline at end of file diff --git a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs index 8238f47..3ae93aa 100644 --- a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs +++ b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs @@ -21,6 +21,5 @@ namespace DevHive.Web.Models.Post public List Comments { get; set; } public List FileUrls { get; set; } - // public List Files { get; set; } } } diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 3a03f1a..98397e7 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -35,11 +35,11 @@ namespace DevHive.Web.Tests public void AddComment_ReturnsOkObjectResult_WhenCommentIsSuccessfullyCreated() { Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; - CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel + CreateCommentServiceModel createCommentServiceModel = new() { Message = MESSAGE }; @@ -67,11 +67,11 @@ namespace DevHive.Web.Tests public void AddComment_ReturnsBadRequestObjectResult_WhenCommentIsNotCreatedSuccessfully() { Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; - CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel + CreateCommentServiceModel createCommentServiceModel = new() { Message = MESSAGE }; @@ -86,8 +86,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } @@ -95,8 +95,7 @@ namespace DevHive.Web.Tests [Test] public void AddComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; @@ -115,11 +114,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - ReadCommentServiceModel readCommentServiceModel = new ReadCommentServiceModel + ReadCommentServiceModel readCommentServiceModel = new() { Message = MESSAGE }; - ReadCommentWebModel readCommentWebModel = new ReadCommentWebModel + ReadCommentWebModel readCommentWebModel = new() { Message = MESSAGE }; @@ -132,7 +131,7 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); OkObjectResult okObjectResult = result as OkObjectResult; - ReadCommentWebModel resultModel = okObjectResult.Value as Models.Comment.ReadCommentWebModel; + ReadCommentWebModel resultModel = okObjectResult.Value as ReadCommentWebModel; Assert.AreEqual(MESSAGE, resultModel.Message); } @@ -143,11 +142,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenCommentIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; - UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel + UpdateCommentServiceModel updateCommentServiceModel = new() { NewMessage = MESSAGE }; @@ -171,11 +170,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnBadObjectResult_WhenCommentIsNotUpdatedSuccessfully() { string message = "Unable to update comment!"; - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; - UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel + UpdateCommentServiceModel updateCommentServiceModel = new() { NewMessage = MESSAGE }; @@ -196,7 +195,7 @@ namespace DevHive.Web.Tests [Test] public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized() { - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; @@ -224,7 +223,7 @@ namespace DevHive.Web.Tests } [Test] - public void DeletComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully() + public void DeleteComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully() { string message = "Could not delete Comment"; Guid id = Guid.NewGuid(); @@ -243,7 +242,7 @@ namespace DevHive.Web.Tests } [Test] - public void DeletComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() + public void DeleteComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); diff --git a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj index f8390de..465698c 100644 --- a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -4,13 +4,14 @@ false - - - - + + + + + - + true diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs index 7c8d64e..af4672a 100644 --- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs @@ -81,8 +81,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index 96b0356..f10f8dd 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -32,11 +32,11 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsOkObjectResult_WhenPostIsSuccessfullyCreated() { - CreatePostWebModel createPostWebModel = new CreatePostWebModel + CreatePostWebModel createPostWebModel = new() { Message = MESSAGE }; - CreatePostServiceModel createPostServiceModel = new CreatePostServiceModel + CreatePostServiceModel createPostServiceModel = new() { Message = MESSAGE }; @@ -64,11 +64,11 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsBadRequestObjectResult_WhenPostIsNotCreatedSuccessfully() { - CreatePostWebModel createTechnologyWebModel = new CreatePostWebModel + CreatePostWebModel createTechnologyWebModel = new() { Message = MESSAGE }; - CreatePostServiceModel createTechnologyServiceModel = new CreatePostServiceModel + CreatePostServiceModel createTechnologyServiceModel = new() { Message = MESSAGE }; @@ -83,8 +83,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } @@ -92,8 +92,7 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - CreatePostWebModel createPostWebModel = new CreatePostWebModel + CreatePostWebModel createPostWebModel = new() { Message = MESSAGE }; @@ -112,11 +111,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - ReadPostServiceModel readPostServiceModel = new ReadPostServiceModel + ReadPostServiceModel readPostServiceModel = new() { Message = MESSAGE }; - ReadPostWebModel readPostWebModel = new ReadPostWebModel + ReadPostWebModel readPostWebModel = new() { Message = MESSAGE }; @@ -140,11 +139,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenPostIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; - UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel + UpdatePostServiceModel updatePostServiceModel = new() { NewMessage = MESSAGE }; @@ -163,11 +162,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); string message = "Could not update post!"; - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; - UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel + UpdatePostServiceModel updatePostServiceModel = new() { NewMessage = MESSAGE }; @@ -188,7 +187,7 @@ namespace DevHive.Web.Tests [Test] public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized() { - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index 64e3f11..ff80dc0 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -81,8 +81,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs index 164bcbf..a00f1db 100644 --- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -84,8 +84,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index 7457ad7..13f618e 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -33,17 +33,17 @@ namespace DevHive.Web.Tests public void LoginUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyLoggedIn() { Guid id = Guid.NewGuid(); - LoginWebModel loginWebModel = new LoginWebModel + LoginWebModel loginWebModel = new() { UserName = USERNAME }; - LoginServiceModel loginServiceModel = new LoginServiceModel + LoginServiceModel loginServiceModel = new() { UserName = USERNAME }; string token = "goshotrapov"; - TokenModel tokenModel = new TokenModel(token); - TokenWebModel tokenWebModel = new TokenWebModel(token); + TokenModel tokenModel = new(token); + TokenWebModel tokenWebModel = new(token); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(loginServiceModel); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); @@ -61,18 +61,17 @@ namespace DevHive.Web.Tests [Test] public void RegisterUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyRegistered() { - Guid id = Guid.NewGuid(); - RegisterWebModel registerWebModel = new RegisterWebModel + RegisterWebModel registerWebModel = new() { UserName = USERNAME }; - RegisterServiceModel registerServiceModel = new RegisterServiceModel + RegisterServiceModel registerServiceModel = new() { UserName = USERNAME }; string token = "goshotrapov"; - TokenModel tokenModel = new TokenModel(token); - TokenWebModel tokenWebModel = new TokenWebModel(token); + TokenModel tokenModel = new(token); + TokenWebModel tokenWebModel = new(token); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(registerServiceModel); this.MapperMock.Setup(p => p.Map(It.IsAny())).Returns(tokenWebModel); @@ -95,11 +94,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; - UserWebModel userWebModel = new UserWebModel + UserWebModel userWebModel = new() { UserName = USERNAME }; @@ -121,12 +120,6 @@ namespace DevHive.Web.Tests [Test] public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - UserWebModel userWebModel = new UserWebModel - { - UserName = USERNAME - }; - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); IActionResult result = this.UserController.GetById(Guid.NewGuid(), null).Result; @@ -137,12 +130,11 @@ namespace DevHive.Web.Tests [Test] public void GetUser_ReturnsTheUser_WhenItExists() { - Guid id = Guid.NewGuid(); - UserWebModel userWebModel = new UserWebModel + UserWebModel userWebModel = new() { UserName = USERNAME }; - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; @@ -166,15 +158,15 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenUserIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdateUserWebModel updateUserWebModel = new UpdateUserWebModel + UpdateUserWebModel updateUserWebModel = new() { UserName = USERNAME }; - UpdateUserServiceModel updateUserServiceModel = new UpdateUserServiceModel + UpdateUserServiceModel updateUserServiceModel = new() { UserName = USERNAME }; - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; @@ -192,13 +184,13 @@ namespace DevHive.Web.Tests public void UpdateProfilePicture_ShouldReturnOkObjectResult_WhenProfilePictureIsUpdatedSuccessfully() { string profilePictureURL = "goshotrapov"; - UpdateProfilePictureWebModel updateProfilePictureWebModel = new UpdateProfilePictureWebModel(); - UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new UpdateProfilePictureServiceModel(); - ProfilePictureServiceModel profilePictureServiceModel = new ProfilePictureServiceModel + UpdateProfilePictureWebModel updateProfilePictureWebModel = new(); + UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new(); + ProfilePictureServiceModel profilePictureServiceModel = new() { ProfilePictureURL = profilePictureURL }; - ProfilePictureWebModel profilePictureWebModel = new ProfilePictureWebModel + ProfilePictureWebModel profilePictureWebModel = new() { ProfilePictureURL = profilePictureURL }; diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs index 8b7d657..0b8194e 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs @@ -1,6 +1,5 @@ using System; using AutoMapper; -//using AutoMapper.Configuration; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; @@ -15,10 +14,10 @@ namespace DevHive.Web.Configurations.Extensions public static void UseAutoMapperConfiguration(this IApplicationBuilder app) { - var config = new MapperConfiguration(cfg => + _ = new MapperConfiguration(cfg => { cfg.AllowNullCollections = true; }); } } -} \ No newline at end of file +} diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs index 286727f..c017a8c 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs @@ -6,8 +6,6 @@ namespace DevHive.Web.Configurations.Extensions { public static class ConfigureExceptionHandlerMiddleware { - public static void ExceptionHandlerMiddlewareConfiguration(this IServiceCollection services) { } - public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app) { app.UseMiddleware(); diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs deleted file mode 100644 index d422bc8..0000000 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Text; -using System.Threading.Tasks; -using DevHive.Services.Options; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.IdentityModel.Tokens; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class JWTExtensions - { - public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration) - { - services.AddSingleton(new JWTOptions(configuration - .GetSection("AppSettings") - .GetSection("Secret") - .Value)); - - // Get key from appsettings.json - var key = Encoding.ASCII.GetBytes(configuration - .GetSection("AppSettings") - .GetSection("Secret") - .Value); - - // Setup Jwt Authentication - services.AddAuthentication(x => - { - x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(x => - { - x.Events = new JwtBearerEvents - { - OnTokenValidated = context => - { - // TODO: add more authentication - return Task.CompletedTask; - } - }; - x.RequireHttpsMetadata = false; - x.SaveToken = true; - x.TokenValidationParameters = new TokenValidationParameters - { - //ValidateIssuerSigningKey = false, - IssuerSigningKey = new SymmetricSecurityKey(key), - ValidateIssuer = false, - ValidateAudience = false - }; - }); - } - } -} \ No newline at end of file diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs new file mode 100644 index 0000000..03d4b11 --- /dev/null +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs @@ -0,0 +1,54 @@ +using System.Text; +using System.Threading.Tasks; +using DevHive.Services.Options; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Tokens; + +namespace DevHive.Web.Configurations.Extensions +{ + public static class ConfigureJwt + { + public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddSingleton(new JwtOptions(configuration + .GetSection("AppSettings") + .GetSection("Secret") + .Value)); + + // Get key from appsettings.json + var key = Encoding.ASCII.GetBytes(configuration + .GetSection("AppSettings") + .GetSection("Secret") + .Value); + + // Setup Jwt Authentication + services.AddAuthentication(x => + { + x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(x => + { + x.Events = new JwtBearerEvents + { + OnTokenValidated = context => + { + // TODO: add more authentication + return Task.CompletedTask; + } + }; + x.RequireHttpsMetadata = false; + x.SaveToken = true; + x.TokenValidationParameters = new TokenValidationParameters + { + //ValidateIssuerSigningKey = false, + IssuerSigningKey = new SymmetricSecurityKey(key), + ValidateIssuer = false, + ValidateAudience = false + }; + }); + } + } +} diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj index 6f78b69..6511c37 100644 --- a/src/Web/DevHive.Web/DevHive.Web.csproj +++ b/src/Web/DevHive.Web/DevHive.Web.csproj @@ -7,21 +7,22 @@ latest - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + + - - + + \ No newline at end of file diff --git a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs index cb6d4ca..f159b69 100644 --- a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs +++ b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs @@ -9,18 +9,11 @@ namespace DevHive.Web.Middleware public class ExceptionMiddleware { private readonly RequestDelegate _next; - // private readonly ILogger _logger; public ExceptionMiddleware(RequestDelegate next) { this._next = next; - // this._logger = logger; } - // public ExceptionMiddleware(RequestDelegate next, ILogger logger) - // { - // this._logger = logger; - // this._next = next; - // } public async Task InvokeAsync(HttpContext httpContext) { @@ -30,20 +23,19 @@ namespace DevHive.Web.Middleware } catch (Exception ex) { - // this._logger.LogError($"Something went wrong: {ex}"); await HandleExceptionAsync(httpContext, ex); } } - private Task HandleExceptionAsync(HttpContext context, Exception exception) + private static Task HandleExceptionAsync(HttpContext context, Exception exception) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return context.Response.WriteAsync(new { - StatusCode = context.Response.StatusCode, - Message = exception.Message + context.Response.StatusCode, + exception.Message }.ToString()); } } -- cgit v1.2.3