コード例 #1
0
        public AdminMember CreateMember(AdministratorRegistrationForm form)
        {
            var userName = form.Member.Email.Scrub();
            var password = form.Password.Scrub();
            var model    = AdminMember.Empty;

            if (this.IsMongoMembershipEnabled)
            {
                try
                {
                    var status         = MembershipCreateStatus.UserRejected;
                    var membershipUser = this.MembershipProvider.CreateUser(userName, password, userName, "", "", true, null, out status);

                    if (status == MembershipCreateStatus.Success)
                    {
                        // create a user account
                        model = this.Uow.Administrators.CreateMember(form, membershipUser.ProviderUserKey.ToString());

                        if (model == null)
                        {
                            throw new Exception("failed to create administrator account");
                        }
                    }
                    else
                    {
                        Logger.Warn(string.Format("Failed to create administrator: {0}. Reason: {1}", userName, status));
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(string.Format("Error creating administrator: {0}", userName), e);
                    throw e;
                }
            }
            else
            {
                // create a user account
                model = this.Uow.Administrators.CreateMember(form, string.Empty);

                if (model == null)
                {
                    throw new Exception("failed to create administrator account");
                }
            }

            try
            {
                WebSecurity.CreateUserAndAccount(userName, password, new
                {
                    MongoUserId = model.Id
                });
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Error creating WebSecurity administrator: {0}", userName), e);
                throw e;
            }

            return(model);
        }
コード例 #2
0
        public HttpResponseMessage CreateAdministratorMember(AdministratorRegistrationForm registrationForm)
        {
            var formValidation = registrationForm.Validate(this.AccountSession, ValidationMode.Create);

            if (formValidation.IsValid)
            {
                try
                {
                    // create the account
                    var member = this.AuthenticationSecurity.CreateMember(registrationForm);

                    // add appropriate roles to the account
                    var roles = new string[2] {
                        Definitions.Account.Roles.Elevated, Definitions.Account.Roles.Administrator
                    };

                    this.AuthenticationSecurity.AddRolesToUser(registrationForm.Member.Email, roles);

                    // get the updated administrator member
                    var results = this.Uow.Administrators.GetById(member.Id);

                    return(CreateSuccessResponse(new { success = true, results = results }, HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    // log exception
                    Logger.Error(string.Format("Exception detected attempting to create administrator member via user {0}", this.AccountSession.MemberId), ex);

                    return(CreateErrorResponse(ex));
                }
            }

            // invalid parameters, generate response
            return(CreateInvalidResponse(formValidation));
        }
コード例 #3
0
        public void CreateAdministratorAccount()
        {
            // TODO: figure out how we an create the UoW w/o doing this
            this.Uow = new ObsequyUow(new RepositoryProvider(new RepositoryFactories()));

            // ?? we should probably put this in the web config
            var form = new AdministratorRegistrationForm()
            {
                Member = new AdminMember()
                {
                    Email     = "*****@*****.**",
                    FirstName = "Big",
                    LastName  = "Daddy",
                    IsNotifiedOnConsumerRegistrations = true,
                    IsNotifiedOnProviderRegistrations = true,
                    IsNotifiedOnAcceptedResponses     = true,
                    IsNotifiedOnExceptions            = false
                },
                Password        = "******",
                ConfirmPassword = "******",
            };

            if (!WebSecurity.UserExists(form.Member.Email))
            {
                // register this account
                CreateMember(form);

                // add appropriate roles to the account
                var roles = new string[2] {
                    Definitions.Account.Roles.Elevated, Definitions.Account.Roles.Administrator
                };

                AddRolesToUser(form.Member.Email, roles);
            }
        }
コード例 #4
0
        public AdminMember CreateMember(AdministratorRegistrationForm registrationForm, string membershipId)
        {
            // create the model
            var model = new AdminMember()
            {
                AccountType     = AccountType.Administrator,
                AccountStatus   = AccountStatus.Active,
                AccountPrestige = AccountPrestige.None,
                MembershipId    = membershipId,
                Email           = registrationForm.Member.Email.Scrub(),
                FirstName       = registrationForm.Member.FirstName.Scrub(),
                LastName        = registrationForm.Member.LastName.Scrub(),
                Created         = new ChangeReceipt(this.AccountSession),
                Modified        = new ChangeReceipt(this.AccountSession),
                IsNotifiedOnConsumerRegistrations = registrationForm.Member.IsNotifiedOnConsumerRegistrations,
                IsNotifiedOnProviderRegistrations = registrationForm.Member.IsNotifiedOnProviderRegistrations,
                IsNotifiedOnAcceptedResponses     = registrationForm.Member.IsNotifiedOnAcceptedResponses,
                IsNotifiedOnExceptions            = registrationForm.Member.IsNotifiedOnExceptions
            };

            // insert the collection
            var result = this.Collection.Insert(model);

            if (result.Ok)
            {
                // log the creation
                this.Logger.Info(string.Format("created administrator member for email {0} with ID {1}", model.Email, model.Id));

                // return the created model
                return(model);
            }
            else
            {
                // log the failure
                this.Logger.Error(string.Format("failed to create administrator member for email {0}. Code: {1}, Reason: {2}", model.Email, result.Code, result.ErrorMessage));
            }

            return(null);
        }