コード例 #1
0
        public async Task <Option <UserWithTokenResponse> > Authenticate(AuthenticateRequest request)
        {
            using var client = new HttpClient();
            var accountClient = new AccountClient(externals.Account, client);

            var authenticateRequest = new Data.Account.AuthenticateRequest()
            {
                Username = request.Username,
                Password = request.Password,
            };

            Option <AccountWithTokenDto> response;

            try
            {
                response = (await accountClient.AccountqueryAuthenticateAsync(authenticateRequest)).DeserializeOption();
            }
            catch
            {
                return(Option <UserWithTokenResponse> .FromError("Could not connect to the account service."));
            }

            return(response.Select(x => new UserWithTokenResponse
            {
                Id = x.Id,
                Bio = x.Bio,
                Username = x.Username,
                Token = x.Token,
                Role = x.Role,
            }));
        }
コード例 #2
0
        public async Task <Option <PagedData <UserResponse> > > GetAll([FromQuery] int pageSize, [FromQuery] int pageNumber, [FromQuery] string?usernameFilter)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                JwtBearerDefaults.AuthenticationScheme,
                this.HttpContext.Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", ""));
            var accountClient = new AccountClient(externals.Account, client);

            PagedData <AccountDto> response;

            try
            {
                response = (await accountClient.AccountqueryAllAsync(usernameFilter, pageSize, pageNumber)).DeserializePagedData();
            }
            catch (Exception e)
            {
                return(Option <PagedData <UserResponse> > .FromError(e.Message));
            }

            return(response.Select(x => new UserResponse
            {
                Id = x.Id,
                Bio = x.Bio,
                Username = x.Username,
                Role = x.Role,
            }));
        }
コード例 #3
0
        public async Task <Option <UserWithTokenResponse> > Register(RegisterRequest request)
        {
            using var client = new HttpClient();
            var accountClient = new AccountClient(externals.Account, client);

            var createAccount = new CreateAccountRequest
            {
                Username     = request.Username,
                EmailAddress = request.Email,
                Password     = request.Password,
            };

            Option <AccountWithTokenDto> response;

            try
            {
                response = (await accountClient.AccountcommandCreateAsync(createAccount)).DeserializeOption();
            }
            catch (Exception e)
            {
                return(Option <UserWithTokenResponse> .FromError(e.Message));
            }

            return(response.Select(x => new UserWithTokenResponse
            {
                Id = x.Id,
                Bio = x.Bio,
                Username = x.Username,
                Role = x.Role,
                Token = x.Token,
            }));
        }
コード例 #4
0
        public async Task <Option <UserResponse> > GetById(Guid id)
        {
            using var client = new HttpClient();
            var accountClient = new AccountClient(externals.Account, client);

            Option <AccountDto> response;

            try
            {
                response = (await accountClient.AccountqueryAsync(id)).DeserializeOption();
            }
            catch (Exception e)
            {
                return(Option <UserResponse> .FromError(e.Message));
            }

            return(response.Select(x => new UserResponse
            {
                Id = x.Id,
                Bio = x.Bio,
                Username = x.Username,
                Role = x.Role,
            }));
        }