Exemplo n.º 1
0
        public IActionResult Login([FromBody] User user, [FromQuery(Name = "d")] string destination = "frontend")
        {
            var u = _userRepository.GetUser(user.Email);

            if (u == null)
            {
                return(NotFound("User not found."));
            }

            if (destination == "backend" && !u.IsAdmin)
            {
                return(BadRequest("Could not authenticate user."));
            }

            var isValid = u.ValidatePassword(user.Password, _encryptor);

            if (!isValid)
            {
                return(BadRequest("Could not authenticate user."));
            }

            var token = _jwtBuilder.GetToken(u.Id);

            return(new OkObjectResult(token));
        }
Exemplo n.º 2
0
        public ActionResult <string> Login([FromBody] LoginModel user)
        {
            var u = _loginsvc.GetUser(user.Email);

            if (u == null)
            {
                return(NotFound("User not found."));
            }



            var isValid = u.ValidatePassword(user.Password, _encryptor);

            if (!isValid)
            {
                return(BadRequest("Could not authenticate user."));
            }

            var token = _jwtBuilder.GetToken(u.Id);

            var Response = new
            {
                Token = token,
            };

            return(Ok(Response));
        }
        public IActionResult Login([FromBody] User user)
        {
            var u = _userRepository.GetUser(user.Email);

            if (u == null)
            {
                return(NotFound("User not found."));
            }
            var isValid = u.ValidatePassword(user.Password, _encryptor);

            if (!isValid)
            {
                return(BadRequest("Could not authenticate user."));
            }

            var token = _jwtBuilder.GetToken(u.Id);

            return(new OkObjectResult(token));
        }