コード例 #1
0
        public async Task <IdModel> Handle(PostRequest request, CancellationToken cancellationToken)
        {
            var client = await fClientRepository.GetAsync(request.Model.ClientId, cancellationToken);

            if (client is null)
            {
                throw new BadRequestException($"Client with ID '{request.Model.ClientId}' doesn't exist.");
            }

            if (request.Model.Username != null && await fUserRepository.ExistsByUsernameAsync(request.Model.Username, cancellationToken))
            {
                throw new ConflictException($"User with username '{request.Model.Username}' already exists.");
            }
            if (await fUserRepository.ExistsByEmailAsync(request.Model.Email, cancellationToken))
            {
                throw new ConflictException($"User with email '{request.Model.Email}' already exists.");
            }

            var user = await RegisterAsync(request.Model, client, cancellationToken);

            var context = fLoggingContextService.GetRequestContext();
            await fEmailService.SendEmailAsync(VerifyAccountEmailContext.New(user, client, context), cancellationToken);

            return(new IdModel {
                Id = user.Id
            });
        }
コード例 #2
0
        public async Task <Unit> Handle(PatchVerificationRequest request, CancellationToken cancellationToken)
        {
            var client = await fClientRepository.GetAsync(request.Model.ClientId, cancellationToken);

            if (client is null)
            {
                throw new BadRequestException($"Client with ID '{request.Model.ClientId}' doesn't exist.");
            }

            var user = await GetUserByEmailOrThrowAsync(request.Email, cancellationToken);

            if (user.EmailToken is null)
            {
                throw new ConflictException($"Account with email '{request.Email}' is already verified.");
            }

            var context = fLoggingContextService.GetRequestContext();
            await fEmailService.SendEmailAsync(VerifyAccountEmailContext.New(user, client, context), cancellationToken);

            return(Unit.Value);
        }