From 6aad7c9c8a59bcc7a4d2d640ea6979f98300e3de Mon Sep 17 00:00:00 2001 From: esantangelo <enzo020895@gmail.com> Date: Sun, 13 Dec 2020 19:53:06 -0300 Subject: [PATCH] fix-bedelia --- .../Tsi1.Api/Controllers/PostController.cs | 5 +--- .../Tsi1.Api/Controllers/UserController.cs | 24 +++++++++++++++---- .../Tsi1.BusinessLayer/DataLoad/DataLoad.cs | 14 +++++------ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs index a20d5fc..f80f795 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs @@ -11,6 +11,7 @@ using Tsi1.BusinessLayer.Interfaces; namespace Tsi1.Api.Controllers { + [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor + ", " + UserTypes.FacultyAdmin)] [Route("api/[controller]")] [ApiController] public class PostController : ControllerBase @@ -29,8 +30,6 @@ namespace Tsi1.Api.Controllers _emailService = emailService; } - - [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)] [HttpGet("GetPosts/{forumId}")] public async Task<IActionResult> GetPosts(int forumId) { @@ -44,7 +43,6 @@ namespace Tsi1.Api.Controllers return Ok(result.Data); } - [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)] [HttpPost("Create")] public async Task<IActionResult> Create(PostCreateDto newPost) { @@ -74,7 +72,6 @@ namespace Tsi1.Api.Controllers return Ok(result.Data); } - [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)] [HttpDelete("Delete/{postId}")] public async Task<IActionResult> Delete(int postId) { diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs index 9bc016b..c0eb212 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs @@ -64,17 +64,33 @@ namespace Tsi1.Api.Controllers } var result = new ServiceResult<User>(); + var isStudent = true; if (tenant.Data.IsLoginBedelia) { - var bedeliaResult = await _bedeliaService.Login(userName, request.Password); + var userNotStudent = await _userService.GetByUsername(userName, tenant.Data.Id); - if (bedeliaResult.HasError) + if (!userNotStudent.HasError) { - return BadRequest(bedeliaResult.Message); + if (userNotStudent.Data.UserType.Name != UserTypes.Student.ToString()) + { + result.Data = userNotStudent.Data; + isStudent = false; + } + } - result = await _userService.GetByIdentityCard(userName); + if (isStudent) + { + var bedeliaResult = await _bedeliaService.Login(userName, request.Password); + + if (bedeliaResult.HasError) + { + return BadRequest(bedeliaResult.Message); + } + + result = await _userService.GetByIdentityCard(userName); + } } else { diff --git a/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs b/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs index a4ef700..23b7b93 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs @@ -147,7 +147,7 @@ namespace Tsi1.BusinessLayer.DataLoad Student = new Student { TenantId = tenantFing.Id, - IdentityCard = "4932876-0", + IdentityCard = "49328760", }, TenantId = tenantFing.Id, }, @@ -164,7 +164,7 @@ namespace Tsi1.BusinessLayer.DataLoad Student = new Student { TenantId = tenantFing.Id, - IdentityCard = "4932877-6", + IdentityCard = "49328776", }, TenantId = tenantFing.Id, }, @@ -177,10 +177,10 @@ namespace Tsi1.BusinessLayer.DataLoad Password = "mathias", FirstName = "Mathias", LastName = "Martinez", - Email = "mathias@mail.com", + Email = "mathias.martinez.fernandez@gmail.com", Student = new Student { - IdentityCard = "1234567-8", + IdentityCard = "50540723", TenantId = tenantFing.Id, }, TenantId = tenantFing.Id, @@ -244,11 +244,11 @@ namespace Tsi1.BusinessLayer.DataLoad Password = "rodriguez", FirstName = "Marcelo", LastName = "Rodriguez", - Email = "marcelo@gmail.com", + Email = "cmarceorp@gmail.com", Student = new Student { TenantId = tenantFmed.Id, - IdentityCard = "76347887-0", + IdentityCard = "42567630", }, TenantId = tenantFmed.Id, }, @@ -265,7 +265,7 @@ namespace Tsi1.BusinessLayer.DataLoad Student = new Student { TenantId = tenantFmed.Id, - IdentityCard = "73642873-6", + IdentityCard = "46728282", }, TenantId = tenantFmed.Id, }, -- GitLab