Пример #1
0
        public async Task <ActionResult <AppUserDto> > Authenticate([FromBody] AppLoginDto appLoginDto)
        {
            var user = await _userService.Authenticate(appLoginDto.Username, appLoginDto.Password);

            if (user == null)
            {
                return(BadRequest(new ApiErrorDto {
                    Message = "Username or password is incorrect"
                }));
            }

            if (!user.IsRegistrationAccepted())
            {
                return(BadRequest(new ApiErrorDto {
                    Message = "User is not yet accepted. Please contact the admin."
                }));
            }

            var respUserDto = _mapper.Map <AppUserDto>(user);

            respUserDto.Token = _tokenManager.GenerateToken(user);

            return(respUserDto);
        }