aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/UserService.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-17 23:06:12 +0200
committertranstrike <transtrike@gmail.com>2020-12-17 23:06:12 +0200
commit9af49263c0a182acb9c0ba4aa7982bbe51855465 (patch)
treefb5092a24495bfe964cea56ae02ecad04142238f /src/DevHive.Services/Services/UserService.cs
parentfaa2e47b6718c59feadecea176020f3326076d5d (diff)
parentd104a6810dcca58e7003833e5b7c74a7722df879 (diff)
downloadDevHive-9af49263c0a182acb9c0ba4aa7982bbe51855465.tar
DevHive-9af49263c0a182acb9c0ba4aa7982bbe51855465.tar.gz
DevHive-9af49263c0a182acb9c0ba4aa7982bbe51855465.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Services/Services/UserService.cs')
-rw-r--r--src/DevHive.Services/Services/UserService.cs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 6f69d6d..bd9c7c5 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -40,7 +40,7 @@ namespace DevHive.Services.Services
if (user.PasswordHash != GeneratePasswordHash(loginModel.Password))
throw new ArgumentException("Incorrect password!");
- return new TokenModel(WriteJWTSecurityToken(user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
}
public async Task<TokenModel> RegisterUser(RegisterServiceModel registerModel)
@@ -64,7 +64,7 @@ namespace DevHive.Services.Services
await this._userRepository.AddAsync(user);
- return new TokenModel(WriteJWTSecurityToken(user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
}
public async Task<UserServiceModel> GetUserById(Guid id)
@@ -72,7 +72,13 @@ namespace DevHive.Services.Services
User user = await this._userRepository.GetByIdAsync(id)
?? throw new ArgumentException("User does not exist!");
+<<<<<<< HEAD
return this._userMapper.Map<UserServiceModel>(user);
+=======
+ UserServiceModel model = this._userMapper.Map<UserServiceModel>(user);
+
+ return model;
+>>>>>>> d104a6810dcca58e7003833e5b7c74a7722df879
}
public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel)
@@ -110,15 +116,21 @@ namespace DevHive.Services.Services
return string.Join(string.Empty, SHA512.HashData(Encoding.ASCII.GetBytes(password)));
}
- private string WriteJWTSecurityToken(IList<Role> roles)
+ private string WriteJWTSecurityToken(string userName, string passwordHash, IList<Role> roles)
{
byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret);
List<Claim> claims = new()
{
- new Claim(ClaimTypes.Role, roles[0].Name) // TODO: add support for multiple roles
+ new Claim(ClaimTypes.Name, userName),
+ new Claim(ClaimTypes.Hash, passwordHash)
};
+ foreach(var role in roles)
+ {
+ claims.Add(new Claim(ClaimTypes.Role, role.Name));
+ }
+
SecurityTokenDescriptor tokenDescriptor = new()
{
Subject = new ClaimsIdentity(claims),