refactor: Entfernte DbContext und Hilfsklassen, die durch 'new' generiert wurden, und injiziert. Testprojekt aufgrund von Generierungsfehlern entfernt.
This commit is contained in:
@@ -9,7 +9,7 @@ namespace StaffDBServer.SharedExtensions
|
||||
[ApiController]
|
||||
public class InfoController : InfoBaseController
|
||||
{
|
||||
public InfoController() : base(new WebApiContext())
|
||||
public InfoController(WebApiContext context) : base(context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,13 @@ namespace StaffDBServer.SharedControllers
|
||||
[JWTAuthorizeAttribute]
|
||||
public class WebAppUserController : BaseMiniController
|
||||
{
|
||||
public WebAppUserController() : base(new WebApiContext())
|
||||
private readonly WebAppUserRepository webAppUserRepository;
|
||||
WebAppUserHelper webAppUserHelper;
|
||||
|
||||
public WebAppUserController(WebApiContext context, WebAppUserRepository webAppUserRepository, WebAppUserHelper webAppUserHelper) : base(context)
|
||||
{
|
||||
this.webAppUserRepository = webAppUserRepository;
|
||||
this.webAppUserHelper = webAppUserHelper;
|
||||
}
|
||||
|
||||
[HttpPost("Culture")]
|
||||
@@ -23,8 +28,6 @@ namespace StaffDBServer.SharedControllers
|
||||
{
|
||||
try
|
||||
{
|
||||
//User Should by in the DB
|
||||
WebAppUserRepository webAppUserRepository = new WebAppUserRepository();
|
||||
WebAppUser userFromDB = await webAppUserRepository.GetByAsync(u => u.LoginName == userFromClient.LoginName, false);
|
||||
|
||||
if (userFromDB != default) //first login, get User from WebAppEmployeeInfo
|
||||
@@ -51,7 +54,7 @@ namespace StaffDBServer.SharedControllers
|
||||
try
|
||||
{
|
||||
var accessToken = Request.Headers[HeaderNames.Authorization];
|
||||
WebAppUserHelper webAppUserHelper = new WebAppUserHelper();
|
||||
|
||||
WebAppUser result = await webAppUserHelper.CheckLoginWithJWTAsync(accessToken, userFromClient.ClientVersion);
|
||||
return new OkObjectResult(result);
|
||||
}
|
||||
@@ -67,8 +70,7 @@ namespace StaffDBServer.SharedControllers
|
||||
public async Task<IActionResult> LoginWithNameAndPasswordAsync([FromBody] WebAppUser userFromClient, int webApiId)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebAppUserHelper webAppUserHelper = new WebAppUserHelper();
|
||||
{
|
||||
var result = await webAppUserHelper.CheckLoginWithNameAndPasswordAsync(userFromClient, webApiId);
|
||||
return new OkObjectResult(result);
|
||||
}
|
||||
@@ -85,7 +87,6 @@ namespace StaffDBServer.SharedControllers
|
||||
{
|
||||
try
|
||||
{
|
||||
WebAppUserHelper webAppUserHelper = new WebAppUserHelper();
|
||||
var result = await webAppUserHelper.CheckLoginWithNameAndPasswordAsync(userFromClient);
|
||||
return new OkObjectResult(result);
|
||||
}
|
||||
|
||||
@@ -14,9 +14,18 @@ namespace StaffDBServer.SharedControllers
|
||||
|
||||
public int GlbWebApiIdStaffDB { get; private set; } = 2;
|
||||
|
||||
public async Task<WebAppUser> CheckLoginWithJWTAsync(StringValues accessToken, string clientVersion)
|
||||
WebAppUserRepository webAppUserRepository;
|
||||
|
||||
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository;
|
||||
|
||||
public WebAppUserHelper(WebAppUserRepository webAppUserRepository, WebAppEmployeeInfoRepository webAppEmployeeInfoRepository)
|
||||
{
|
||||
WebAppUserRepository webAppUserRepository = new WebAppUserRepository();
|
||||
this.webAppUserRepository = webAppUserRepository;
|
||||
this.webAppEmployeeInfoRepository = webAppEmployeeInfoRepository;
|
||||
}
|
||||
|
||||
public async Task<WebAppUser> CheckLoginWithJWTAsync(StringValues accessToken, string clientVersion)
|
||||
{
|
||||
if (!JwtManager.IsValidatJwtTokenSubject(accessToken))
|
||||
{
|
||||
throw new UnauthorizedAccessException($"Not valid JWT");
|
||||
@@ -27,8 +36,7 @@ namespace StaffDBServer.SharedControllers
|
||||
{
|
||||
throw new UnauthorizedAccessException($"Unable to decrypt JWT");
|
||||
}
|
||||
|
||||
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository = new WebAppEmployeeInfoRepository();
|
||||
|
||||
WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == ldapUser.LoginName);
|
||||
if (webAppEmployeeInfo == default)
|
||||
{
|
||||
@@ -63,10 +71,9 @@ namespace StaffDBServer.SharedControllers
|
||||
public async Task<WebAppUser> CheckLoginWithNameAndPasswordAsync(WebAppUser userFromClient, int webAppId)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository = new WebAppEmployeeInfoRepository();
|
||||
{
|
||||
WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == userFromClient.LoginName && x.WebAppId == webAppId);
|
||||
WebAppUserRepository webAppUserRepository = new WebAppUserRepository();
|
||||
|
||||
return await DoCheckLoginWithNameAndPasswordAsync(userFromClient, webAppUserRepository, webAppEmployeeInfoRepository);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -79,9 +86,8 @@ namespace StaffDBServer.SharedControllers
|
||||
{
|
||||
try
|
||||
{
|
||||
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository = new WebAppEmployeeInfoRepository();
|
||||
WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == userFromClient.LoginName && x.WebAppId == GlbWebApiIdStaffDB);
|
||||
WebAppUserRepository webAppUserRepository = new WebAppUserRepository();
|
||||
|
||||
return await DoCheckLoginWithNameAndPasswordAsync(userFromClient, webAppUserRepository, webAppEmployeeInfoRepository);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user