Copied to clipboard

Flag this post as spam?

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


  • Chris Hill 14 posts 114 karma points
    Oct 02, 2017 @ 20:06
    Chris Hill
    0

    I followed this article to try and get a login form to protect some areas of my site - the login form appears when I try and access the nodes that I set to be protected via role based protection, but when I enter the correct username and password the form is just redisplayed and I don't appear to be logged in. The form does however seem to react to incorrect login details.

    Obviously I want to proceed to the content that I had selected - please help!

  • Chris Hill 14 posts 114 karma points
    Oct 04, 2017 @ 16:41
    Chris Hill
    0

    I have added the following code onto my login Partial Macro :

    @loginStatusModel.IsLoggedIn.ToString()

    And it always shows False.

    Entering an incorrect username and password fails the validation, entering a correct username and password just bounces back to the login page and shows that value of false.

    How / where do I debug this?

  • Nigel Wilson 944 posts 2076 karma points
    Oct 04, 2017 @ 19:11
    Nigel Wilson
    0

    Hi Chris

    Are you using Visual Studio?

    If so, then you can put break points in the controller code to step your way through.

    If not then maybe post your code on here so someone can assist.

    Cheers, Nigel

  • Chris Hill 14 posts 114 karma points
    Oct 04, 2017 @ 20:08
    Chris Hill
    0

    Hi Nigel - thanks for the reply.

    I'm not as I just did an install of Umbraco via the IIS Web Platform Installer and have been adapting it via the Umbraco interface. Can I just pull all the files down in VS and run it locally? Is this firing back to a controller?

    The code in the partial macro is (sorry can't get it to format quite right) :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc @using Umbraco.Web @using Umbraco.Web.Models @using Umbraco.Web.Controllers

    @{ // You have to set the login node ID otherwise you'll have an infinite loop if someone hits the login page first var loginNodeID = 1519; var loginModel = new LoginModel(); var loginStatusModel = Members.GetCurrentLoginStatus();

    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
    Html.RequiresJs("/umbraco_client/ui/jquery.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    

    }

    @* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@ @Html.RenderJsHere()

    @{ var checkUrl = HttpContext.Current.Request.Url.AbsolutePath.ToString();

    // add a trailing / if there isn't one (you can access http://mydomain.com/login or http://mydomain.com/login/
    if (@checkUrl[checkUrl.Length -1] != '/') {
        checkUrl = checkUrl + "/";
    }
    
    @* if we don't have a session variable and have a request URL then store it *@
    @* we have to store it because if user tries an incorrect login then Current.Request.Url will show /umbraco/RenderMvc *@
    if (HttpContext.Current.Request.Url != null && HttpContext.Current.Request.Url.AbsolutePath.ToString() != "/umbraco/RenderMvc" && HttpContext.Current.Session["redirectURL"] == null) {
        if (checkUrl !=  @Umbraco.Content(loginNodeID).Url) {
            HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
        }
    }
    
    if (loginStatusModel.IsLoggedIn)
    {
        var redirectUrl = (string)HttpContext.Current.Session["redirectURL"];
    
        var currentUrl = HttpContext.Current.Request.Url.ToString();
        if (HttpContext.Current.Session["redirectURL"] != null) {
            // clear the session variable for future logins
            HttpContext.Current.Session["redirectURL"] = null;
            HttpContext.Current.Response.Redirect(redirectUrl);
        }
        else {
            // Nothing in the session so we will go home 
            HttpContext.Current.Response.Redirect("/");
        }
    }
    
    @loginStatusModel.IsLoggedIn.ToString()
    
    using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
    {
        <fieldset>
            <legend>Login</legend>
    
            @Html.ValidationSummary("loginModel", true)
    
            @Html.LabelFor(m => loginModel.Username)
            @Html.TextBoxFor(m => loginModel.Username)
            @Html.ValidationMessageFor(m => loginModel.Username)
            <br />
    
            @Html.LabelFor(m => loginModel.Password)
            @Html.PasswordFor(m => loginModel.Password)
            @Html.ValidationMessageFor(m => loginModel.Password)
            <br />
    
            <button>Login</button>
        </fieldset>  
    }
    

    }

  • Nigel Wilson 944 posts 2076 karma points
    Oct 05, 2017 @ 01:19
    Nigel Wilson
    0

    Hi Chris

    If you pull the code down and open the site in Visual Studio, you might be able to then run in debug mode - not 100% sure to be honest.

    However in your partial macro file (if running in debug mode) you will be able to set break points and step through the code to try and determine what's happening / not happening.

    If I get a chance over the next day I'll try and replicate on a test website and provide an update.

    Cheers, Nigel

  • Nigel Wilson 944 posts 2076 karma points
    Oct 05, 2017 @ 18:17
    Nigel Wilson
    0

    Hi Chris

    So I have run a test as follows:spun up a test site and worked through the tutorial.

    1. Created a test site using a starter kit
    2. Created a login page within the site
    3. Created the macro as per the tutorial - copy / pasted the code and updated the node ID for the login page.
    4. Created a member group
    5. Created a member and assigned the group to them
    6. Updated the "public access" on the "contact" page within the site - assigned the member group, selected the login page, and selected the home page for the "Error Page" (not really an issue for the purposes of this test)

    I then browsed to the "contact" page and got the login page and after logging in got redirected to the contact page.

    By starting a new session, browsing to the login page and logging in, you are redirected to the home page, which is expected behaviour in the code.

    So effectively the tutorial worked as expected for me, so I wonder if there might be something in the above steps / setup that you have implemented differently.

    Hope this helps.

    Cheers Nigel

  • Chris Hill 14 posts 114 karma points
    Oct 06, 2017 @ 09:56
    Chris Hill
    0

    Nigel

    Regarding this line :

    @* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@ @Html.RenderJsHere()

    Did you do anything with that - it's still in my Partial macro but reading it, it seems to suggest to put in Layout - I have tried that and got an error, but I can't see with it just in my macro that the JQuery stuff is in the page source.

  • Chris Hill 14 posts 114 karma points
    Oct 06, 2017 @ 08:07
    Chris Hill
    0

    Wow thanks Nigel for going to all that trouble.

    I think I followed all those steps correctly - the Login page is just a normal page / doc type with the partial macro inserted isn't it?

    Did you do this all in VS? As I say I did install Umbraco via the IIS Web Platform Installer which I presume gives me compiled code rather than the source code for me to publish myself?

    I have made a lot of changes to the code direct in the interface, and also put a lot of content in it - if I need to reverse engineer that back out into a fresh site in VS is that doable? I can't debug it as is so I can't even see where my login page is firing off to, to check that something is actually happening in the background.

  • Chris Hill 14 posts 114 karma points
    Oct 06, 2017 @ 10:16
    Chris Hill
    100

    Ahhhhh - found it - Forms Authentication wasn't enabled for the site....

    Thanks again for all your help!

  • Nigel Wilson 944 posts 2076 karma points
    Oct 06, 2017 @ 17:00
    Nigel Wilson
    0

    Hi Chris

    Pleased you've worked it out/

    Cheers Nigel

Please Sign in or register to post replies

Write your reply to:

Draft