Website Summary Files Commits Branches @commit @diff @stats
path: root / src / DevHive.Services / Services / UserService.cs
diff options
context:
space:
mode:
Commit8179af787a7bf375753a178b89111a91d84a8bb8 (patch)
Author
 transtrike <transtrike@gmail.com>
2021-01-20 18:07:58 +0200
Committer
 transtrike <transtrike@gmail.com>
2021-01-20 18:07:58 +0200
Fileseb2dbeb52e0875ddc06d5e6ca1bd97ef8d941d4e /src/DevHive.Services/Services/UserService.cs
DevHive-8179af787a7bf375753a178b89111a91d84a8bb8.tar
DevHive-8179af787a7bf375753a178b89111a91d84a8bb8.tar.gz
DevHive-8179af787a7bf375753a178b89111a91d84a8bb8.zip
Parentaa4f7bdd9a2df09fc47e82c2b85fb7647203ba8d (diff)
Changed List to HashSet for "no duplicates" scenario
1 files changed, 6 insertions, 6 deletions
-rw-r--r--src/DevHive.Services/Services/UserService.cs12
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index ee4b24d..51c4432 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -75,7 +75,7 @@ namespace DevHive.Services.Services
// Set the default role to the user
Role defaultRole = await this._roleRepository.GetByNameAsync(Role.DefaultRole);
- user.Roles = new List<Role>() { defaultRole };
+ user.Roles = new HashSet<Role>() { defaultRole };
await this._userRepository.AddAsync(user);
@@ -144,12 +144,12 @@ namespace DevHive.Services.Services
await this.ValidateUserCollections(updateUserServiceModel);
- List<Language> languages = new();
+ HashSet<Language> languages = new();
foreach (UpdateUserCollectionServiceModel lang in updateUserServiceModel.Languages)
languages.Add(await this._languageRepository.GetByNameAsync(lang.Name) ??
throw new ArgumentException("Invalid language name!"));
- List<Technology> technologies = new();
+ HashSet<Technology> technologies = new();
foreach (UpdateUserCollectionServiceModel tech in updateUserServiceModel.Technologies)
technologies.Add(await this._technologyRepository.GetByNameAsync(tech.Name) ??
throw new ArgumentException("Invalid technology name!"));
@@ -257,7 +257,7 @@ namespace DevHive.Services.Services
// There is authorization name in the beginning, i.e. "Bearer eyJh..."
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7));
- Guid jwtUserID = new Guid(this.GetClaimTypeValues("ID", jwt.Claims)[0]);
+ Guid jwtUserID = new Guid(this.GetClaimTypeValues("ID", jwt.Claims).First());
List<string> jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims);
User user = await this._userRepository.GetByIdAsync(jwtUserID)
@@ -326,11 +326,11 @@ namespace DevHive.Services.Services
}
}
- private string WriteJWTSecurityToken(Guid userId, IList<Role> roles)
+ private string WriteJWTSecurityToken(Guid userId, HashSet<Role> roles)
{
byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret);
- List<Claim> claims = new()
+ HashSet<Claim> claims = new()
{
new Claim("ID", $"{userId}"),
};