Exemplo n.º 1
0
            public async Task <GoodFoodUserDto> Handle(LoginUserCommand request,
                                                       CancellationToken cancellationToken)
            {
                if (string.IsNullOrEmpty(request.Username) || string.IsNullOrEmpty(request.Password))
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { UserPassword = "******" });
                }

                var userFromDB = await _userAuth.VerifyUser(request.Username, request.Password);

                if (userFromDB == null)
                {
                    throw new RestException(HttpStatusCode.Unauthorized, new { User = "******" });
                }

                var user = new GoodFoodUserDto
                {
                    UserName = userFromDB.Username,
                    Token    = _jwtGenerator.CreateToken(userFromDB)
                };

                return(user);
            }