Copied to clipboard

Flag this post as spam?

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


  • Giacomo Cosenza 16 posts 36 karma points
    Apr 18, 2011 @ 19:08
    Giacomo Cosenza
    0

    Check validate user on Login and send email Validation

    Hello everyone. I'm trying to implement the user registration procedure by sending an email to validate your account. This is the code to the registration:

     

    try
                {
                    /* User is created and setting extra parameters to profile */
                    TextBox UserNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                    string username = UserNameTextBox.Text;
    
    
                    //MemberType mt = new MemberType(
                    MembershipUser User = Membership.GetUser(username);
                    umbraco.cms.businesslogic.member.Member member = new umbraco.cms.businesslogic.member.Member((int)User.ProviderUserKey);
    
    
                    /* Here you can access properties for the member */
    
                    umbraco.cms.businesslogic.property.Property FullNameProperty = member.getProperty("fullname"); // Property alias
    
                    TextBox FullNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FullName");
    
                    FullNameProperty.Value = FullNameTextBox.Text;
    
                    //member.AddGroup(1068);
    
    
                    Guid activationCode = Guid.NewGuid();
    
                    member.getProperty("active").Value = false;
                    member.getProperty("activationCode").Value = activationCode.ToString();
    
    
             // send mail 
    MailMessage Msg = new MailMessage(); Msg.From = new MailAddress("[email protected]", "Cef Activation Account"); Msg.To.Add(member.Email); Response.Write(member.Email); Msg.Subject = "Attivazione account"; Msg.Body = "umbraco.xxxx.com/registrazione.aspx?user=" + username + "&ac=" + activationCode; SmtpClient Smtp = new SmtpClient("smtp.xxxxxx.it"); Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; Smtp.EnableSsl = true; Smtp.Send(Msg); Roles.AddUserToRole(CreateUserWizard1.UserName, "memberRegister"); member.Save(); } catch (Exception ex) { test.Text += ex.StackTrace; }

     

    and in the page load I used this. 

    protected void Page_Load(object sender, EventArgs e)
            {
    
                Label test = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("test");
    
                string username = Request.QueryString["user"];
                string aCode = Request.QueryString["ac"];
    
                if (username != null && username.Length > 0 && aCode != null && aCode.Length > 0)
                {
                    Member m = Member.GetMemberFromLoginName(username);
    
                    if (m != null)
                    {
                        string savedACode = (string)m.getProperty("activationCode").Value;
                        try
                        {
                            Guid aGuid = new Guid(aCode);
                            Guid savedAGuid = new Guid(savedACode);
    
                            if (aGuid.Equals(savedAGuid))
                            {
                                m.getProperty("active").Value = true;
                                m.Save();
                                test.Text = "Account has been activated.";
                            }
                            else
                            {
                                test.Text = "No account could be found to activate with the data given.";
                            }
                        }
                        catch
                        {
                            test.Text = "No account could be found to activate with the data given.";
                        }
                    }
                    else
                        test.Text = "No account could be found to activate with the data given.";
                }
                else
                {
                    test.Text = "No account could be found to activate with the data given.";
                }
            }

     

    Correct?

     

    Unfortunately, the mail does not arrive: (. web.confg I have configured in the SMTP server, but need not be the same. Anyway. I added two properties in members: active (true / false) and activationCode (textString). You is created but not exploited the two properties. Why? Also, I did override the ValidateUser works, but in addition to failing to understand how it works, it should be in the loop and Application Pool drop down. This is the code I have used:

    public class CustomMemberShipProvider : umbraco.providers.members.UmbracoMembershipProvider
        {
            public override bool ValidateUser(string username, string password)
            {
    
    
                string encodedPassword = EncodePassword(password);
                umbraco.cms.businesslogic.member.Member m = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginAndEncodedPassword(username, encodedPassword);
    
                //umbraco.cms.businesslogic.member.Member m = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginNameAndPassword(username, EncodePassword(password));
    
                if (m == null)
                {
                    return false;
                }
                else
                {
                    try
                    {
                        if (m.getProperty("active").Value.ToString() == "1")
                        {
                            return false;
                        }
                        else
                        {
                            return true;
                        }
    
                    }
                    catch
                    {
                        return false;
                    }
    
                }
                //return (m != null);
            }
        }

     

    I used the version greater than 4.0.2 and unfortunately does not support this procedure. There are others?

    Thanks in advanced!

    Regards.

    G.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 18, 2011 @ 20:17
    Tom Fulton
    0

    Hi,

    You shouldn't need to override the ValidateUser to support the "active" bit.  In the web.config you can specify the properties to use, ie: umbracoApprovePropertyTypeAlias="isApproved" and umbracoLockPropertyTypeAlias="isLocked".

    If you haven't seen this already, there is a very good 3 part blog post that should help you, it takes you through all the steps needed for "Authenticating new members before activating them":  http://umbraco.miketaylor.eu/2010/08/29/authenticating-new-members/

    -Tom

  • Giacomo Cosenza 16 posts 36 karma points
    Apr 19, 2011 @ 09:53
    Giacomo Cosenza
    0

    Thanks Tom!

    I think what I was looking for. Try it now!

    G.

  • Giacomo Cosenza 16 posts 36 karma points
    Apr 19, 2011 @ 13:13
    Giacomo Cosenza
    0

    Hi tom,

    I've problem with the web.config.

    I add this section in the <system.web>

    <profile
            defaultProvider="UmbracoMemberProfileProvider" 
            enabled="true" 
            inherits="customMemberProfile.MemberProfile, customMemberProfile"
            >
          <providers>
            <clear />
            <add 
                name="UmbracoMemberProfileProvider" 
                type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
          </providers>
    
          <properties>
            <clear />
    
            <add name="authGuid" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="firstName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="lastName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="company" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="address" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="fax" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="province" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="cap" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="phone" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="email" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
            <add name="webSite" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
          </properties>
        </profile>

     

    The page return this error: 

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

    Parser Error Message: This profile property has already been defined.

    Source Error: 

    Line 192:        <clear />
    Line 193:        
    Line 194:        <add name="authGuid" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
    Line 195:        <add name="firstName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
    Line 196:        <add name="lastName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />

    Source File: C:\inetpub\wwwroot\build\web.config    Line: 194 

    Why? In the web.config the property profile is set only once.

    Thanks in advace,

    Regards.

    G.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 19, 2011 @ 15:19
    Tom Fulton
    0

    I think you can't name the properties the same that they are named on the Profile Class.  For example, if the property on the profile class is "AuthGuid" you should make the property in web.config and your Member Profile class different, maybe prefix them with an 'm'.  See the comment on Aaron's blog post:

     

    For the "property already defined" error, I was getting this when I was trying to set the umbraco profile alias to be the same as the property on the MemberProfile (upper/lower case didn't matter.) Once I had them as completely different strings it worked. This also works well for saving back to the member profile like this:

    ((MemberProfile)HttpContext.Current.Profile).FirstName = txtFirstName.Text;
    ((MemberProfile)HttpContext.Current.Profile).Save();

    -Tom

  • adarsh 46 posts 66 karma points
    Jul 05, 2011 @ 12:49
    adarsh
    0

    hii need your guidance in creating registration form for user.

    i used the createuserwizard from visual studio, its work fine i can create user and my problem if user allready exits, i need to show error message like user allready exits please try with other user anme .

     

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jul 05, 2011 @ 13:44
    Michael Latouche
    0

    Hi adarsh,

    I thought the error would be built in, but apparently not. What you can do, I think, is register the CreateUserError event, and there you can deal with the error type. You could then output the error message to, let say, an error "label", or some javascript alert or whatever. For example:

    void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e)
    {
         if (e.CreateUserError == System.Web.Security.MembershipCreateStatus.DuplicateUserName)
            LabelError.Text = "duplicate user name";
    }

    Hopt this helps.

    Cheers,

    Michael.

  • adarsh 46 posts 66 karma points
    Jul 05, 2011 @ 15:04
    adarsh
    0

    hi Michael

    Thanks for reply, i tired createuserwizard1_createusererro but not sucessfull.

    its does not show any messages.

    so now iam trying with custome login its works fine now i am stuck with authenticate email, sending mail to user to activate the account..

    adarsh

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jul 05, 2011 @ 15:44
    Michael Latouche
    0

    Hi adarsh,

    Strange that you don't get anything. Maybe it is another error you are getting? Did you try to debug and see what error code you got? Also, do not forget to register the event on the control, somewhere in the Load or Init:

    CreateUserWizard1.CreateUserError += CreateUserWizard1_CreateUserError

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft