Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Feb 07, 2014 @ 20:17
    Paul Griffiths
    0

    Checking if username exists from current members

    Hi all,

    Im really hoping someone can help me please. Im fairly new to this so please be gentle.

    I have built a .Net user control that allows a user to register to the website but how can I check whether the username that the user checks is already taken by an existing member?

    I have been search around for a solution for hours but so far no Luck, so any feedback would be great. Ive come across this but tried implementing it with no luck http://encosia.com/aspnet-username-availability-checking-via-ajax/.

    Im using umbraco 6.1.6

    Thanks

  • Marcio Goularte 388 posts 1360 karma points
    Feb 07, 2014 @ 20:34
    Marcio Goularte
    0

    Hi Paul,

    Try this:

    var member  =  Membership.GetUser(username);

    if (member  != null)  {  

    //member exists

     }  else {

      //member does not exist

     }

    Or Umbraco API:

    using umbraco.cms.businesslogic.member

    var member  = Member.GetMemberFromLoginName(loginName);

    or

     var member =  Member.GetMemberFromEmail(email);

    if (member  != null)  {  

    //member  exists

     }  else {

      //member  does not exist

     }

  • jivan thapa 194 posts 681 karma points
    Feb 07, 2014 @ 20:38
    jivan thapa
    1

    Use Umbraco member

    using umbraco.cms.businesslogic.member;
    
        if(Member.IsMember(string username))
        {
           // username is taken
        }
    
  • Marcio Goularte 388 posts 1360 karma points
    Feb 07, 2014 @ 20:43
    Marcio Goularte
    0

    code of Jivan is better :)

    regards

  • Paul Griffiths 370 posts 1021 karma points
    Feb 07, 2014 @ 21:32
    Paul Griffiths
    0

    Wow thanks for the quick responses guys very much appreciated. So let me just get this right. So my form looks like this (Shortened down slightly)

    Lbl name - txtName LblUsername - txtName LblPassword - txtPassword

    So I add the using umbraco.cms.businesslogic.member namespace

    And add the following code

    If (Member.IsMember(string username))

    { // username is taken

    }

    Or is it this code

    If (Member.IsMember(txtUsername.Text))

    { // username is taken

    }

    Sorry if that's an obvious question but im just trying to understand the solution as well as wanting to implement it. Thanks for your help

    Paul

  • jivan thapa 194 posts 681 karma points
    Feb 07, 2014 @ 21:46
    jivan thapa
    0
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.member;
    
    var userName = txtUsername.Text;
                    if (!Member.IsMember(userName))
                    {
    
                        // assume that you have created MemberType "NewMember" on Umbraco backoffice
                        Member.MakeNew(userName, MemberType.GetByAlias("newMember"), new User(0));
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("User id is taken, Please choose another Id");
                    }
    
  • jivan thapa 194 posts 681 karma points
    Feb 07, 2014 @ 21:51
    jivan thapa
    1
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.member;
    
    var userName = txtUsername.Text;
                    if (!Member.IsMember(userName))
                    {
    
                        // assume that you have created MemberType "NewMember" on Umbraco backoffice
                        Member.MakeNew(userName, MemberType.GetByAlias("newMember"), new User(0));
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("User id is taken, Please choose another Id");
                    }
    
  • Paul Griffiths 370 posts 1021 karma points
    Feb 08, 2014 @ 09:29
    Paul Griffiths
    0

    Hi Jivan,

    Thanks again for taking the time out to help me.

    I'm currently at work but will try your solution when I get home and see if it works :)

    Thanks

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Feb 10, 2014 @ 20:51
    Paul Griffiths
    0

    Just a quick update peeps. The solution given by Jivan above worked a treat :) thank you

Please Sign in or register to post replies

Write your reply to:

Draft