public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            var user = workflowContext.Content.As <UserPart>();

            user.RegistrationStatus = UserStatus.Approved;
            user.EmailStatus        = UserStatus.Approved;
            _userEventHandlers.Approved(user);

            yield return(T("Done"));
        }
예제 #2
0
        public ActionResult Approve(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
            {
                return(new HttpUnauthorizedResult());
            }

            var user = Services.ContentManager.Get <IUser>(id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            user.As <UserPart>().RegistrationStatus = UserStatus.Approved;
            Services.Notifier.Information(T("User {0} approved", user.UserName));
            _userEventHandlers.Approved(user);

            return(RedirectToAction("Index"));
        }
예제 #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);
        }
예제 #4
0
        public ActionResult Approve(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, "Not authorized to manage users"))
            {
                return(new HttpUnauthorizedResult());
            }

            var user = _userRepository.Get(id);

            if (user != null)
            {
                user.RegistrationStatus = UserStatus.Approved;
                Services.Notifier.Information(string.Format("User {0} approved", user.UserName));
                _userEventHandlers.Approved(user);
            }

            return(RedirectToAction("Index"));
        }
예제 #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      = PBKDF2;
            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
            };

            _userEventHandlers.Creating(userContext);

            if (userContext.Cancel)
            {
                return(null);
            }

            _orchardServices.ContentManager.Create(user);

            _userEventHandlers.Created(userContext);
            if (user.RegistrationStatus == UserStatus.Approved)
            {
                _userEventHandlers.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);
        }