Copied to clipboard

Flag this post as spam?

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


  • bob baty-barr 1180 posts 1294 karma points MVP
    Nov 17, 2011 @ 15:59
    bob baty-barr
    0

    login form stopped showing up?

    i have a site where this was working fine, but now when users are presented witih protected content, it says they are logged in as [blank] and presented with the logout button... when the logout button is clicked, it basically just takes them to the login page... which is great... however, it still says they are logged in as blank...

    any thoughts???

    thanks,

  • Jonas Eriksson 930 posts 1825 karma points
    Nov 17, 2011 @ 16:40
    Jonas Eriksson
    0

    Hi Bob

    Hm, not sure, it's a very simple script, basically just using standard membership functions. Did it stop working at the same time as something else was installed/changed?

    Also - can you run ?umbdebugshowtrace=1 on the page and see if it says something on AUTH_USER or LOGON_USER ? 

  • bob baty-barr 1180 posts 1294 karma points MVP
    Nov 17, 2011 @ 16:44
    bob baty-barr
    0

    both those values show as blank?

    wierd... i will keep digging.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Nov 17, 2011 @ 17:50
    bob baty-barr
    1

    okay, so with the AWESOME help of Richard Soeteman [@rsoeteman on twitter send him a #H5YR] he pointed out that there could be an issue with a member NOT having an login name... still trying to figure out how that happened, but INDEED it DID happen...

    Richard provided me with an update to the razor login script and said it was perfectly fine for me to share... so here it is...

    @using System.Web  
    @using System.Web.Security
    @helper LoginForm()
    {
    }
    
    @helper LogoutForm()
    {
    }
    
    @helper Message(string message)
    {

    @message

    }
    
    @{
      var isSubmitLogin = (IsPost && Request["submit"]=="login");
      var isSubmitLogout = (IsPost && Request["submit"]=="logout");
      var currentUser = Membership.GetUser();
      var requestedUrl = Request.Url.PathAndQuery.ToString(); // Model.Url;
      if (Request["ReturnUrl"]!=null)
      {
        requestedUrl = Request["ReturnUrl"];
      }
    
      if (HttpContext.Current.User.Identity.IsAuthenticated)
       {    
        if (!isSubmitLogout)
         {
           @Message("Logged in : " + currentUser.UserName)
           @LogoutForm()
         }
        else
         {
           FormsAuthentication.SignOut();
           FormsAuthentication.RedirectToLoginPage();
         } 
       }
    
      if (!HttpContext.Current.User.Identity.IsAuthenticated)
       {
        if (!isSubmitLogin)  
         {
           @LoginForm()
          }
        else
         {
          string username=Request["username"];
          string password=Request["password"];
          if (Membership.ValidateUser(username, password))
          {
            // RedirectFromLoginPage does not work that good within the Umbraco context
            // FormsAuthentication.RedirectFromLoginPage(username, true);
    
            FormsAuthentication.SetAuthCookie(username, true);
    
            // Redirect to / refresh the requested page
            Response.Redirect(requestedUrl);
          }
          else
          {
            @Message("Login failed for " + username)
            @LoginForm()
          }
         }       
        }
      }
    
  • Jonas Eriksson 930 posts 1825 karma points
    Nov 17, 2011 @ 18:42
    Jonas Eriksson
    0

    +1 for the HttpContext.Current.User.Identity.IsAuthenticated, I'll replace and update the package (some other code style tweaks too).

    #h5yr to @rsoeteman :)

  • Jonas Eriksson 930 posts 1825 karma points
    Nov 17, 2011 @ 18:48
    Jonas Eriksson
    0

    But wait - did the blank username make the user to be automatically logged in? That's strange.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Nov 17, 2011 @ 18:50
    bob baty-barr
    0

    it apparently made some 'member' logged in.... but you could not log them out... basically put authentication in a death loop...

     

Please Sign in or register to post replies

Write your reply to:

Draft