Пример #1
0
        public async Task <IActionResult> Login([FromBody] LoginUserCommand command)
        {
            Logger.LogInformation("{Message} {Username}", "Trying to login user", command.Username);
            var result = await Mediator.Send(command);

            if (!result.IsSucceeded)
            {
                Logger.LogWarning("{Message} {ErrorMessage} {Username} ",
                                  "Failed at login user", result.Errors.Values, command.Username);
                return(GetResponse(result));
            }

            var userData = result.Data;
            var response = new ApiLoginResponse
            {
                Id       = userData.Id,
                Username = userData.Username,
                Email    = userData.Email,
                Token    = _tokenGenerator.GenerateTokenForUser(userData)
            };

            Logger.LogInformation("{Message} {UserId} {Username}",
                                  "Successful login for user", userData.Id, userData.Username);
            return(Ok(response));
        }