Ejemplo n.º 1
0
 public UserController(
     IUserService userService,
     AuthTokenGenerator tokenGenerator)
 {
     _userService    = userService;
     _tokenGenerator = tokenGenerator;
 }
Ejemplo n.º 2
0
        public IHttpActionResult Authenticate([FromBody] LoginRequest login)
        {
            _loggerService.LogInformation("start - Authenticate");
            if (string.IsNullOrEmpty(login.UserName) || string.IsNullOrEmpty(login.Password))
            {
                return(BadRequest("Bad credentials"));
            }

            if (!_userRepository.HasValidCredentials(login.UserName, login.Password))
            {
                var loginResponse = new LoginResponse {
                    ResponseMsg = { StatusCode = HttpStatusCode.Unauthorized }
                };
                IHttpActionResult response = ResponseMessage(loginResponse.ResponseMsg);
                return(response);
            }

            _loggerService.LogInformation($"Get token for user: {login.UserName}");

            string jwToken = AuthTokenGenerator.CreateToken(login.UserName,
                                                            _userRepository.GetRoleByUserName(login.UserName), _secretAuthKey);

            _loggerService.LogInformation("end - Authenticate");

            return(Ok(new { token = jwToken }));
        }
Ejemplo n.º 3
0
        private TrackList GetTracks(List <Answer> answers, string genre)
        {
            var recommendation = _recommendationBuilder.CalculateFromQuestions(answers, genre);

            var query  = _queryBuilder.GetRecommendations(recommendation);
            var result = _apiClient.GetData(query,
                                            AuthTokenGenerator
                                            .DoAuth(_clientId, _clientSecret)
                                            .AccessToken).Result;

            var tracks = JsonHelp.Deserialize <TrackList>(result);

            return(tracks);
        }