I have a form that registers users. The form works fine but I also need to add them to a group on submit.
I've used MemberGroup mg = MemberGroup.GetByName("All");
This is what I have so far:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using umbraco.cms.businesslogic.member; using umbraco.cms.businesslogic.propertytype;
you could do something like "newMember.AddGroup(12);" where the number corresponds with the id of your usergroup. It will work I guess, but it's deprecated.
I've been using it like this:
MembershipCreateStatus createStatus;
var user = System.Web.Security.Membership.CreateUser(emailAddress, password, emailAddress, "noquestion", "noanswer", true, out createStatus);
if (createStatus != MembershipCreateStatus.Success) { throw new MembershipCreateUserException(createStatus); } System.Web.Security.Roles.AddUserToRole(user.UserName, "YourUsergroupname");
Using AddGroup on Registration form
Hi,
I have a form that registers users. The form works fine but I also need to add them to a group on submit.
I've used MemberGroup mg = MemberGroup.GetByName("All");
This is what I have so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.propertytype;
public partial class UserControls_RegisterMember : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = umbraco.library.GetDictionaryItem("Register Name");
lblEmail.Text = umbraco.library.GetDictionaryItem("Register Email");
lblUsername.Text = umbraco.library.GetDictionaryItem("Register Username");
lblPassword.Text = umbraco.library.GetDictionaryItem("Register Password");
lblPhone.Text = umbraco.library.GetDictionaryItem("Register Phone");
lblCompany.Text = umbraco.library.GetDictionaryItem("Register Company");
lblSubscribe.Text = umbraco.library.GetDictionaryItem("Register Subscribe");
btnSubmit.Text = umbraco.library.GetDictionaryItem("Register Button");
RequiredFieldValidator1.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
RequiredFieldValidator2.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
RequiredFieldValidator3.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
RequiredFieldValidator4.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
RequiredFieldValidator5.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
RequiredFieldValidator6.Text = umbraco.library.GetDictionaryItem("Regsiter Required");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Member.GetMemberFromEmail(txtEmail.Text) == null)
{
MemberType registerMemberType = new MemberType(1212);
MemberGroup mg = MemberGroup.GetByName("All");
Member newMember = Member.MakeNew(txtName.Text, registerMemberType, new umbraco.BusinessLogic.User(0));
newMember.Email = txtEmail.Text;
newMember.LoginName = txtUsername.Text;
newMember.Password = txtPassword.Text;
newMember.getProperty("phoneNumber").Value = txtPhone.Text;
newMember.getProperty("company").Value = txtCompany.Text;
newMember.getProperty("subscribe").Value = chkSubscribe.Checked;
newMember.Save();
Panel1.Visible = false;
lblMsg.Visible = true;
lblMsg.Text = umbraco.library.GetDictionaryItem("Register Success");
}
else
{
lblError.Visible = true;
lblError.Text = umbraco.library.GetDictionaryItem("Register Error");
txtEmail.Text = "";
}
}
}
Hi Roger,
you could do something like "newMember.AddGroup(12);" where the number corresponds with the id of your usergroup. It will work I guess, but it's deprecated.
I've been using it like this:
Hope it helps you out, cheers
Jeffrey
Thanks, the 1st method worked :)
is working on a reply...