Custom registration in DotnetNuke using DotnetNuke Classes
UserController uCtrl = new UserController();//DotnetNuke Class
UserInfo oUser = new UserInfo();//DotnetNuke Class
oUser.Username = Name;
oUser.Email = Email;
oUser.PortalID = PortalId;
oUser.IsSuperUser = false;
oUser.FirstName = First Name;
oUser.LastName = Last Name;
oUser.DisplayName = Name;
oUser.Profile.Telephone = Phone;
//Want to add value in custom profile property in DNN
oUser.Profile.SetProfileProperty(“Property_Name”, “Property_Value”);
UserMembership oNewMembership = new UserMembership(oUser);
oNewMembership.Approved = true;
oNewMembership.CreatedDate = System.DateTime.Now;
oNewMembership.Password = Pass Value;//Password must be 7 charachter otherwise it will create error
oNewMembership.IsOnLine = false;
oUser.Membership = oNewMembership;
UserCreateStatus createStatus = UserController.CreateUser(ref oUser);
//If object initializes successfully then it will go in If condition
if (UserCreateStatus.Success == createStatus)
{
lblErrorUserCreation.Text=”User Created Successfully”;
}
else
{
//DotnetNuke will give u raised error
object objError = UserController.CreateUser(ref oUser);
if (UserCreateStatus.UserAlreadyRegistered.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Already Register”;
else if (UserCreateStatus.InvalidPassword.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Invalid Password”;
else if (UserCreateStatus.InvalidUserName.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Invalid User Name”;
else if (UserCreateStatus.PasswordMismatch.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Password Mismatch”;
else if (UserCreateStatus.UsernameAlreadyExists.ToString() == objError.ToString())
lblErrorUserCreation.Text = “User Already Exist”;
else if (UserCreateStatus.InvalidEmail.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Invalid Email”;
else if (UserCreateStatus.DuplicateEmail.ToString() == objError.ToString())
lblErrorUserCreation.Text = “Duplicate Email”;
else if (UserCreateStatus.DuplicateUserName.ToString() == objError.ToString())
lblErrorUserCreation.Text = “User Already exist”;
}