Copied to clipboard

Flag this post as spam?

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


  • adarsh 46 posts 66 karma points
    Jul 05, 2011 @ 10:19
    adarsh
    0

    Registration page for user?

    i just followed the mike blog of authenticating new members before activating them? the url is

    http://umbraco.miketaylor.eu/2010/08/29/ its work fine and my only query is how i can check the if user is allready exits and again he want to enter registration form i need to display the message user is allready exits.

    iam using the above code to save in the database and send a link to the user to activate. its work fine. but i how to check if user is allready registered. what i need to modify in code.

     protected void cwMember_CreatedUser(object sender, EventArgs e)
    {

    try
    {
    CreateUserWizard cuw = (CreateUserWizard)sender;
    MembershipUser user = Membership.GetUser(cuw.UserName);
    if (user != null)
    {
    string newUserGuid = System.Guid.NewGuid().ToString("N");
    MemberProfile me = MemberProfile.GetUserProfile(cuw.UserName);

    me.AuthGuid = newUserGuid;
    me.FirstName = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
    me.MiddleName = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("MiddleName")).Text;
    me.LastName = ((TextBox)cuw.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;
    me.Save();
    Roles.AddUserToRole(cuw.UserName, "SiteMembers ");
    HyperLink hlAuth = (HyperLink)cuw.CompleteStep.ContentTemplateContainer.FindControl("hlAuth");
    if (hlAuth != null)
    {
    hlAuth.NavigateUrl = "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ApplicationPath.TrimEnd('/') + "/authenticate.aspx?a=" + user.UserName + "&b=" + newUserGuid;

    hlAuth.Text = hlAuth.NavigateUrl;
    }
    }
    }
    catch (Exception ex)
    {
    Literal1.Text = ex.StackTrace;

    }

     

    its works like a charm and i dont how to check if the user is allready exits in that case i need to display a message user is allready registered.

     

  • Javier Barrera 34 posts 85 karma points
    Jul 06, 2011 @ 00:41
    Javier Barrera
    0

    I would check for a user account by using the .NET membership library located in using System.Web.Security; Also, I have code for adding custom properties to the Umbraco Membership backend in this code. Please note that I do have some custom code in there, such as Message.Add(), which is part of a website library that I created to show messages to the end user on the site (not the backend).

       protected bool createUserAccount()
    {
    if (Membership.GetUser(txtEmailAddress.Text) == null)
    {
    MembershipCreateStatus status;

    try
    {
    MembershipUser user = Membership.CreateUser(txtEmailAddress.Text,
    txtPassword.Text,
    txtEmailAddress.Text,
    System.Configuration.ConfigurationManager.AppSettings["PasswordRecoveryQuestion"],
    System.Configuration.ConfigurationManager.AppSettings["PasswordRecoveryAnswer"],
    true,
    out status);

    if (status == MembershipCreateStatus.Success)
    {
    try
    {
    // Add Umbraco Properties
    Member member = Member.GetMemberFromEmail(txtEmailAddress.Text);

    if (member != null || member.Id > 0)
    {
    member.Text = txtFirstName.Text + " " + txtLastName.Text;
    member.getProperty("firstName").Value = txtFirstName.Text;
    member.getProperty("lastName").Value = txtLastName.Text;
    member.getProperty("company").Value = txtCompany.Text;
    member.Save();
    }

    return true;
    }
    catch (Exception err)
    {
    Message.Add(err.ToString(), MessageType.Bad, 10000);
    return false;
    }
    }
    else
    {
    Message.Add("The user account could not be created. " + status.ToString(), MessageType.Bad, 10000);
    return false;
    }
    }
    catch (Exception err)
    {
    Message.Add(err.Message, MessageType.Bad, 10000);
    return false;
    }
    }
    else
    {
    Message.Add("The e-mail address you entered is already in use. Please use another e-mail address.", MessageType.Bad, 10000);
    return false;
    }
    }

    Also, the following Is depreciated, but continues to work. I'm not sure of the alternate to do this.

    Member.GetMemberFromEmail()

     

  • adarsh 46 posts 66 karma points
    Jul 06, 2011 @ 16:14
    adarsh
    0

    hi Javier Barrera

    sorry for late reply, thanks i did the same way. it work finally.

    Adarsh

    cheers!!

     

Please Sign in or register to post replies

Write your reply to:

Draft