Skip to content
Snippets Groups Projects
Commit 2346132a authored by Lucca Santangelo's avatar Lucca Santangelo
Browse files

merge from develop

parents dd2ac4fb dd52bd77
No related branches found
No related tags found
1 merge request!46commit
Showing
with 1270 additions and 1 deletion
...@@ -135,5 +135,23 @@ namespace Bedelia.Controllers ...@@ -135,5 +135,23 @@ namespace Bedelia.Controllers
return Ok(result); 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; ...@@ -11,6 +11,7 @@ using Tsi1.Api.Models;
using Tsi1.BusinessLayer.Dtos; using Tsi1.BusinessLayer.Dtos;
using Tsi1.BusinessLayer.Helpers; using Tsi1.BusinessLayer.Helpers;
using Tsi1.BusinessLayer.Interfaces; using Tsi1.BusinessLayer.Interfaces;
using Tsi1.DataLayer.Entities;
namespace Tsi1.Api.Controllers namespace Tsi1.Api.Controllers
{ {
...@@ -62,7 +63,24 @@ namespace Tsi1.Api.Controllers ...@@ -62,7 +63,24 @@ namespace Tsi1.Api.Controllers
return BadRequest(tenant.Message); 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) if (result.HasError)
{ {
return BadRequest(result.Message); 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 ...@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos
{ {
public string Name { get; set; } public string Name { get; set; }
public string Theme { get; set; } public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
} }
} }
...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Theme { get; set; } public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
} }
} }
...@@ -9,5 +9,6 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -9,5 +9,6 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Theme { get; set; } public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
} }
} }
...@@ -11,6 +11,8 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -11,6 +11,8 @@ namespace Tsi1.BusinessLayer.Interfaces
{ {
Task<ServiceResult<bool>> IsValidUser(string identityCard); Task<ServiceResult<bool>> IsValidUser(string identityCard);
Task<ServiceResult<bool>> CloseRecord(string courseName, List<UserGradeDto> userGrades); Task<ServiceResult<bool>> CloseRecord(string courseName, List<UserGradeDto> userGrades);
Task<ServiceResult<bool>> Login(string identityCard, string password);
Task<ServiceResult<bool>> IsValidCourse(string courseName); Task<ServiceResult<bool>> IsValidCourse(string courseName);
Task<ServiceResult<bool>> CreateUsers(List<UserCreateBedeliaDto> users); Task<ServiceResult<bool>> CreateUsers(List<UserCreateBedeliaDto> users);
Task<ServiceResult<bool>> CreateCourses(List<CourseCreateBedeliaDto> users); Task<ServiceResult<bool>> CreateCourses(List<CourseCreateBedeliaDto> users);
......
...@@ -18,6 +18,8 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -18,6 +18,8 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<UserDetailDto>> GetById(int userId); Task<ServiceResult<UserDetailDto>> GetById(int userId);
Task<ServiceResult<User>> GetByIdentityCard(string IdentityCard);
Task<ServiceResult<User>> GetByUsername(string username, int tenantId); Task<ServiceResult<User>> GetByUsername(string username, int tenantId);
Task<ServiceResult<bool>> UpdatePassword(int userId, string password); Task<ServiceResult<bool>> UpdatePassword(int userId, string password);
......
...@@ -58,6 +58,30 @@ namespace Tsi1.BusinessLayer.Services ...@@ -58,6 +58,30 @@ namespace Tsi1.BusinessLayer.Services
return result; 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;
}
public async Task<ServiceResult<bool>> IsValidCourse(string courseName) public async Task<ServiceResult<bool>> IsValidCourse(string courseName)
{ {
var result = new ServiceResult<bool>(); var result = new ServiceResult<bool>();
......
...@@ -369,5 +369,27 @@ namespace Tsi1.BusinessLayer.Services ...@@ -369,5 +369,27 @@ namespace Tsi1.BusinessLayer.Services
return result; 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 ...@@ -19,6 +19,7 @@ namespace Tsi1.DataLayer.Entities
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Theme { get; set; } public string Theme { get; set; }
public bool IsLoginBedelia { get; set; }
public ICollection<Course> Courses { get; set; } public ICollection<Course> Courses { get; set; }
public ICollection<Professor> Professors { 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 ...@@ -700,6 +700,9 @@ namespace Tsi1.DataLayer.Migrations
.HasColumnType("integer") .HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<bool>("IsLoginBedelia")
.HasColumnType("boolean");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("character varying(50)"); .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