From 9b287f08b8e2c8d091967597bc9610afea8058ca Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 12 Dec 2020 14:47:33 +0200 Subject: Improved appsettings.json reading --- API/Service/UserService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'API/Service') diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index c4f6e92..797a924 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -4,7 +4,7 @@ using AutoMapper; using Data.Models.Classes; using Data.Models.DTOs; using Microsoft.AspNetCore.Mvc; - +using Data.Models.Options; using System.IdentityModel.Tokens.Jwt; using Microsoft.IdentityModel.Tokens; using System.Security.Claims; @@ -18,13 +18,13 @@ namespace API.Service { private readonly UserDbRepository _userDbRepository; private readonly IMapper _userMapper; - private readonly IConfiguration _appSettings; + private readonly JWTOptions _jwtOptions; - public UserService(DevHiveContext context, IMapper mapper, IConfiguration appSettings) + public UserService(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { this._userDbRepository = new UserDbRepository(context); this._userMapper = mapper; - this._appSettings = appSettings; + this._jwtOptions = jwtOptions; } public async Task LoginUser(LoginDTO loginDTO) @@ -35,7 +35,7 @@ namespace API.Service return new NotFoundObjectResult("User does not exist!"); // Get key from appsettings.json - var key = Encoding.ASCII.GetBytes(_appSettings.GetSection("Secret").Value); + var key = Encoding.ASCII.GetBytes(_jwtOptions.Secret); if (user.PasswordHash != GeneratePasswordHash(loginDTO.Password)) return new BadRequestObjectResult("Incorrect password!"); -- cgit v1.2.3