Пример #1
0
        public async Task <IActionResult> Login(string username, string password)
        {
            var user = await _userManager.FindByNameAsync(username);

            if (user is null)
            {
                return(BadRequest());
            }
            var result = await _signInManager.CheckPasswordSignInAsync(user, password, false);

            if (result.Succeeded)
            {
                return(Ok(new UserResponse
                {
                    UserId = user.Id,
                    Username = user.UserName,
                    JwtToken = _jwtTokenHandler.GenerateToken(user.Id)
                }));
            }
            return(BadRequest("Wrong Password"));
        }