Ejemplo n.º 1
0
        public async Task <AuthorizationDto> Authorization([FromBody] LoginModel input)
        {
            var user = await _userService.GetUser(input.UserName);

            if (user == null)
            {
                throw new Exception("Invalid username or password");
            }

            var jwt = _token.GetToken(user);

            return(new AuthorizationDto
            {
                Id = user.Id,
                Username = user.UserName,
                Token = jwt,
                Role = user.Role.Name
            });
        }
        public async Task <AuthorizationResponse> AuthorizationAsync([FromBody] UserLoginModel input)
        {
            var authorizationResponse = await _userService.GetUserAsync(input.Login, input.Password);

            if (authorizationResponse == null)
            {
                throw new ArgumentException("Invalid username or password");
            }

            var jwt = _tokenFormation.GetToken(authorizationResponse);

            return(new AuthorizationResponse
            {
                Id = authorizationResponse.Id,
                UserName = authorizationResponse.UserName,
                Role = authorizationResponse.Role,
                Token = jwt
            });
        }