Exemple #1
0
        public IActionResult Authenticate([FromBody] UserCredentialsDto credentials,
                                          [FromHeader(Name = nameof(HeaderNames.Accept))] string mediaType)
        {
            var user = _weblogDataRepository.Authenticate(
                credentials.EmailAddress, credentials.Password);

            if (user is null)
            {
                return(Unauthorized());
            }

            var userToReturn = _mapper.Map <UserDto>(user);

            var includeLinks = MediaTypes.IncludeLinks(mediaType);

            if (!includeLinks)
            {
                return(Ok(userToReturn));
            }

            var links         = CreateLinksForUser(user.UserId);
            var userWithLinks = new UserDtoWithLinks(userToReturn, links);

            return(Ok(userWithLinks));
        }
Exemple #2
0
        public void Authenticate()
        {
            //-- arrange
            var user = new User
            {
                FirstName    = "fname",
                LastName     = "lname",
                EmailAddress = "email@users",
                Password     = "******"
            };

            _repository.AddUser(user);
            _repository.Save();

            //-- act
            var actual = _repository.Authenticate("email@users", "secret");

            //-- assert
            Assert.AreEqual(user, actual);

            //-- clean up
            _repository.DeleteUser(user);
            _repository.Save();
        }