More in this section
Forums / Security / new user registraiton

new user registraiton

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    08 Nov 2009
    Link to this post
    I am trying to get the email address to write to the user tbale but I am not sure how with this code. The user name is their email and ideally I would like to simply duplicate the user name (email) to the email field in the user table. Then use that email to send a registration confirmation.  Can you help me with this? 

    using System;  
    using System.Collections;  
    using System.Collections.Generic;  
    using System.Configuration;  
    using System.Data;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Text;  
    using Telerik.Security;  
     
    public partial class Custom_Controls_Login_NewUserRegistration : System.Web.UI.UserControl  
    {
        #region Properties  
     
        public CreateUserWizard CreateUserWizard  
        {  
            get 
            {  
                return this.CreateUserWizard1;  
            }  
            set 
            {  
                this.CreateUserWizard1 = value;  
            }  
        }
        #endregion  
     
        #region Methods  
     
        protected override void OnInit(EventArgs e)  
        {  
            base.OnInit(e);  
     
            this.CreateUserWizard1.CreatedUser += new EventHandler(CreateUserWizard1_CreatedUser);  
        }
        #endregion  
     
        #region Event handlers  
     
        // TODO :   
        //CreateUserWizard.OnSendingMail Method, CreateUserWizard.SendingMail Event or MailDefinition  
     
        void CreateUserWizard1_CreatedUser(object sender, EventArgs e)  
        {  
            UserManager manager = new UserManager(CreateUserWizard1.MembershipProvider);  
            if (!manager.RoleExists("1 ALL NEW USERS"))  
                manager.CreateRole("1 ALL NEW USERS");  
     
            manager.AddUserToRole(CreateUserWizard1.UserName, "NEW Person");  
        }  
     
        // Save users profile info  
        protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)  
        {  
            TextBox txtFirstName = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtFirstName");  
            TextBox txtLastName = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtLastName");  
            TextBox txtTitle = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtTitle");  
            TextBox txtCompany = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtCompany");  
            TextBox txtAddress1 = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtAddress1");  
            TextBox txtAddress2 = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtAddress2");  
            TextBox txtCity = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtCity");  
            TextBox txtState = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtState");  
            TextBox txtZip = (TextBox)CreateUserWizard1.ActiveStep.FindControl("txtZip");  
     
            ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(this.Page.User.Identity.Name, true);  
            profile.FirstName = txtFirstName.Text;  
            profile.LastName = txtLastName.Text;  
            profile.Title = txtTitle.Text;  
            profile.CompanyName = txtCompany.Text;  
            profile.Address1 = txtAddress1.Text;  
            profile.Address2 = txtAddress2.Text;  
            profile.City = txtCity.Text;  
            profile.State = txtState.Text;  
            profile.Zip = txtZip.Text;  
              
            profile.Save();  
        }
        #endregion  
     
    }  
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewUserRegistration.ascx.cs" Inherits="Custom_Controls_Login_NewUserRegistration" %> 
     
     
    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"   
        RequireEmail="False" onfinishbuttonclick="CreateUserWizard1_FinishButtonClick">  
        <WizardSteps> 
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">  
                <ContentTemplate> 
                    <table border="0">  
                        <tr> 
                            <td align="center" colspan="2">  
                                Sign Up for Your New Account</td> 
                        </tr> 
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Email:</asp:Label></td>  
                            <td> 
                                <asp:TextBox ID="UserName" runat="server"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" Display="Dynamic" cssClass="Validator" 
                                    ErrorMessage="Email is required." ToolTip="Enter your email address. This will be your user name."   
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                                    <asp:RegularExpressionValidator ID="EmailValid" runat="server" Display="Dynamic" cssClass="Validator" ControlToValidate="UserName" ValidationGroup="CreateUserWizard1"   
                                    ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" ErrorMessage="Email address is not valid" /> 
     
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></td>  
                            <td> 
                                <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
                                    ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label></td>  
                            <td> 
                                <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" 
                                    ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." 
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label></td>  
                            <td> 
                                 <asp:DropDownList ID="Question" runat="server" Width="200">  
                                            <asp:ListItem Text="[Select a Question]" /> 
                                            <asp:ListItem Text="Favorite Pet" /> 
                                            <asp:ListItem Text="What is your elemetary school name?"  /> 
                                            <asp:ListItem Text="Who was your childhood hero?"  /> 
                                            <asp:ListItem Text="Your favorite hobby?"  /> 
                                        </asp:DropDownList> 
                                          
                                     
                                <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" InitialValue="[Select a Question]" ControlToValidate="Question" 
                                    ErrorMessage="Select a Security Question" ToolTip="Security question is required." 
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Your Answer:</asp:Label></td>  
                            <td> 
                                <asp:TextBox ID="Answer" runat="server"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" 
                                    ErrorMessage="Security answer is required." ToolTip="Security answer is required." 
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td align="center" colspan="2">  
                                <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" 
                                    ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." 
                                    ValidationGroup="CreateUserWizard1"></asp:CompareValidator> 
                            </td> 
                        </tr> 
                          
                        <tr> 
                            <td align="right">  
                                <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="txtEmail">Email:</asp:Label></td>  
                            <td> 
                                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="txtEmail" Display="Dynamic"   
                                    ErrorMessage="Email is required." ToolTip="Enter your email address."   
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" Display="Dynamic" ControlToValidate="txtEmail" ValidationGroup="CreateUserWizard1"   
                                    ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" ErrorMessage="Email address is not valid" /> 
     
                            </td> 
                        </tr> 
                          
                        <tr> 
                            <td align="center" colspan="2" style="color: red">  
                                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> 
                            </td> 
                        </tr> 
                    </table> 
                </ContentTemplate> 
            </asp:CreateUserWizardStep> 
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Profile">  
                <table class="style1">  
                    <tr> 
                        <td> 
                            First name</td> 
                        <td> 
                            <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                    <tr> 
                        <td> 
                            Last name</td> 
                        <td> 
                            <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                    <tr> 
                        <td> 
                            Title</td> 
                        <td> 
                            <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"   
                                ControlToValidate="txtTitle" ErrorMessage="* required">* required</asp:RequiredFieldValidator> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td> 
                            Company Name</td> 
                        <td> 
                            <asp:TextBox ID="txtCompany" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                      <tr> 
                        <td> 
                            Address</td> 
                        <td> 
                            <asp:TextBox ID="txtAddress1" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                    <tr> 
                        <td> 
                            &nbsp;</td> 
                        <td> 
                            <asp:TextBox ID="txtAddress2" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                    <tr> 
                        <td> 
                            City</td> 
                        <td> 
                            <asp:TextBox ID="txtCity" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"   
                                ControlToValidate="txtCity" ErrorMessage="* required">* required</asp:RequiredFieldValidator> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td> 
                            State</td> 
                        <td> 
                            <asp:TextBox ID="txtState" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"   
                                ControlToValidate="txtState" ErrorMessage="* required">* required</asp:RequiredFieldValidator> 
                        </td> 
                    </tr> 
                    
                    <tr> 
                        <td> 
                            Zip</td> 
                        <td> 
                            <asp:TextBox ID="txtZip" runat="server"></asp:TextBox> 
                        </td> 
                        <td> 
                            &nbsp;</td> 
                    </tr> 
                </table> 
            </asp:WizardStep> 
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">  
                <ContentTemplate> 
                  
     
     
     
                    <table border="0">  
                        <tr> 
                            <td align="center" colspan="2">  
                                <h2>Registration Pending</h2></td>  
                        </tr> 
                        <tr> 
                            <td> 
                                <class="message">  
        Thankyou for registering!<br /> 
        Your registration is currently pending approval.<br /> 
        You will receive a notification email indicating the result during the next couple of days.  
    </p></td>  
                        </tr> 
                        <tr> 
                            <td align="right" colspan="2">  
                                <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" CommandName="Continue" 
                                    Text="Continue" ValidationGroup="CreateUserWizard1" /> 
                            </td> 
                        </tr> 
                    </table> 
                </ContentTemplate> 
            </asp:CompleteWizardStep> 
        </WizardSteps> 
        <FinishNavigationTemplate> 
            <asp:Button ID="FinishPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious" 
                Text="Previous" /> 
            <asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete" Text="Finish" /> 
        </FinishNavigationTemplate> 
        <StartNavigationTemplate> 
            <asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" Text="Next" /> 
        </StartNavigationTemplate> 
        <StepNavigationTemplate> 
            <asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False" CommandName="MovePrevious" 
                Text="Previous" /> 
            <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" Text="Next" /> 
        </StepNavigationTemplate> 
    </asp:CreateUserWizard> 
     
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Nov 2009
    Link to this post
    Hi Laura,

    You can subscribe for CreatingUser event and add cancel the base code by calling e.cancel = true. Then set the username as email of the user being created.

    void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
      {
         MembershipUser u = Membership.CreateUser(CreateUserWizard1.UserName, CreateUserWizard1.Password, CreateUserWizard1.UserName);
         e.Cancel = true;
      }

    Another option is modifying the template and setting AutoPostBack for the TextBox with ID="UserName". Then add the following logic to the code behind of the control

    protected override void OnLoad(EventArgs e)
       {
           base.OnLoad(e);
           if (!String.IsNullOrEmpty(CreateUserWizard1.UserName))
           {
               CreateUserWizard1.Email = CreateUserWizard1.UserName;
           }
       }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered