Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="User"/> class
        /// and publishes a <see cref="UserRegistered"/> event.
        /// </summary>
        /// <param name="tenantId">
        /// Initial value of the <see cref="TenantId"/> property.
        /// </param>
        /// <param name="username">
        /// Initial value of the <see cref="Username"/> property.
        /// </param>
        /// <param name="password">
        /// Initial value of the <see cref="Password"/> property.
        /// </param>
        /// <param name="enablement">
        /// Initial value of the <see cref="Enablement"/> property.
        /// </param>
        /// <param name="person">
        /// Initial value of the <see cref="Person"/> property.
        /// </param>
        public User(
            TenantId tenantId,
            string username,
            string password,
            Enablement enablement,
            Person person)
        {
            AssertionConcern.AssertArgumentNotNull(tenantId, "The tenantId is required.");
            AssertionConcern.AssertArgumentNotNull(person, "The person is required.");
            AssertionConcern.AssertArgumentNotEmpty(username, "The username is required.");
            AssertionConcern.AssertArgumentLength(username, 3, 250, "The username must be 3 to 250 characters.");

            // Defer validation to the property setters.
            this.Enablement = enablement;
            this.Person     = person;
            this.TenantId   = tenantId;
            this.Username   = username;

            this.ProtectPassword(string.Empty, password);

            person.User = this;

            DomainEventPublisher
            .Instance
            .Publish(new UserRegistered(
                         tenantId,
                         username,
                         person.Name,
                         person.ContactInformation.EmailAddress));
        }
Beispiel #2
0
        public User(
                TenantId tenantId,
                string username,
                string password,
                Enablement enablement,
                Person person)
        {
            AssertionConcern.AssertArgumentNotNull(tenantId, "The tenantId is required.");
            AssertionConcern.AssertArgumentNotNull(person, "The person is required.");
            AssertionConcern.AssertArgumentNotEmpty(username, "The username is required.");
            AssertionConcern.AssertArgumentLength(username, 3, 250, "The username must be 3 to 250 characters.");

            this.Enablement = enablement;
            this.Person = person;
            this.TenantId = tenantId;
            this.Username = username;

            ProtectPassword("", password);

            person.User = this;

            DomainEventPublisher
                .Instance
                .Publish(new UserRegistered(
                        tenantId,
                        username,
                        person.Name,
                        person.ContactInformation.EmailAddress));
        }
        private void RegisterAdministratorFor(
            Tenant tenant,
            FullName administorName,
            EmailAddress emailAddress,
            PostalAddress postalAddress,
            Telephone primaryTelephone,
            Telephone secondaryTelephone)
        {
            RegistrationInvitation invitation = tenant.OfferRegistrationInvitation("init").OpenEnded();
            string strongPassword             = new PasswordService().GenerateStrongPassword();

            // Publishes domain event UserRegistered.
            User admin = tenant.RegisterUser(
                invitation.InvitationId,
                "admin",
                strongPassword,
                Enablement.IndefiniteEnablement(),
                new Person(
                    tenant.TenantId,
                    administorName,
                    new ContactInformation(
                        emailAddress,
                        postalAddress,
                        primaryTelephone,
                        secondaryTelephone)));

            tenant.WithdrawInvitation(invitation.InvitationId);

            // Since this is a new entity, add it to
            // the collection-oriented repository.
            // Subsequent changes to the entity
            // are implicitly persisted.
            _userRepository.Add(admin);

            // Publishes domain event RoleProvisioned.
            Role adminRole = tenant.ProvisionRole(
                "Administrator",
                string.Format("Default {0} administrator.", tenant.Name));

            // Publishes domain event UserAssignedToRole,
            // but not GroupUserAdded because the group
            // reference held by the role is an "internal" group.
            adminRole.AssignUser(admin);

            // Since this is a new entity, add it to
            // the collection-oriented repository.
            // Subsequent changes to the entity
            // are implicitly persisted.
            _roleRepository.Add(adminRole);

            DomainEventPublisher
            .Instance
            .Publish(new TenantAdministratorRegistered(
                         tenant.TenantId,
                         tenant.Name,
                         administorName,
                         emailAddress,
                         admin.Username,
                         strongPassword));
        }
Beispiel #4
0
        internal User(
            TenantId tenantId,
            string username,
            string password,
            Enablement enablement,
            Person person)

            : this()
        {
            this.Enablement = enablement;
            this.Person     = person;
            this.TenantId   = tenantId;
            this.Username   = username;

            this.ProtectPassword("", password);

            person.User = this;

            DomainEventPublisher
            .Instance
            .Publish(new UserRegistered(
                         tenantId,
                         username,
                         person.Name,
                         person.ContactInformation.EmailAddress));
        }
