Exemplo n.º 1
0
        public AuthenticateResponse Authenticate(BasicAuthenticateRequest model)
        {
            var user = _users.FilterBy(x => x.UserName.Equals(model.UserName) &&
                                       x.AccountType == AccountType.Internal).FirstOrDefault();

            if (user == null ||
                !SecurePasswordHasher.Verify(model.Password, user.Password))
            {
                return(null);
            }

            var token = _jwtTokenGenerator.GenerateJwtToken(user);

            return(new AuthenticateResponse(user, token));
        }
Exemplo n.º 2
0
        private IActionResult ProcessBasicRequest(AuthenticateRequest model)
        {
            var basicRequest = new BasicAuthenticateRequest
            {
                UserName = model.UserName,
                Password = model.Password
            };

            ModelValidator.Validate(basicRequest);

            var res = _loginService.Authenticate(basicRequest);

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

            return(Ok(res));
        }