This project is read-only.

weird code ?!

Jun 30, 2009 at 12:18 PM
Edited Jun 30, 2009 at 1:51 PM

There is something weird in the code of the following method (BaseController.cs)

 public bool  IsCurrentUserAuthenticated
{
      get 
      {
                if (HttpContext.User.Identity.IsAuthenticated && (CurrentUser != null))
               {
                     if (!CurrentUser.IsLockedOut)
                    {
                          return true;
                     }

                  Log.Warning("Logging out User: {0}", CurrentUserName);
                 // Logout the user if the account is locked out
                FormsAuthentication.SignOut();
                Log.Info("User Logged out.");
             }
            return false;
}


unless it is misnommed it should be as simple as


public bool IsUserAuthenticated
{
    get
    {
           return  HttpContext.User.Identity.IsAuthenticated;
    }
}

Jun 30, 2009 at 3:40 PM

It appears to be a refactoring to prevent that code from being duplicated wherever IsAuthenticated and !IsLockedOut checks need to occur. Perhaps it should be renamed to something like IsCurrentUserValid?

Jul 1, 2009 at 7:25 PM

To be a valid user you do no have to be connected and authenticated
No, I am more surprised by he fact the user is logout in this code
 IMHO, this subroutine should be limited to

return (HttpContext.User.Identity.IsAuthenticated && (CurrentUser != null) );

 

Jul 1, 2009 at 10:38 PM

Where would you recommend checking if the user is locked out? It would seem to me that you should check if they've been locked out anytime you check if they're authenticated. If the user is locked out while logged in, the person is no longer a valid user and should be logged off.

Jul 1, 2009 at 11:11 PM

In the case where a user is lockout while he is still connected and authenticated, I would let the action that locked him out to log him out too.

I am quite sure there is a good reason behind this code because this project is very clean and very well thought out


I am always wondering how long did them to produce it