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 IUser CreateUser(CreateUserParams createUserParams)
        {
            Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);

            return _contentManager.Create<User>(UserDriver.ContentType.Name, init =>
            {
                init.Record.UserName = createUserParams.Username;
                init.Record.Email = createUserParams.Email;
                init.Record.NormalizedUserName = createUserParams.Username.ToLower();
                init.Record.HashAlgorithm = "SHA1";
                SetPassword(init.Record, createUserParams.Password);
            });
        }
Example #3
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>
        /// Creates a UserPart that will be tied to the active directory
        /// username to allow the user to use the core Orchard functionality.
        /// </summary>
        /// <param name="createUserParams"></param>
        private void CreateUser(CreateUserParams createUserParams)
        {
            var user = _contentManager.New<UserPart>("User");

            user.Record.UserName = createUserParams.Username;
            user.Record.Email = createUserParams.Email;
            user.Record.NormalizedUserName = createUserParams.Username.ToLowerInvariant();
            user.Record.HashAlgorithm = "SHA1";
            user.Record.RegistrationStatus = UserStatus.Approved;
            user.Record.EmailStatus = UserStatus.Approved;
            SetPasswordHashed(user.Record, createUserParams.Password);

            _contentManager.Create(user);
        }
Example #5
0
        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;
        }
Example #6
0
		public CustomUserPart ActivateCustomUser(int userId, CreateUserParams createUserParams)
		{
			this.Logger.Information("ActivateCustomUser {0}", createUserParams.Email);

			if ( string.IsNullOrWhiteSpace(createUserParams.Email) )
			{
				throw new ArgumentException("No email adress provided!");
			}

			var customUserPart = this.GetCustomUser(userId);
			var normalizedEmailAddress = createUserParams.Email.Trim().ToLowerInvariant();

			// Prevent unnecessary override
			if ( customUserPart.User.Email != normalizedEmailAddress )
			{
				customUserPart.User.Email = normalizedEmailAddress;
			}

			this.membershipService.SetPassword(customUserPart.User, createUserParams.Password);

			var registrationSettings = this.orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
			if ( registrationSettings != null )
			{
				customUserPart.User.RegistrationStatus = registrationSettings.UsersAreModerated
					? UserStatus.Pending
					: UserStatus.Approved;

				customUserPart.User.EmailStatus = registrationSettings.UsersMustValidateEmail
					? UserStatus.Pending
					: UserStatus.Approved;
			}

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

			if ( customUserPart.User.RegistrationStatus == UserStatus.Approved )
			{
				this.userEventHandler.Approved(customUserPart.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 = this.membershipService.GetUser(userName);
					if ( recipient != null )
					{
						var template = this.shapeFactory.Create("Template_User_Moderated", Arguments.From(createUserParams));
						template.Metadata.Wrappers.Add("Template_User_Wrapper");

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

						this.messageService.Send("Email", parameters);
					}
				}
			}

			this.customUserEventHandler.CustomUserActivated(customUserPart);

			return customUserPart;
		}
Example #7
0
 public IUser CreateUser(CreateUserParams createUserParams) {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Creates a UserPart that will be tied to the active directory
        /// username to allow the user to use the core Orchard functionality.
        /// </summary>
        /// <param name="createUserParams"></param>
        /// <returns>The user object that was saved to the database.</returns>
        private IUser CreateUser(CreateUserParams createUserParams)
        {
            var user = _contentManager.New<UserPart>("User");

            user.Record.UserName = createUserParams.Username;
            user.Record.Email = createUserParams.Email;
            user.Record.NormalizedUserName = createUserParams.Username.ToLowerInvariant();
            user.Record.HashAlgorithm = "SHA1";
            user.Record.RegistrationStatus = UserStatus.Approved;
            user.Record.EmailStatus = UserStatus.Approved;
            SetPasswordHashed(user.Record, createUserParams.Password);

            _contentManager.Create(user);

            // Flush the session now so any calls to authentication service is able to pick up the new user.
            _contentManager.Flush();

            return user;
        }
Example #9
0
 public IUser CreateUser(CreateUserParams createUserParams)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public IUser CreateUser(CreateUserParams createUserParams)
 {
     return originalMembershipService.Value.CreateUser(createUserParams);
 }
		public ActionResult Activate(CustomUserActivate input)
		{
			if ( input == null )
			{
				this.ModelState.AddModelError("_form", this.T("The argument cannot be null").Text);
			}

			CustomUserPart customUserPart = null;
			if ( this.ModelState.IsValid )
			{
				customUserPart = this.myService.GetCustomUserByActivationCode(input.ActivationCode);

				if ( customUserPart == null || customUserPart.User == null || customUserPart.User.UserName != input.UserName )
				{
					this.notifier.Add(NotifyType.Error, this.T("The activation failed"));
				}

				if ( string.IsNullOrEmpty(input.Email) )
				{
					this.ModelState.AddModelError("Email", this.T("You must specify an email address.").Text);
				}
				else if ( input.Email.Length >= 255 )
				{
					this.ModelState.AddModelError("Email", this.T("The email address you provided is too long.").Text);
				}
				else if ( !Regex.IsMatch(input.Email, UserPart.EmailPattern, RegexOptions.IgnoreCase) )
				{
					// http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx    
					this.ModelState.AddModelError("Email", this.T("You must specify a valid email address.").Text);
				}
				else if ( !this.myService.VerifyEmailUnicity(customUserPart.User.Id, input.Email) )
				{
					this.ModelState.AddModelError("Email", this.T("This email address is already in use.").Text);
				}
			}

			if ( !this.ModelState.IsValid )
			{
				return this.View(input);
			}

			Debug.Assert(customUserPart != null, "customUserPart != null");
			var user = customUserPart.User;
			var userParams = new CreateUserParams(user.UserName, input.Password, input.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true);
			this.myService.ActivateCustomUser(customUserPart.Id, userParams);

			this.notifier.Add(NotifyType.Information, this.T("Your account was activated. You can now log in."));
			return this.RedirectToAction("LogOn", "Account", new { area = "Orchard.Users" });
		}