Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • nickornotto 317 posts 679 karma points
    Apr 04, 2013 @ 13:03
    nickornotto
    0

    Username validation not working in CreateUserWizard

    I have a CreateUserWizard for users to register new account.

    I have added my text fields and required field validators

    However when I click register button with empty username I get error:

     Exception Details: System.ArgumentException: The username of a Member must be different from an emptry string
    Parameter name: loginName

    The username field has its requiredfieldvalidator so it should work. I have also added UserNameRequiredErrorMessage property to the wizard.

    loginName mentioned in the above error message is a control for LoginView. I have this on the same page but it's not used during the registration for CreateUserWizard.

    Why is this happening?

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Apr 04, 2013 @ 23:32
    Jan Skovgaard
    0

    Hi Eva

    Could you perhaps show us the code you have written for this? It will make it easier to pinpoint what might be the caue of the above error.

    /Jan

  • Charles Afford 1163 posts 1709 karma points
    Apr 04, 2013 @ 23:36
    Charles Afford
    0

    Hi, is this something you have created?  It sounds like the problem i had trying to get strongly typed access to member properties.  If so you need to make sure your alias and name are diffrent.  Umbraco appears to do a lower case match thus no diffrence between your name and alias if they are the same name

  • nickornotto 317 posts 679 karma points
    Apr 05, 2013 @ 15:52
    nickornotto
    0

    My code:

        <asp:Panel ID="pnlRegister" runat="server">
       
        <asp:CreateUserWizard ID="cuwRegister" RequireEmail="false"
        OnContinueButtonClick="cuwRegister_ContinueButtonClick"
            OnCreatedUser="cuwRegister_CreatedUser" 
        runat="server">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
        <ContentTemplate>
        <asp:ValidationSummary ID="uxValSummaryRegister" DisplayMode="BulletList" runat="server" ValidationGroup="CreateUserWizard" ForeColor="#FF5555" />
        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>

                    <div class="row">
                        <label>Email</label>
                        <asp:TextBox ID="UserName" runat="server" />
              <asp:requiredfieldvalidator runat="server"
                                controltovalidate="UserName"
                                tooltip="Email is a required"
                                id="reqEmail"
                                validationgroup="CreateUserWizard"
                                errormessage="Email is a required" Display="Dynamic">
                                *
                              </asp:requiredfieldvalidator>
                        <asp:RegularExpressionValidator ID="revEmail" runat="server"
                            ControlToValidate="UserName"
                            ErrorMessage="Enter correct email address"
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*
                        </asp:RegularExpressionValidator>
                    </div>
                    <div class="row">
                        <label><umbraco:Macro Item="Confirm email" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="ConfirmEmail" runat="server" />
              <asp:requiredfieldvalidator runat="server"
                                controltovalidate="ConfirmEmail"
                                tooltip="Confirm Email address is a required"
                                id="reqConfirmEmail"
                                validationgroup="CreateUserWizard"
                                errormessage="Confirm Email address is a required">
                                *
                              </asp:requiredfieldvalidator>
                        <asp:CompareValidator runat="server"
                            id="cmpNumbers"
                            controltovalidate="ConfirmEmail"
                            controltocompare="UserName"
                            operator="Equal"
                            type="String"
                            errormessage="Email and Confirm Email do not match" />
                    </div>
                    <div class="row">
                        <label><umbraco:Macro Item="Password" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="Password" runat="server" TextMode="Password" />
              <asp:requiredfieldvalidator runat="server"
                                controltovalidate="Password"
                                tooltip="Password is a required"
                                id="reqPassword"
                                validationgroup="CreateUserWizard"
                                errormessage="Password is a required">
                                *
                              </asp:requiredfieldvalidator>
                    </div>
                    <div class="row">
                        <label><umbraco:Macro Item="Confirm password" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" />
              <asp:requiredfieldvalidator runat="server"
                                controltovalidate="ConfirmPassword"
                                tooltip="Confirm Password is a required"
                                id="Requiredfieldvalidator1"
                                validationgroup="CreateUserWizard"
                                errormessage="Confirm Password is a required">
                                *
                              </asp:requiredfieldvalidator>
                        <asp:CompareValidator runat="server"
                            id="CompareValidator1"
                            controltovalidate="ConfirmPassword"
                            controltocompare="Password"
                            operator="Equal"
                            type="String"
                            errormessage="Password and Confirm Password do not match" />
                    </div>

                    <div class="row">
                        <label><umbraco:Macro Item="First name" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="txtFirstName" runat="server" />
                    </div>
                    <div class="row">
                        <label><umbraco:Macro Item="Surname" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="txtSurname" runat="server" />
                    </div>
                    <div class="row">
                        <label><umbraco:Macro Item="Date of birth" Alias="Dictionary-Item" runat="server" /></label>
                        <asp:TextBox ID="DOB" runat="server" />
              <asp:requiredfieldvalidator runat="server"
                                controltovalidate="DOB"
                                tooltip="Date of birth is a required"
                                id="Requiredfieldvalidator2"
                                validationgroup="CreateUserWizard"
                                errormessage="Date of birth is a required">
                                *
                              </asp:requiredfieldvalidator>
                    </div>

                    </ContentTemplate>
                    </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"></asp:CompleteWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>

    </asp:Panel>

    <asp:Panel ID="pnlLogin" runat="server">

    <asp:LoginView ID="lwLogin" runat="server">
        <AnonymousTemplate>
            <asp:Login ID="lwLoginPanel" TitleTextStyle-CssClass="h1" runat="server"></asp:Login>
        </AnonymousTemplate>
        <LoggedInTemplate>
                <asp:LoginName
            <asp:LoginStatus ID="logStatus" runat="server" />
        </LoggedInTemplate>
    </asp:LoginView>

    </asp:Panel>

    <asp:Panel ID="pnlThankYou" Visible="false" runat="server">

    <umbraco:Item field="thankYou" runat="server" />

    </asp:Panel>




    and in the code behind:


        protected void cuwRegister_CreatedUser(object sender, EventArgs e)
        {
            string email = cuwRegister.UserName;
            string username = cuwRegister.UserName;
            string password = cuwRegister.Password;
            Page.Validate("CreateUserWizard");
            if(Page.IsValid)
                CreateUser(email, username, password);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            btnRegister.Text = cuwRegister.CreateUserButtonText = umbraco.library.GetDictionaryItem("Register");
            cuwRegister.DuplicateUserNameErrorMessage = umbraco.library.GetDictionaryItem("Duplicated email");
            cuwRegister.DuplicateEmailErrorMessage = umbraco.library.GetDictionaryItem("Duplicated email");
            cuwRegister.InvalidEmailErrorMessage = umbraco.library.GetDictionaryItem("Email address incorrect");
            cuwRegister.InvalidPasswordErrorMessage = umbraco.library.GetDictionaryItem("Password incorrect");
            cuwRegister.EmailRequiredErrorMessage = umbraco.library.GetDictionaryItem("Email required");
            cuwRegister.PasswordRequiredErrorMessage = umbraco.library.GetDictionaryItem("Password required");
            cuwRegister.ConfirmPasswordCompareErrorMessage = umbraco.library.GetDictionaryItem("Password not matching");
            cuwRegister.UserNameRequiredErrorMessage = umbraco.library.GetDictionaryItem("Password not matching");


            Login lwPanelLogin = (Login)lwLogin.FindControl("lwLoginPanel");
            if (lwPanelLogin != null)
            {
                lwPanelLogin.TitleText = umbraco.library.GetDictionaryItem("Already registered? Log in here");
                lwPanelLogin.LoginButtonText = umbraco.library.GetDictionaryItem("Login");
                lwPanelLogin.RememberMeText = umbraco.library.GetDictionaryItem("Remember me next time");
                lwPanelLogin.PasswordLabelText = umbraco.library.GetDictionaryItem("Password");
                lwPanelLogin.UserNameLabelText = "Email";
            }
        }

        protected void CreateUser(string email, string username, string password)
        {
            bool isLoggedIn = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
            if (Membership.GetUserNameByEmail(email) == null)
            {
                MembershipUser member = Membership.CreateUser("aaa", password, email);
            }

            if(!isLoggedIn)
                if (System.Web.Security.Membership.ValidateUser(username, password))
                {
                    FormsAuthentication.SetAuthCookie(username, true);
                }
        }




    (Note that I use Username field to get email and then email is used to login)

  • Charles Afford 1163 posts 1709 karma points
    Apr 05, 2013 @ 21:04
    Charles Afford
    0

    Ok, dont think it was what i was thinking of.  Will have a think

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies