aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Services')
-rw-r--r--src/DevHive.Services/DevHive.Services.csproj4
-rw-r--r--src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs12
-rw-r--r--src/DevHive.Services/Services/UserService.cs20
3 files changed, 17 insertions, 19 deletions
diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj
index 280610d..19f67d8 100644
--- a/src/DevHive.Services/DevHive.Services.csproj
+++ b/src/DevHive.Services/DevHive.Services.csproj
@@ -16,5 +16,9 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DevHive.Common\DevHive.Common.csproj" />
+ </ItemGroup>
+
</Project>
diff --git a/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs b/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs
deleted file mode 100644
index 631808e..0000000
--- a/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace DevHive.Services.Models.Identity.User
-{
- public class TokenServiceModel
- {
- public TokenServiceModel(string token)
- {
- this.Token = token;
- }
-
- public string Token { get; set; }
- }
-} \ No newline at end of file
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 24f74f5..63b8389 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -3,7 +3,6 @@ using DevHive.Data.Repositories;
using DevHive.Services.Options;
using DevHive.Services.Models.Identity.User;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
using DevHive.Data.Models;
using System;
using System.IdentityModel.Tokens.Jwt;
@@ -12,6 +11,7 @@ using Microsoft.IdentityModel.Tokens;
using System.Security.Cryptography;
using System.Text;
using System.Collections.Generic;
+using DevHive.Common.Models.Identity;
namespace DevHive.Services.Services
{
@@ -28,7 +28,7 @@ namespace DevHive.Services.Services
this._jwtOptions = jwtOptions;
}
- public async Task<TokenServiceModel> LoginUser(LoginServiceModel loginModel)
+ public async Task<TokenModel> LoginUser(LoginServiceModel loginModel)
{
if (!await this._userRepository.IsUsernameValid(loginModel.UserName))
throw new ArgumentException("Invalid username!");
@@ -38,10 +38,10 @@ namespace DevHive.Services.Services
if (user.PasswordHash != GeneratePasswordHash(loginModel.Password))
throw new ArgumentException("Incorrect password!");
- return new TokenServiceModel(WriteJWTSecurityToken(user.Role));
+ return new TokenModel(WriteJWTSecurityToken(user.Role));
}
- public async Task<TokenServiceModel> RegisterUser(RegisterServiceModel registerModel)
+ public async Task<TokenModel> RegisterUser(RegisterServiceModel registerModel)
{
if (await this._userRepository.DoesUsernameExist(registerModel.UserName))
throw new ArgumentException("Username already exists!");
@@ -55,7 +55,7 @@ namespace DevHive.Services.Services
await this._userRepository.AddAsync(user);
- return new TokenServiceModel(WriteJWTSecurityToken(user.Role));
+ return new TokenModel(WriteJWTSecurityToken(user.Role));
}
public async Task<UserServiceModel> GetUserById(Guid id)
@@ -76,7 +76,10 @@ namespace DevHive.Services.Services
throw new ArgumentException("Username already exists!");
User user = this._userMapper.Map<User>(updateModel);
- await this._userRepository.EditAsync(user);
+ bool result = await this._userRepository.EditAsync(user);
+
+ if (!result)
+ throw new InvalidOperationException("Unable to edit user!");
return this._userMapper.Map<UserServiceModel>(user);;
}
@@ -87,7 +90,10 @@ namespace DevHive.Services.Services
throw new ArgumentException("User does not exist!");
User user = await this._userRepository.GetByIdAsync(id);
- await this._userRepository.DeleteAsync(user);
+ bool result = await this._userRepository.DeleteAsync(user);
+
+ if (!result)
+ throw new InvalidOperationException("Unable to delete user!");
}
private string GeneratePasswordHash(string password)