예제 #1
0
        public async Task <Result <UserView> > Authenticate([FromBody] AuthenticateModel model)
        {
            var result = new Result <UserView>();

            try
            {
                var query = new AuthenticateQuery(model.Username, model.Password);
                var user  = this._mediator.Execute(query);
                if (user != null)
                {
                    result.Data = _mapper.Map <UserView>(user);
                }
                else
                {
                    result.Error     = "Username or password is incorrect";
                    result.IsSuccess = false;
                }

                return(result);
            }
            catch (Exception e)
            {
                result.Error     = e.Message;
                result.IsSuccess = false;
            }
            finally
            {
                _logger.LogInformation("User's token generated.");
            }

            return(result);
        }
예제 #2
0
        public async Task <ActionResult <AuthenticatedUserResource> > Authenticate(CancellationToken cancellationToken = default)
        {
            AuthenticateQuery query = new AuthenticateQuery();

            AuthenticatedUserResource user = await _mediator.Send(query, cancellationToken);

            return(Ok(user));
        }
예제 #3
0
        public async Task <IActionResult> Authenticate(AuthenticateQuery query)
        {
            var response = await _queryProcessor.Execute(query, _httpContext);

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

            return(Ok(response));
        }
예제 #4
0
        private void Authenticate()
        {
            if (null == _config.User || null == _config.Password)
            {
                throw new InvalidCredentialException();
            }

            var obsAuth = new AuthenticateQuery(this, ConsistencyLevel.ONE, ExecutionFlags.None, _config.User, _config.Password).AsFuture();

            if (!obsAuth.Result.Single())
            {
                throw new InvalidCredentialException();
            }
        }
예제 #5
0
 public User Authenticate(string Email, string Password)
 {
     try
     {
         IMediator service = _container.GetInstance <IMediator>();
         var       query   = new AuthenticateQuery
         {
             Email    = Email,
             Password = Password
         };
         return(service.Proccess(query));
     }
     catch (ExceptionLog ex)
     {
         throw ex;
     }
 }
 public User Authenticate(string Email, string Password)
 {
     try
     {
         IMediator service = _container.GetInstance<IMediator>();
         var query = new AuthenticateQuery
         {
             Email = Email,
             Password = Password
         };
         return service.Proccess(query);
     }
     catch (ExceptionLog ex)
     {
         throw ex;
     }
 }
예제 #7
0
        public async Task <UserAuthenticateResult> Authenticate(AuthenticateQuery authenticateQuery)
        {
            User user = await _cacheProvider.GetFromCache <User>($"User_{authenticateQuery.Email}");

            if (user == null)
            {
                user = await _userService.GetUser(authenticateQuery.Email);
            }

            var authenticateResult = new UserAuthenticateResult
            {
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                UserId    = user.Id,
                UserType  = user.UserType
            };

            return(authenticateResult);
        }
예제 #8
0
        public async Task <IActionResult> Authenticate([FromBody] AuthenticateQuery authenticateQuery)
        {
            var result = await _mediator.Send(authenticateQuery);

            return(Json(result));
        }