public ActionResult <AuthOutputDto> Login(AuthInputDto login) { try { AuthOutputDto tokenAcesso = _authAppService.Login(login); return(Ok(tokenAcesso)); } catch (ErrorAction error) { var err = BadRequest(new { error.Text, error.Status }); return(err); } }
public ActionResult <AuthOutputDto> Register(UsersInputDto user) { try { AuthOutputDto tokenAcesso = _authAppService.Register(user); return(Ok(tokenAcesso)); } catch (ErrorAction error) { var err = BadRequest(new { error.Text, error.Status }); return(err); } }
public AuthOutputDto Login(AuthInputDto login) { string passwordHashed = _cryptyService.GenerateHashKey(login.Password); User userLoged = _authRepository.FindByUserOrEmail(login.Email); if (userLoged == null || !passwordHashed.Equals(userLoged.Password)) { ErrorAction error = new ErrorAction(1, Messages.Messages.UsuarioNaoEncontrado.Replace("{0}", login.Email)); throw error; } string token = _dataAgent.GenerateToken(userLoged); EnterpriseOutputDto userOutput = _mapper.Map <EnterpriseOutputDto>(userLoged); AuthOutputDto authOutput = new AuthOutputDto { Token = token, User = userOutput }; return(_mapper.Map <AuthOutputDto>(authOutput)); }