Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Aug 19, 2010 @ 00:11
    Eddie Foreman
    0

    Login only approved members

    Hi All

    I've followed the great article http://www.nibble.be/?p=66, as I would like to disable member logins until they've been approved.  The member type has a check property with an alias of approved. The approach used in the article, does not appear to work in Umbraco versions of 4.0.2 or greater.

    I'm using Umbraco version v 4.0.4.2 and the ASP.Net LoginContorls.  And was wondering if and how I can achieve a similair thing?

    ...
    public class CustomMemberShipProvide :UmbracoMembershipProvider
    {
    public override bool ValidateUser(string username, string password)
    {
    string encodedPassword = EncodePassword(password);
    Member currentMember = Member.GetMemberFromLoginAndEncodedPassword(username, encodedPassword);
    if (currentMember == null)
    {
    return false;
    }
    else {
    try {
    if (currentMember.getProperty("approved").ToString() == "1")
    {
    return true;
    }else{
    return false;
    }
    }catch{
    return false;
    }
    }
    //also intellisense is stating this code is never reached???
    return (currentMember != null);
    }

    }
    ...

    Any thoughts or ideas would be greatly appreciated

    Thanks

    Eddie

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 19, 2010 @ 00:34
  • Eddie Foreman 215 posts 288 karma points
    Aug 19, 2010 @ 11:52
    Eddie Foreman
    0

    Hi Slace

    Thanks, tried the alternative method (http://our.umbraco.org/wiki/how-tos/membership-providers/check-if-user-is-active-before-logging-in/alternative-method-for-checking-active-membership).

    Which works when the correct username and password are entered.  When either the username or password is entered incorrectly i get a server application error  - Object reference not set to an instance of an object.

    Code from class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco.cms.businesslogic.member;

    namespace LoginForm
    {
    public partial class LoginForm : System.Web.UI.UserControl
    {
    protected void CheckMemberStatus(object sender, LoginCancelEventArgs e)
    {
    Member m = Member.GetMemberFromLoginNameAndPassword(login.UserName, login.Password);
    if (m.getProperty("memberStatus").Value.ToString() != "22")
    {
    e.Cancel = true;
    login.FailureText = "Your Member account is not yet active...";
    }
    }

    protected void LoggedIn(object sender, EventArgs e)
    {
    if(Request.IsAuthenticated){
    login.Visible = false;
    }
    }
    }
    }

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
    LoginForm.LoginForm.CheckMemberStatus(Object sender, LoginCancelEventArgs e) +103
    System.Web.UI.WebControls.Login.OnLoggingIn(LoginCancelEventArgs e) +108
    System.Web.UI.WebControls.Login.AttemptLogin() +76
    System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
    System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +111
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Any thoughts

    Thanks

    Eddie

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 19, 2010 @ 12:05
    Aaron Powell
    0

    Make sure that there is a value in the property you're trying to check.

  • Eddie Foreman 215 posts 288 karma points
    Aug 19, 2010 @ 12:41
    Eddie Foreman
    0

    Hi Slace

    When entering an incorrect username or password, the member does not exist.  So wrapping an if statement around the getProperty(...) seems to have done the trick.

                ...
    if (m != null) {
    if (m.getProperty("memberStatus").Value.ToString() != "22")
    {
    e.Cancel = true;
    login.FailureText = "Your Member account is not yet active...";
    }
    }
    ...

    Thanks for your help

    Eddie

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 19, 2010 @ 15:14
    Aaron Powell
    0

    I'd also check that m.getProperty(...).Value != null, unless you're unit tests ensure that you could never reach that state.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies