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?
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");
}
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");
}
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
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
}
Use Umbraco member
code of Jivan is better :)
regards
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
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
Just a quick update peeps. The solution given by Jivan above worked a treat :) thank you
is working on a reply...