public void Created(UserContext context)
        {
            //run through each role to see if the new user complies to a role to let them in a certain area.
            var rules = validationService.GetRules().Where(e => e.CheckUserOnRegistration).ToList();
            var rulesGroupByRole = rules.GroupBy(e => e.RoleTargetRecord).ToDictionary(e => e.Key, e => e.ToList());

            foreach (var group in rulesGroupByRole.Keys)
            {
                var actualRole = roleService.GetRoleByName(group.RoleName);
                var collecion = rulesGroupByRole[group];
                foreach (var rule in collecion)
                {
                    if (!validationService.SatisfyRule(context.User, rule))
                        continue;

                    var userRolePart = context.User.As<UserRolesPart>();
                    userRolePart.Roles.Add(actualRole.Name);

                    userRolesRepository.Create(new UserRolesPartRecord()
                    {
                        UserId = context.User.Id,
                        Role = actualRole
                    });

                    break;
                }
            }
        }
        public IUser CreateUser(CreateUserParams createUserParams) {
            Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);

            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();

            var user = _orchardServices.ContentManager.New<UserPart>("User");

            user.Record.UserName = createUserParams.Username;
            user.Record.Email = createUserParams.Email;
            user.Record.NormalizedUserName = createUserParams.Username.ToLowerInvariant();
            user.Record.HashAlgorithm = "SHA1";
            SetPassword(user.Record, createUserParams.Password);

            if ( registrationSettings != null ) {
                user.Record.RegistrationStatus = registrationSettings.UsersAreModerated ? UserStatus.Pending : UserStatus.Approved;
                user.Record.EmailStatus = registrationSettings.UsersMustValidateEmail ? UserStatus.Pending : UserStatus.Approved;
            }

            if(createUserParams.IsApproved) {
                user.Record.RegistrationStatus = UserStatus.Approved;
                user.Record.EmailStatus = UserStatus.Approved;
            }

            var userContext = new UserContext {User = user, Cancel = false};
            foreach(var userEventHandler in _userEventHandlers) {
                userEventHandler.Creating(userContext);
            }

            if(userContext.Cancel) {
                return null;
            }

            _orchardServices.ContentManager.Create(user);

            foreach ( var userEventHandler in _userEventHandlers ) {
                userEventHandler.Created(userContext);
                if (user.RegistrationStatus == UserStatus.Approved) {
                    userEventHandler.Approved(user);
                }
            }

            if ( registrationSettings != null  && registrationSettings.UsersAreModerated && registrationSettings.NotifyModeration && !createUserParams.IsApproved ) {
                var usernames = String.IsNullOrWhiteSpace(registrationSettings.NotificationsRecipients)
                                    ? new string[0]
                                    : registrationSettings.NotificationsRecipients.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);

                foreach ( var userName in usernames ) {
                    if (String.IsNullOrWhiteSpace(userName)) {
                        continue;
                    }
                    var recipient = GetUser(userName);
                    if (recipient != null)
                        _messageManager.Send(recipient.ContentItem.Record, MessageTypes.Moderation, "email" , new Dictionary<string, string> { { "UserName", createUserParams.Username}, { "Email" , createUserParams.Email } });
                }
            }

            return user;
        }
        public void Created(UserContext context)
        {
            var role = _roleService.GetRoleByName("Harvester");

            if (role == null) {
                _notifier.Warning(T("No role found with the name <strong>Harvester</strong>"));
                return;
            }

            _userRolesRepository.Create(new UserRolesPartRecord { Role = role, UserId = context.User.Id });
            _notifier.Information(T("Thanks for registering! You have been added to the {0} role.", role.Name));
        }
        public void Created(UserContext context)
        {
            if (!_facebookConnectService.IsAuthenticated()) return;

            // This can happen if someone connects to the site with FB, logs out then registers a new user while being logged in to FB.
            // This prevents to attach the same FB user to different local users.
            if (_facebookConnectService.AuthenticatedFacebookUserIsSaved()) return;

            var facebookUser = _facebookConnectService.FetchMe();
            IEnumerable<FacebookConnectValidationKey> errors;
            if (_facebookConnectService.UserIsValid(facebookUser, _siteService.GetSiteSettings().As<FacebookConnectSettingsPart>(), out errors))
            {
                _facebookConnectService.UpdateFacebookUser(context.User.As<IUser>(), facebookUser);
            }
        }
