Skip to content

Commit

Permalink
Merge 188756d into 8dbfcec
Browse files Browse the repository at this point in the history
  • Loading branch information
raffacabofrio authored Nov 16, 2021
2 parents 8dbfcec + 188756d commit 74b395e
Show file tree
Hide file tree
Showing 23 changed files with 1,172 additions and 538 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AutoMapper;
using ShareBook.Api.ViewModels;
using ShareBook.Domain;

using ShareBook.Domain.DTOs;

namespace ShareBook.Api.AutoMapper
{
public class ViewModelToDomainMappingProfile : Profile
Expand All @@ -24,7 +25,7 @@ protected ViewModelToDomainMappingProfile(string profileName) : base(profileName
#region [ User ]

CreateMap<LoginUserVM, User>();
CreateMap<RegisterUserVM, User>()
CreateMap<RegisterUserDTO, User>()
.ForPath(dest => dest.Address.Street, opt => opt.MapFrom(src => src.Street))
.ForPath(dest => dest.Address.Number, opt => opt.MapFrom(src => src.Number))
.ForPath(dest => dest.Address.PostalCode, opt => opt.MapFrom(src => src.PostalCode))
Expand Down
31 changes: 24 additions & 7 deletions ShareBook/ShareBook.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ShareBook.Api.ViewModels;
using ShareBook.Domain;
using ShareBook.Domain.Common;
using ShareBook.Domain.DTOs;
using ShareBook.Domain.Exceptions;
using ShareBook.Infra.CrossCutting.Identity;
using ShareBook.Infra.CrossCutting.Identity.Interfaces;
Expand Down Expand Up @@ -102,14 +103,18 @@ public async Task<IActionResult> WhoAccessedMyProfile(Guid userId)
[HttpPost("Register")]
[ProducesResponseType(typeof(object), 200)]
[ProducesResponseType(409)]
public IActionResult Post([FromBody] RegisterUserVM registerUserVM, [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations)
public IActionResult Post([FromBody] RegisterUserDTO registerUserDto, [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations)
{
var user = _mapper.Map<User>(registerUserVM);

var result = _userService.Insert(user);

if (result.Success)
return Ok(_signManager.GenerateTokenAndSetIdentity(result.Value, signingConfigurations, tokenConfigurations));
var result = _userService.Insert(registerUserDto);

if (result.Success)
{
if (registerUserDto.Age > 12)
return Ok(_signManager.GenerateTokenAndSetIdentity(result.Value, signingConfigurations, tokenConfigurations));
else
return Ok(new Result(SuccessMessage: "Seu cadastro foi realizado com sucesso. Foi enviado um email para os pais solicitando o consentimento. Vamos te avisar por email quando seu acesso for liberado. Obrigado. =)"));
}


return Conflict(result);
}
Expand Down Expand Up @@ -215,6 +220,18 @@ public IActionResult ChangeUserPasswordByHashCode([FromBody] ChangeUserPasswordB
return Ok(resultChangePasswordUser);
}

[HttpPut("ParentAproval")]
public IActionResult ParentAproval([FromBody] ParentAprovalVM parentAprovalVM)
{
var ParentHashCodeAproval = parentAprovalVM.ParentHashCodeAproval;

if (string.IsNullOrEmpty(ParentHashCodeAproval) || !Guid.TryParse(ParentHashCodeAproval, out _))
throw new ShareBookException("Código inválido.");

_userService.ParentAproval(ParentHashCodeAproval);
return Ok();
}

#endregion PUT

private bool IsValidClientVersion(string client, string clientVersion)
Expand Down
2 changes: 1 addition & 1 deletion ShareBook/ShareBook.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ShareBook.Api
public class Program
{
public static void Main(string[] args)
{
{
BuildWebHost(args).Run();
}

Expand Down
7 changes: 7 additions & 0 deletions ShareBook/ShareBook.Api/ViewModels/ParentAprovalVM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ShareBook.Api.ViewModels
{
public class ParentAprovalVM
{
public string ParentHashCodeAproval { get; set; }
}
}
61 changes: 0 additions & 61 deletions ShareBook/ShareBook.Api/ViewModels/RegisterUserVM.cs

This file was deleted.

38 changes: 38 additions & 0 deletions ShareBook/ShareBook.Domain/DTOs/RegisterUserDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

namespace ShareBook.Domain.DTOs
{
public class RegisterUserDTO
{
public string Name { get; set; }

public string Email { get; set; }

public string Street { get; set; }

public string Number { get; set; }

public string Complement { get; set; }

public string Neighborhood { get; set; }

public string PostalCode { get; set; }

public string City { get; set; }

public string State { get; set; }

public string Country { get; set; }

public string Linkedin { get; set; }

public string Phone { get; set; }

public string Password { get; set; }

public bool AllowSendingEmail { get; set; } = true;

public int Age { get; set; }

public string ParentEmail { get; set; }
}
}
5 changes: 5 additions & 0 deletions ShareBook/ShareBook.Domain/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class User : BaseEntity
public virtual ICollection<Book> BooksDonated { get; set; }
public virtual ICollection<AccessHistory> Visitors { get; set; }

public string ParentEmail { get; set; }
public string ParentHashCodeAproval { get; set; }
public bool ParentAproved { get; set; } = true;


public bool PasswordIsStrong()
{
Regex rgx = new Regex(@"(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9])[A-Za-z0-9\d$@$!%_*_?&#.,-_:;]{8,}");
Expand Down
Loading

0 comments on commit 74b395e

Please sign in to comment.