Пример #1
0
        /// <inheritdoc />
        public async Task <Error> RegisterUserAsync(
            string botName,
            string username,
            string userId,
            CancellationToken cancellationToken = default
            )
        {
            Error error;

            var bot = await _botsRepo.GetByNameAsync(botName, cancellationToken)
                      .ConfigureAwait(false);

            if (bot == null)
            {
                _logger?.LogInformation("Chat bot {0} doesn't exists.", botName);
                error = new Error(ErrorCode.BotNotFound);
            }
            else
            {
                bool usernameExists = await _zvClient.UserExistsAsync(username, cancellationToken)
                                      .ConfigureAwait(false);

                if (usernameExists)
                {
                    try
                    {
                        await _regsRepo.AddAsync(new Registration
                        {
                            ChatBotDbRef = new MongoDBRef(MongoConstants.Collections.Bots.Name, bot.Id),
                            Username     = username,
                            ChatUserId   = userId
                        }, cancellationToken
                                                 ).ConfigureAwait(false);

                        error = null;
                    }
                    catch (DuplicateKeyException e)
                    {
                        _logger?.LogInformation(e, "Bot {0} has already registered user {1}.", botName, username);
                        error = new Error(ErrorCode.RegistrationExists, "Bot has already registered this user.");
                    }
                }
                else
                {
                    error = new Error(ErrorCode.UserNotFound);
                }
            }

            return(error);
        }
        public async Task <Unit> Handle(RegisterNewUserCommand request, CancellationToken cancellationToken)
        {
            var password = PasswordManager.HashPassword(request.Password);

            var userRegistration = UserRegistration.RegisterNewUser(
                request.Login,
                password,
                request.Email,
                request.FirstName,
                request.LastName);

            await _userRegistrationRepository.AddAsync(userRegistration);

            return(Unit.Value);
        }
        public async Task <Guid> Handle(RegisterNewUserCommand command, CancellationToken cancellationToken)
        {
            var password = PasswordManager.HashPassword(command.Password);

            var userRegistration = UserRegistration.RegisterNewUser(
                command.Login,
                password,
                command.Email,
                command.FirstName,
                command.LastName,
                _usersCounter,
                command.ConfirmLink);

            await _userRegistrationRepository.AddAsync(userRegistration);

            return(userRegistration.Id.Value);
        }
Пример #4
0
        public async Task <Guid> Handle(RegisterNewUserCommand request, CancellationToken cancellationToken)
        {
            var password = PasswordManager.HashPassword(request.Password);

            var registration = UserRegistration.RegisterNewUser(
                request.Login,
                password,
                request.Email,
                request.FirstName,
                request.LastName,
                _usersCounter);

            await _userRegistrationRepository.AddAsync(registration);

            var email = new EmailMessage(request.Email,
                                         "Football Banter - Please confirm your registration",
                                         "This should be link to confirmation page. For now, please execute HTTP request " +
                                         $"PATCH http://localhost:5000/userRegistration/{registration.Id.Value}/confirm");

            await _emailSender.SendEmail(email);

            return(registration.Id.Value);
        }