Пример #1
0
        public async Task <ActionResult <TokenDto> > Login([FromBody] UserLoginDto userDto)
        {
            var user = await _userManager.FindByEmailAsync(userDto.Email);

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status403Forbidden,
                                  new []
                {
                    new ErrorDescription {
                        Code = "BadCredentials", Description = "Wrong login or password"
                    }
                }));
            }

            var result = await _signInManager.CheckPasswordSignInAsync(
                user, userDto.Password, false);

            if (!result.Succeeded)
            {
                return(StatusCode(StatusCodes.Status403Forbidden,
                                  new []
                {
                    new ErrorDescription {
                        Code = "BadCredentials", Description = "Wrong login or password"
                    }
                }));
            }

            return(Ok(new TokenDto
            {
                Token = _tokenProvider.GenerateJwtToken(user)
            }));
        }