public async Task <IActionResult> RegisterAsync([FromBody] DTO.RegistrationInput registration)
        {
            var token = await AuthManager.RegisterUserAsync(registration);

            return(Ok(new DTO.SuccessResponse <DTO.TokenOutput>()
            {
                Success = true,
                Content = token
            }));
        }
        public async Task <DTO.TokenOutput> RegisterUserAsync(DTO.RegistrationInput registration)
        {
            var errors        = new List <string>();
            var existingEmail = await UserManager.FindByEmailAsync(registration.Email);

            if (existingEmail != null)
            {
                errors.Add("This email already exists.");
            }

            var existingUserName = await UserManager.FindByNameAsync(registration.UserName);

            if (existingUserName != null)
            {
                errors.Add("This username already exists.");
            }

            if (errors.Count != 0)
            {
                throw new BadRequestException(errors);
            }

            var result = await UserManager.CreateAsync(new IdentityUser
            {
                UserName = registration.UserName,
                Email    = registration.Email
            }, registration.Password);

            if (!result.Succeeded)
            {
                throw new BadRequestException(result.Errors.Select(error => error.Description).ToList());
            }

            var insertedUser = await UserManager.FindByNameAsync(registration.UserName);

            var tokenResult = await GenerateAuthenticationTokenAsync(insertedUser);

            var httpExtension = new HTTPExtension
            {
                ContentType = "application/json",
                Verb        = HTTPVerb.Post
            };

            httpExtension.Headers.Add("Authorization", $"Bearer {tokenResult.Token}");

            _ = DaprClient.InvokeMethodAsync <DTO.AddressInput, DTO.SuccessResponse <DTO.AddressOutput> >(
                "farmerzon-address", "address", registration.Address, httpExtension);

            return(tokenResult);
        }