Esempio n. 1
0
        public ActionResult Login([FromBody] UserLoginDto model)
        {
            var user = _meetupContext.Users
                       .Include(u => u.Role)
                       .FirstOrDefault(u => u.Email == model.Email);

            if (user is null)
            {
                return(BadRequest("Invalid username or password"));
            }
            var passwordVerificationResult = _passwordHasher
                                             .VerifyHashedPassword(user, user.PasswordHash, model.Password);

            if (passwordVerificationResult == PasswordVerificationResult.Failed)
            {
                return(BadRequest("Invalid username or password"));
            }
            var token = _jwtProvider.GenerateJwtToken(user);

            return(Ok(token));
        }