Example #1
0
        public async Task <TokenModel> SignUpAsync(string username, string password)
        {
            await Task.Delay(2000);

            ValidateUserData(username, password);
            var userModel = new UserModel {
                UserName = username
            };

            return(_userTokenService.CreateToken(userModel));
        }
Example #2
0
        public IActionResult Authenticate([FromBody] UserCredentialsDTO userCredentials)
        {
            var user = _userService.Authenticate(userCredentials.Username,
                                                 userCredentials.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            var userDTO = _mapper.Map <UserDTO>(user);

            userDTO.Token = _userTokenService.CreateToken(user);
            return(Ok(userDTO));
        }