예제 #1
0
        public async Task <IActionResult> GetPersonByCredentials([FromBody] UserModel user)
        {
            var person = await _persons.GetByCredentials(user.Username, PersonExtensions.PasswordHashing(user.Password)).ConfigureAwait(false);

            if (person == null)
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <PersonModel>(person)));
        }
        public void WhenPasswordHashingIsCalledWithSamePasswords_ThenResultIsIdentical()
        {
            // Arrange
            string passwordToTest = "password1234";

            // Act
            string hashedPasswordOne = PersonExtensions.PasswordHashing(passwordToTest);
            string hashedPasswordTwo = PersonExtensions.PasswordHashing(passwordToTest);

            // Assert
            Assert.AreEqual(hashedPasswordOne, hashedPasswordTwo);
        }
        public void WhenPasswordHashingIsCalledWithDifferentPasswords_ThenResultIsDifferent()
        {
            // Arrange
            string passwordToTest    = "password1234";
            string passwordToTestTwo = "password123456";

            // Act
            string hashedPasswordOne = PersonExtensions.PasswordHashing(passwordToTest);
            string hashedPasswordTwo = PersonExtensions.PasswordHashing(passwordToTestTwo);

            // Assert
            Assert.AreNotEqual(hashedPasswordOne, hashedPasswordTwo);
        }
예제 #4
0
        public async Task <IActionResult> AddPerson([FromBody] CreatePersonModel user)
        {
            var userEntity = _mapper.Map <PersonEntity>(user);

            var res = await _persons.GetByUsername(user.Username).ConfigureAwait(false);

            if (res != null)
            {
                return(BadRequest());
            }

            var ress = await _persons.GetByEmail(user.Email).ConfigureAwait(false);

            if (ress != null)
            {
                return(BadRequest());
            }
            userEntity.Password = PersonExtensions.PasswordHashing(userEntity.Password);
            await _persons.AddAsync(userEntity).ConfigureAwait(false);

            var userResult = await _persons.GetByIdAsync(userEntity.Id).ConfigureAwait(false);

            return(CreatedAtRoute("GetPersonById", new { id = userResult.Id }, _mapper.Map <PersonEntity>(userResult)));
        }