Ejemplo n.º 1
0
        public void when_account_registered_then_account_settings_populated()
        {
            var accountId = Guid.NewGuid();

            var accountRegistered = new AccountRegistered
            {
                SourceId = accountId,
                Name     = "Bob",
                Email    = "*****@*****.**",
                Country  = CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("CA")).CountryISOCode,
                Phone    = "555.555.2525",
                Password = new byte[] { 1 }
            };

            Sut.Handle(accountRegistered);

            using (var context = new BookingDbContext(DbName))
            {
                var dto = context.Find <AccountDetail>(accountId);

                Assert.NotNull(dto);
                Assert.AreEqual(dto.Settings.Name, dto.Name);
                Assert.AreEqual(CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("CA")).CountryISOCode.Code, dto.Settings.Country.Code);
                Assert.AreEqual(accountRegistered.Phone, dto.Settings.Phone);


                var config = new TestServerSettings();
                Assert.IsNull(dto.Settings.ChargeTypeId);
                Assert.AreEqual(dto.Settings.Passengers, config.ServerData.DefaultBookingSettings.NbPassenger);
                Assert.IsNull(dto.Settings.VehicleTypeId);
                Assert.IsNull(dto.Settings.ProviderId);
            }
        }
Ejemplo n.º 2
0
        public Account(AccountId userId, string email)
        {
            var evnt = new AccountRegistered(userId, email);

            state = new AccountState();
            Apply(evnt);
        }
Ejemplo n.º 3
0
 public void Handle(AccountRegistered @event)
 {
     Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName);
     _eventBus.SendCommand(new Login {
         UserName = "******", Password = "******"
     });
 }
Ejemplo n.º 4
0
        public async Task <RegistrationResult> Register(string username, string password)
        {
            var result = await Post.To("/_matrix/client/r0/register")
                         .Using(RestClient)
                         .AddBody(new RegistrationRequest
            {
                Username           = username,
                Password           = password,
                AuthenticationData = new AuthenticationData
                {
                    Type = "m.login.dummy"
                },
                InhibitLogin             = true,
                DeviceId                 = null,
                InitialDeviceDisplayName = null
            })
                         .On(400, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res)))
                         .On(401, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res)))
                         .On(403, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res)))
                         .On(429, (req, res, err) => ProtocolError?.Invoke(this, new ErrorEventArgs(err, res)))
                         .WhenSucceeded(new Action <RegistrationResult>(r =>
            {
                AccountRegistered?.Invoke(this, new RegistrationEventArgs(MxId.Parse(r.UserId)));
            }))
                         .Execute <RegistrationResult>();

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Execute a command asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <returns>
        ///     Task which will be completed once the command has been executed.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, RegisterAccount command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (!string.IsNullOrEmpty(command.UserName) && await _repository.IsUserNameTakenAsync(command.UserName))
            {
                _logger.Warn("UserName is taken: " + command.UserName);
                await SendAccountInfo(context, command.UserName);

                return;
            }

            var account = command.AccountId > 0
                ? new Account(command.AccountId, command.UserName, command.Password)
                : new Account(command.UserName, command.Password);

            account.SetVerifiedEmail(command.Email);

            if (command.ActivateDirectly)
            {
                _logger.Debug("Activating directly");
                account.Activate();
            }

            var accountCount = await _repository.CountAsync();

            if (accountCount == 0)
            {
                account.IsSysAdmin = true;
            }

            await _repository.CreateAsync(account);

            // accounts can be activated directly.
            // should not send activation email then.
            if (account.AccountState == AccountState.VerificationRequired)
            {
                await SendVerificationEmail(context, account);
            }

            var evt = new AccountRegistered(account.Id, account.UserName)
            {
                IsSysAdmin = account.IsSysAdmin
            };
            await context.SendAsync(evt);

            if (command.ActivateDirectly)
            {
                var evt1 = new AccountActivated(account.Id, account.UserName)
                {
                    EmailAddress = account.Email
                };
                await context.SendAsync(evt1);
            }
        }
Ejemplo n.º 6
0
 private void Apply(AccountRegistered @event)
 {
     Id                  = @event.Id;
     Created             = @event.OccurredAt;
     CreatedBy           = @event.UserId;
     LastModified        = @event.OccurredAt;
     LastModifiedBy      = @event.UserId;
     LastModifiedVersion = CalculateLastModifiedVersion();
 }
Ejemplo n.º 7
0
        public Account(AccountId userId, string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentException(nameof(email));
            }

            var evnt = new AccountRegistered(userId, email);

            state = new AccountState();
            Apply(evnt);
        }
