public IActionResult Login(UserDTO user)
        {
            var result = service.Authenticate(user);

            if (!result.Succedeed)
            {
                System.Console.WriteLine($"Authentication failed: {result.Message}");
                return(BadRequest(result.Message));
            }

            System.Console.WriteLine("Authentication success");
            return(new OkObjectResult(result.Object));
        }
Example #2
0
        public async Task <IActionResult> Authenticate(ApplicationUserAuthRequest model)
        {
            Response oR = new Response();

            try
            {
                var oUser = await _service.Authenticate(model);

                if (oUser == null)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.InvalidUserNamePassword;

                    return(BadRequest(oR));
                }

                if (oUser.ApplicationUserStatusId == 2)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.AccountDisabled;

                    return(BadRequest(oR));
                }

                SetToken(oUser);

                oR.Status = StatusCodes.Status200OK;
                oR.Data   = oUser;

                return(Ok(oR));
            }
            catch (Exception ex)
            {
                oR.Status  = StatusCodes.Status500InternalServerError;
                oR.Message = Messages.InternalServerError;

                return(StatusCode(StatusCodes.Status500InternalServerError, oR));
            }
        }
Example #3
0
        public IActionResult CreateToken([FromBody] LoginModel login)
        {
            IActionResult response = Unauthorized();
            var           user     = _userService.Authenticate(login);

            if (user != null)
            {
                var tokenString = _tokenManagement.BuildToken(user);
                response = Ok(new
                {
                    Username = login.UserName,
                    Token    = tokenString
                });
            }
            else
            {
                response = Ok(new { Token = "" });
            }


            return(response);
        }
Example #4
0
        public async Task <IActionResult> Authenticate(EncryptedBasicLoginModel model)
        {
            var result = await _applicationUserService.Authenticate(model);

            return(Ok(GenerateSuccessfulResponse(result)));
        }