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();
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?
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".
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" />
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:
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 .
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"; }
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:
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:
and in the page load I used this.
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:
Thanks in advanced!
Regards.
G.
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
Thanks Tom!
I think what I was looking for. Try it now!
G.
Hi tom,
I've problem with the web.config.
I add this section in the <system.web>
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.
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:
-Tom
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 .
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:
Hopt this helps.
Cheers,
Michael.
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
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.
is working on a reply...