Ejemplo n.º 8
0
        public void Handle(AccountRegistered @event)
        {
            // Check if exists promotion triggered on account creation
            var accountCreatedPromotion = _promotionDao.GetAllCurrentlyActive(PromotionTriggerTypes.AccountCreated).FirstOrDefault();

            if (accountCreatedPromotion != null)
            {
                _commandBus.Send(new AddUserToPromotionWhiteList
                {
                    AccountIds = new[] { @event.SourceId },
                    PromoId    = accountCreatedPromotion.Id
                });
            }
        }
        public async Task HandleAsync(IMessageContext context, RegisterSimple command)
        {
            var pos = command.EmailAddress.IndexOf('@');

            if (pos == -1)
            {
                _logger.Warn("Invalid email address: " + command.EmailAddress);
                throw new InvalidOperationException("Invalid email address");
            }

            var user = _repository.FindByEmailAsync(command.EmailAddress);

            if (user != null)
            {
                _logger.Warn("Email already taken, sending reset password: "******"Failed to generate user name for " + command.EmailAddress);
                return;
            }


            //var id = _idGeneratorClient.GetNextId(Account.SEQUENCE);
            var password = Guid.NewGuid().ToString("N").Substring(0, 10);
            var account  = new Account(userName, password);

            account.SetVerifiedEmail(command.EmailAddress);
            await _repository.CreateAsync(account);

            await SendAccountEmail(context, account, password);

            var evt = new AccountRegistered(account.Id, account.UserName);
            await context.SendAsync(evt);
        }
Ejemplo n.º 10
0
        public void when_account_registered_with_null_country_code()
        {
            var accountId = Guid.NewGuid();

            var accountRegistered = new AccountRegistered
            {
                SourceId = accountId,
                Name     = "Bob",
                Email    = "*****@*****.**",
                Country  = null,
                Phone    = "555.555.2525",
                Password = new byte[] { 1 }
            };

            Sut.Handle(accountRegistered);

            using (var context = new BookingDbContext(DbName))
            {
                var dto = context.Find <AccountDetail>(accountId);

                Assert.AreEqual(CountryCode.GetCountryCodeByIndex(CountryCode.GetCountryCodeIndexByCountryISOCode("US")).CountryISOCode.Code, dto.Settings.Country.Code);
            }
        }
        /// <summary>
        ///     Execute a command asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <returns>
        ///     Task which will be completed once the command has been executed.
        /// </returns>
        public async Task ExecuteAsync(RegisterAccount command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (await _repository.IsUserNameTakenAsync(command.UserName))
            {
                await SendAccountInfo(command.UserName);

                return;
            }

            var account = new Account(command.UserName, command.Password);

            account.SetVerifiedEmail(command.Email);
            await _repository.CreateAsync(account);

            await SendVerificationEmail(account);

            var evt = new AccountRegistered(account.Id, account.UserName);
            await _eventBus.PublishAsync(evt);
        }
Ejemplo n.º 12
0
#pragma warning disable IDE0051
        private void On(AccountRegistered @event)
        {
            Dict.Add(@event.ID, new AccountEntry(@event.ID, @event.Username, @event.Password, @event.Timestamp));
        }
Ejemplo n.º 13
0
 public void Handle(AccountRegistered @event)
 {
     Console.Write("subscriber2: {0} has registered.", @event.UserName);
     throw new DomainException(ErrorCode.UnknownError, "test fail handled event!");
 }
 public void Handle(AccountRegistered @event)
 {
     Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName);
     // _eventBus.SendCommand(new Login {UserName = @event.UserName, Password = @event.Password});
 }
Ejemplo n.º 15
0
 private void Apply(AccountRegistered @event)
 {
     _accounts.Add(@event.AccountId);
     LastModified   = @event.OccurredAt;
     LastModifiedBy = @event.UserId;
 }
Ejemplo n.º 16
0
 private void Handle(AccountRegistered @event)
 {
     _name = @event.Name;
 }
Ejemplo n.º 17
0
 private void OnAccountRegistered(AccountRegistered @event)
 {
     _confirmationToken = @event.ConfirmationToken;
 }
Ejemplo n.º 18
0
 public void When(AccountRegistered e)
 {
     Id    = e.Id;
     Email = e.Email;
 }
Ejemplo n.º 19
0
 public void Handle(AccountRegistered @event)
 {
     Console.Write("account({0}) registered at {1}", @event.AccountID, @event.UserName);
 }