public Response <UsersDto> Authenticate(string username, string password)
        {
            var response = new Response <UsersDto>();

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                response.Message = "Parámetros no pueden ser vacios.";
                return(response);
            }
            try
            {
                var user = _usersDomain.Authenticate(username, password);
                response.Data      = _mapper.Map <UsersDto>(user);
                response.IsSuccess = true;
                response.Message   = "Autenticación Exitosa!!!";
            }
            catch (InvalidOperationException)
            {
                response.IsSuccess = true;
                response.Message   = "Usuario no existe";
            }
            catch (Exception e)
            {
                response.Message = e.Message;
            }
            return(response);
        }
Esempio n. 2
0
        public IActionResult Index(AuthDto dto, string returnUrl = null)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    TempData.Add(TempDataModelStateKey, ModelState);
                    return(RedirectToAction("Index"));
                }

                _usersDomain.Authenticate(dto);

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    returnUrl = HttpUtility.UrlDecode(returnUrl);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                }

                return(RedirectToAction("Index", "BlogAdmin"));
            }
            catch (ShakerDomainException ex)
            {
                TempData.Add(TempDataErrorMessageKey, ex.Message);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.Message);
                TempData.Add(TempDataErrorMessageKey, MessagesGetter.Get(ErrorPresentationMessages.DefaultErrorMessage));
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 3
0
        public IActionResult Authenticate([FromBody] AuthDto dto)
        {
            try
            {
                UserDto userDto = _usersDomain.Authenticate(dto);

                userDto = _jwtAuth.GenerateToken(userDto);

                return(Ok(userDto));
            }
            catch (ShakerDomainException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.Message);

                return(BadRequest(new { message = MessagesGetter.Get(ErrorPresentationMessages.DefaultErrorMessage) }));
            }
        }