Beispiel #5
0
        public IUser CreateUser(CreateUserParams createUserParams)
        {
            Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);

            var user = new UserRecord();

            user.UserName = createUserParams.Username;
            user.Email = createUserParams.Email;
            user.NormalizedUserName = createUserParams.Username.ToLowerInvariant();
            user.HashAlgorithm = PBKDF2;
            SetPassword(user, createUserParams.Password);

            user.RegistrationStatus = UserStatus.Approved;
            user.EmailStatus = UserStatus.Approved;

            if (createUserParams.IsApproved)
            {
                user.RegistrationStatus = UserStatus.Approved;
                user.EmailStatus = UserStatus.Approved;
            }

            var userContext = new UserContext { User = user, Cancel = false, UserParameters = createUserParams };
            _userEventHandlers.Creating(userContext);

            if (userContext.Cancel)
            {
                return null;
            }

            _userRepository.Create(user);

            _userEventHandlers.Created(userContext);
            if (user.RegistrationStatus == UserStatus.Approved)
            {
                _userEventHandlers.Approved(user);
            }

            return user;
        }
 /// <summary>
 /// Called before a User is created
 /// </summary>
 public void Creating(UserContext context)
 {
     return;
 }
 public void Created(UserContext context) {
 }
 public void Creating(UserContext context) {
 }
        public IUser CreateUser(CreateUserParams createUserParams)
        {
            Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);

            var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();

            var user = _orchardServices.ContentManager.New<UserPart>("User");

            user.UserName = createUserParams.Username;
            user.Email = createUserParams.Email;
            user.NormalizedUserName = createUserParams.Username.ToLowerInvariant();
            user.HashAlgorithm = "SHA1";
            SetPassword(user, createUserParams.Password);

            if ( registrationSettings != null ) {
                user.RegistrationStatus = registrationSettings.UsersAreModerated ? UserStatus.Pending : UserStatus.Approved;
                user.EmailStatus = registrationSettings.UsersMustValidateEmail ? UserStatus.Pending : UserStatus.Approved;
            }

            if(createUserParams.IsApproved) {
                user.RegistrationStatus = UserStatus.Approved;
                user.EmailStatus = UserStatus.Approved;
            }

            var userContext = new UserContext {User = user, Cancel = false, UserParameters = createUserParams};
            foreach(var userEventHandler in _userEventHandlers) {
                userEventHandler.Creating(userContext);
            }

            if(userContext.Cancel) {
                return null;
            }

            _orchardServices.ContentManager.Create(user);

            foreach ( var userEventHandler in _userEventHandlers ) {
                userEventHandler.Created(userContext);
                if (user.RegistrationStatus == UserStatus.Approved) {
                    userEventHandler.Approved(user);
                }
            }

            if ( registrationSettings != null
                && registrationSettings.UsersAreModerated
                && registrationSettings.NotifyModeration
                && !createUserParams.IsApproved ) {
                var usernames = String.IsNullOrWhiteSpace(registrationSettings.NotificationsRecipients)
                                    ? new string[0]
                                    : registrationSettings.NotificationsRecipients.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);

                foreach ( var userName in usernames ) {
                    if (String.IsNullOrWhiteSpace(userName)) {
                        continue;
                    }
                    var recipient = GetUser(userName);
                    if (recipient != null) {
                        var template = _shapeFactory.Create("Template_User_Moderated", Arguments.From(createUserParams));
                        template.Metadata.Wrappers.Add("Template_User_Wrapper");

                        var parameters = new Dictionary<string, object> {
                            {"Subject", T("New account").Text},
                            {"Body", _shapeDisplay.Display(template)},
                            {"Recipients", new [] { recipient.Email }}
                        };

                        _messageService.Send("Email", parameters);
                    }
                }
            }

            return user;
        }
 public void Created(UserContext context) {
     CreateOrUpdateOpenAuthUser(context.User);
 }
Beispiel #11
0
		public CustomUserPart CreateCustomUser(CustomUserCreate customUserCreate)
		{
			this.Logger.Information("CreateCustomUser {0}", customUserCreate.UserName);

			var customUser = this.ContentManager.New("CustomUser");
			var customUserPart = customUser.As<CustomUserPart>();
			customUserPart.ActivationCode = customUserCreate.ActivationCode;
			customUserPart.FirstName = customUserCreate.FirstName.TrimSafe();
			customUserPart.LastName = customUserCreate.LastName.TrimSafe();
			customUserPart.WelcomeText = customUserCreate.WelcomeText;

			var user = this.ContentManager.New<UserPart>("User");
			user.UserName = customUserCreate.UserName.TrimSafe();
			user.NormalizedUserName = customUserCreate.UserName.TrimSafe().ToLowerInvariant();
			user.Email = customUserCreate.Email != null ? customUserCreate.Email.Trim().ToLowerInvariant() : null;
			user.HashAlgorithm = PBKDF2;
			user.RegistrationStatus = UserStatus.Pending;
			user.EmailStatus = UserStatus.Pending;
			this.ContentManager.Create(user);

			customUserPart.User = user;

			customUser.As<CommonPart>().Owner = user;

			var userContext = new UserContext
							  {
								  User = customUserPart.User,
								  Cancel = false,
								  UserParameters = new CreateUserParams(customUserCreate.UserName, null, null, null, null, false)
							  };

			this.userEventHandler.Creating(userContext);

			if ( userContext.Cancel )
			{
				return null;
			}

			this.ContentManager.Create(customUser);
			this.userEventHandler.Created(userContext);
			this.customUserEventHandler.CustomUserCreated(customUserPart);

			return customUserPart;
		}
Beispiel #12
0
 public void Created(UserContext context) {
     //_contentManager.Flush();
     //Add users to Mailing List
 }
Beispiel #13
0
 public void Created(UserContext context) {
     _userkeyService.SaveKeyForUser(context.User.Id, Guid.NewGuid());
 }
Beispiel #14
0
 public void Creating(UserContext context) {
     //Not handled
 }
 public void Created(UserContext context) {
     _workflowManager.TriggerEvent("UserCreated",
                                  context.User,
                                  () => new Dictionary<string, object> {{"User", context}});
 }