Nibble

Archive for the 'member' Category


Only log in umbraco members when they have been approved 14

A common thing when dealing with members on your site is that they need to be approved after registration before they can access the protected area on your site.

This post describes a simple way of doing that.

On the umbraco member type I have a True/false property with the alias active. If this is set to true on the member he is an ‘active’ member and is allowed to log in.

activeproperty

 

The only thing that is needed is to override the ValidateUser method of the UmbracoMembershipProvider. So make a custom class, inherit from umbraco.providers.members.UmbracoMembershipProvider and override the method (make sure to reference umbraco.providers).

Instead of just checking if there is a member with the supplied loginname and password we’ll add some extra code that will check if the member has his active property set to true. If that is the case we return true, in all other cases we return false.

 

namespace Nibble
{
    public class CustomMemberShipProvider : umbraco.providers.members.UmbracoMembershipProvider
    {
        public override bool ValidateUser(string username, string password)
        {
            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 true;
                    }
                    else
                    {
                        return false;
                    }
 
                }
                catch
                {
                    return false;
                }
             
            }
            return (m != null);
        }
    }
}

 

Final step is to modify the web.config so that our custom membership provider is used instead of the default umbraco one. So Just change the type attribute on the umbraco membership provider to the type of the custom membership provider.

<add name=”UmbracoMembershipProvider” type=”Nibble.CustomMemberShipProvider”
 enablePasswordRetrieval=”false” enablePasswordReset=”false” requiresQuestionAndAnswer=”false”
 defaultMemberTypeAlias=”CobraMember” passwordFormat=”Hashed” />

 

That’s it, now the asp:login control will only login the member if he has his active property set to true.