Esempio n. 1
0
        public IActionResult Register([FromBody] UserToAuthenticateDto userModel)
        {
            var isUsernameUnique = _userRepository.IsUniqueUser(userModel.Username);

            if (!isUsernameUnique)
            {
                return(BadRequest(new { message = "Username already exists!" }));
            }
            var userToRegister = _userRepository.Register(userModel.Username, userModel.Password);

            return(Ok());
        }
Esempio n. 2
0
        public IActionResult Authenticate([FromBody] UserToAuthenticateDto userModel)
        {
            var userFromDb = _userRepository.Authenticate(userModel.Username, userModel.Password);

            if (userFromDb == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }
            var userToReturn = _mapper.Map <UserToReturnDto>(userFromDb);

            return(Ok(userToReturn));
        }