Skip to content
Snippets Groups Projects
Commit dd52bd77 authored by Enzo Santangelo Dodera's avatar Enzo Santangelo Dodera
Browse files

Merge branch 'feature/bedelia-login' into 'develop'

Feature/bedelia login

See merge request !47
parents 194e373f 20d10b1b
No related branches found
No related tags found
1 merge request!47Feature/bedelia login
Pipeline #10665 passed
Showing
with 1274 additions and 2 deletions
......@@ -135,5 +135,23 @@ namespace Bedelia.Controllers
return Ok(result);
}
[HttpPost("login")]
public async Task<IActionResult> Login(UserLoginDto userLoginDto)
{
var user = await _context.Users.FirstOrDefaultAsync(x => x.IdentityCard == userLoginDto.IdentityCard);
if (user == null)
{
return BadRequest(string.Format("el usuario con cédula {0} no existe en bedelia", userLoginDto.IdentityCard));
}
if (user.Password != userLoginDto.Password)
{
return BadRequest(string.Format("Contraseña incorrecta"));
}
return Ok();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace Bedelia.Dtos
{
public class UserLoginDto
{
[Required]
public string IdentityCard { get; set; }
[Required]
public string Password { get; set; }
}
}
......@@ -11,6 +11,7 @@ using Tsi1.Api.Models;
using Tsi1.BusinessLayer.Dtos;
using Tsi1.BusinessLayer.Helpers;
using Tsi1.BusinessLayer.Interfaces;
using Tsi1.DataLayer.Entities;
namespace Tsi1.Api.Controllers
{
......@@ -24,19 +25,22 @@ namespace Tsi1.Api.Controllers
private readonly IUserTypeService _userTypeService;
private readonly ITenantService _tenantService;
private readonly IEmailService _emailService;
private readonly IBedeliaService _bedeliaService;
public UserController(
IJwtAuthManager jwtAuthManager,
IUserService userService,
IUserTypeService userTypeService,
ITenantService tenantService,
IEmailService emailService)
IEmailService emailService,
IBedeliaService bedeliaService)
{
_jwtAuthManager = jwtAuthManager;
_userService = userService;
_userTypeService = userTypeService;
_tenantService = tenantService;
_emailService = emailService;
_bedeliaService = bedeliaService;
}
[AllowAnonymous]
......@@ -59,7 +63,24 @@ namespace Tsi1.Api.Controllers
return BadRequest(tenant.Message);
}
var result = await _userService.Authenticate(userName, request.Password, tenant.Data.Id);
var result = new ServiceResult<User>();
if (tenant.Data.IsLoginBedelia)
{
var bedeliaResult = await _bedeliaService.Login(userName, request.Password);
if (bedeliaResult.HasError)
{
return BadRequest(bedeliaResult.Message);
}
result = await _userService.GetByIdentityCard(userName);
}
else
{
result = await _userService.Authenticate(userName, request.Password, tenant.Data.Id);
}
if (result.HasError)
{
return BadRequest(result.Message);
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class BedeliaLoginDto
{
public string IdentityCard { get; set; }
public string Password { get; set; }
}
}
......@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos
{
public string Name { get; set; }
public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
}
}
......@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; }
public string Name { get; set; }
public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
}
}
......@@ -9,5 +9,6 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; }
public string Name { get; set; }
public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
}
}
......@@ -12,5 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<bool>> IsValidUser(string identityCard);
Task<ServiceResult<bool>> CloseRecord(string courseName, List<UserGradeDto> userGrades);
Task<ServiceResult<bool>> Login(string identityCard, string password);
}
}
......@@ -18,6 +18,8 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<UserDetailDto>> GetById(int userId);
Task<ServiceResult<User>> GetByIdentityCard(string IdentityCard);
Task<ServiceResult<User>> GetByUsername(string username, int tenantId);
Task<ServiceResult<bool>> UpdatePassword(int userId, string password);
......
......@@ -57,5 +57,29 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<bool>> Login(string identityCard, string password)
{
var result = new ServiceResult<bool>();
var loginDto = new BedeliaLoginDto()
{
IdentityCard = identityCard,
Password = password
};
var jsonInString = JsonConvert.SerializeObject(loginDto);
var model = new StringContent(jsonInString, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"api/Users/login", model);
if (response.StatusCode != HttpStatusCode.OK)
{
result.HasError = true;
var errorMessage = await response.Content.ReadAsStringAsync();
result.AddMessage(errorMessage);
}
return result;
}
}
}
......@@ -382,5 +382,27 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<User>> GetByIdentityCard(string IdentityCard)
{
var result = new ServiceResult<User>();
var user = await _context.Users
.AsNoTracking()
.Include(x => x.Student)
.Include(x => x.UserType)
.FirstOrDefaultAsync(x => x.Student.IdentityCard == IdentityCard);
if (user == null)
{
result.HasError = true;
result.Message = string.Format(ErrorMessages.UserDoesNotExist, IdentityCard);
return result;
}
result.Data = user;
return result;
}
}
}
......@@ -19,6 +19,7 @@ namespace Tsi1.DataLayer.Entities
public int Id { get; set; }
public string Name { get; set; }
public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
public ICollection<Course> Courses { get; set; }
public ICollection<Professor> Professors { get; set; }
......
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tsi1.DataLayer.Migrations
{
public partial class addcolumnIsLoginBedeliatotenant : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsLoginBedelia",
table: "Tenants",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsLoginBedelia",
table: "Tenants");
}
}
}
......@@ -700,6 +700,9 @@ namespace Tsi1.DataLayer.Migrations
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<bool>("IsLoginBedelia")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("character varying(50)");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment