1

we create a custom registration page to register extra-net user in our sitecore application ,but our customer request activation email to activate account . the problem is there is no activation filed in the sitecore core db , there is any solution to achieve this requirement ?

string userName = string.Concat(firstName, lastName);
            userName = string.Format(@"{0}\{1}", domain, userName);
            string newPassword = Membership.GeneratePassword(10, 3);
            try
            {
                if (!User.Exists(userName))
                {
                    Membership.CreateUser(userName, newPassword, email);

}
1
  • Are you kidding me with this many tags?
    – Mark Cassidy
    Commented Apr 2, 2019 at 9:36

2 Answers 2

0

MembershipUser has a property(IsApproved) to disable the user.

So the code will be

            string userName = string.Concat(firstName, lastName);
            userName = string.Format(@"{0}\{1}", domain, userName);
            string newPassword = Membership.GeneratePassword(10, 3);
            try
            {
                if (!User.Exists(userName))
                {
                  var createduser =  Membership.CreateUser(userName, newPassword, email);
                  createduser.IsApproved = false;
                  Membership.UpdateUser(createduser);
            }

This disables the created user. On the mail activation, the code will be

          if (Sitecore.Security.Accounts.User.Exists(userName))
            {
                var createduser=  Membership.GetUser(userName);
                createduser.IsApproved = true;
                Membership.UpdateUser(createduser);

            }
0

Didn't test this in a Sitecore setup, but the CreateUser method does have an overloaded version like this:

public static System.Web.Security.MembershipUser CreateUser (string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status);

Important here is the "isApproved" boolean. If you set that to false, the user is created but should not be able to login. Once activated, you could set this value to true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.