Beispiel #5
0
        void RegisterAdministratorFor(Tenant tenant, FullName administorName, EmailAddress emailAddress, PostalAddress postalAddress, Telephone primaryTelephone, Telephone secondaryTelephone)
        {
            var invitation = tenant.OfferRegistrationInvitation("init").OpenEnded();

            var strongPassword = new PasswordService().GenerateStrongPassword();

            var admin =
                tenant.RegisterUser(
                    invitation.InvitationId,
                    "admin",
                    strongPassword,
                    Enablement.IndefiniteEnablement(),
                    new Person(
                        tenant.TenantId,
                        administorName,
                        new ContactInformation(
                            emailAddress,
                            postalAddress,
                            primaryTelephone,
                            secondaryTelephone)));

            tenant.WithdrawInvitation(invitation.InvitationId);

            this.userRepository.Add(admin);

            var adminRole = tenant.ProvisionRole("Administrator", "Default " + tenant.Name + " administrator.");

            adminRole.AssignUser(admin);

            this.roleRepository.Add(adminRole);

            DomainEventPublisher.Instance.Publish(new TenantAdministratorRegistered(tenant.TenantId, tenant.Name, administorName, emailAddress, admin.Username, strongPassword));
        }
Beispiel #6
0
        internal User(
                TenantId tenantId,
                string username,
                string password,
                Enablement enablement,
                Person person)
            : this()
        {
            this.Enablement = enablement;
            this.Person = person;
            this.TenantId = tenantId;
            this.Username = username;

            this.ProtectPassword("", password);

            person.User = this;

            DomainEventPublisher
                .Instance
                .Publish(new UserRegistered(
                        tenantId,
                        username,
                        person.Name,
                        person.ContactInformation.EmailAddress));
        }
Beispiel #7
0
        public void DefineEnablement(Enablement enablement)
        {
            this.Enablement = enablement;

            DomainEventPublisher
            .Instance
            .Publish(new UserEnablementChanged(
                         this.TenantId,
                         this.Username,
                         this.Enablement));
        }
Beispiel #8
0
 public UserEnablementChanged(
     TenantId tenantId,
     String username,
     Enablement enablement)
 {
     Enablement   = enablement;
     EventVersion = 1;
     OccurredOn   = DateTime.Now;
     TenantId     = tenantId.Id;
     Username     = username;
 }
 public UserEnablementChanged(
         TenantId tenantId,
         String username,
         Enablement enablement)
 {
     this.Enablement = enablement;
     this.EventVersion = 1;
     this.OccurredOn = DateTime.Now;
     this.TenantId = tenantId.Id;
     this.Username = username;
 }
Beispiel #10
0
 public UserEnablementChanged(
     TenantId tenantId,
     String username,
     Enablement enablement)
 {
     this.Enablement   = enablement;
     this.EventVersion = 1;
     this.OccurredOn   = DateTime.Now;
     this.TenantId     = tenantId.Id;
     this.Username     = username;
 }
Beispiel #11
0
        public override bool Equals(Object anotherObject)
        {
            bool equalObjects = false;

            if (anotherObject != null && this.GetType() == anotherObject.GetType())
            {
                Enablement typedObject = (Enablement)anotherObject;
                equalObjects =
                    this.Enabled == typedObject.Enabled &&
                    this.StartDate == typedObject.StartDate &&
                    this.EndDate == typedObject.EndDate;
            }

            return(equalObjects);
        }
Beispiel #12
0
        public void DefineEnablement(Enablement enablement)
        {
            this.Enablement = enablement;

            DomainEventPublisher
                .Instance
                .Publish(new UserEnablementChanged(
                        this.TenantId,
                        this.Username,
                        this.Enablement));
        }
Beispiel #13
0
        public User RegisterUser(
                string invitationIdentifier,
                string username,
                string password,
                Enablement enablement,
                Person person)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");

            User user = null;

            if (this.IsRegistrationAvailableThrough(invitationIdentifier))
            {
                // ensure same tenant
                person.TenantId = this.TenantId;

                user = new User(this.TenantId, username, password, enablement, person);
            }

            return user;
        }
Beispiel #14
0
        public User RegisterUser(string invitationIdentifier, string username, string password, Enablement enablement, Person person)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");

            User user = null;

            if (this.IsRegistrationAvailableThrough(invitationIdentifier))
            {
                // ensure same tenant
                person.TenantId = this.TenantId;
                user            = new User(this.TenantId, username, password, enablement, person);
            }

            return(user);
        }