Copied to clipboard

Flag this post as spam?

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


  • krisek 16 posts 103 karma points
    Sep 30, 2014 @ 11:37
    krisek
    0

    After login redirect to other page

    Hello,

    I have read some posts regarding my problem but could really solve the problem. 

    So, I created a Login page (in its properties i chose "Login" template). In templates I have this Login template here is the code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "umbLayout.cshtml";
    }
    
    
    <div id="main-wrapper">
        <div id="main" class="container">
            <div class="row">
                <div class="9u skel-cell-mainContent">
                    <div class="content content-left">
                        <!-- Content -->
                        <article class="is-page-content">
                           @Html.Partial("Login")                          
                        </article>
                        <!-- /Content -->
                    </div>
                </div>
                <div class="3u">
                    <div class="sidebar">
                        <!-- Sidebar -->
                        @{ Html.RenderPartial("umbLatestNewsWidget"); }
                        <!-- /Sidebar -->
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="12u">
                    @{ Html.RenderPartial("umbFeatures"); }
                </div>
            </div>
        </div>
    </div>
    <!-- /Main -->    

    a then I have a partial view "Login", code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Models
    @using Umbraco.Web.Controllers
    
    @{
        var loginModel = new LoginModel();
    
        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()
    
    @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>  
    }

    I can see that page after I run the application, but can someone tell me after succesfull login how can I redirect the user to other page? Now when I login it stays on the same page :/

    Thank you, 

    Christopher

     

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Sep 30, 2014 @ 17:26
    Steve Morgan
    1

    Hi Christopher,

    You need to store the page requested in a session variable and redirect them to the page - I do something similar in a blog post here 

    http://siempresolutions.co.uk/blog/Umbraco_Members_Protected_Area_of_Website  

    Have a look at the razor code on there.

    HTH 


    Steve

     

     

     

     

     

     

     

     

  • krisek 16 posts 103 karma points
    Sep 30, 2014 @ 17:46
    krisek
    0

    Thank you for your answer, the article is written very poorly. It's not clear what and how to achieve each step. For example part 2.1:

    "Allow the homepage to be created at the root and the others to be legitimate children. Then create a Master template, update all of the other templates to be children of this and add the Initialzr template code to the master with a @RenderBody and something relevant in the child templates"

    For me this is totally not clear. 

    Apart from that I still don't understand how all Umbraco works... As I understand this for now is: umbraco is a .NET system which allows to create websites (blogs, etc) from scratch by coding through the browser. It's not like Wordpress that you can only do whats in the admin panel. Umbraco is much more abstract. Correct?

     

     And still wondering how to achieve the redirect. 

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Sep 30, 2014 @ 18:06
    Steve Morgan
    100

    Sorry to hear it's poorly written - I wrote it :( 

    There is a definite learning curve to Umbraco - I suspect one of the failings of my blog post is that it uses the Umbraco terminology expecting you to understand it already! That will be the case for most of the documentation you're likely to find here (if not worse). Out of the box Umbraco is an empty shell - as opposed to Wordpress which is a blogging engine out of the box (because that's what it is). When you learn how to use Umbraco you'll see that implementing a blog is a simple razor script in Umbraco with two or three document types and templates (an hour job at most!) but you're not just limited to that blog.... 

    If you've jumped straight in and started trying to create a members only section without an understanding of "templates" and "document types" then I can see how you'd be confused. :) 

    If I may, I'd recommend you take an hour to step through this tutorial (which I wrote with great help from Jeavon on this forum). 

    http://our.umbraco.org/documentation/Using-Umbraco/Creating-Basic-Site/

    My blog post is referring to the same template that is used in that tutorial. It would be best to take a fresh install of Umbraco and leave what you've started and come back to it after.  Follow that tutorial and then my blog post - that would create you a basic site with a members area. Hopefully then you can take those concepts and apply it to your own site (and you'll also be "speaking" fluent Umbraco!). 

    I promise you'll also never look at Wordpress again and I speak as a PHP developer :) I'd really appreciate any feedback on that documentation - if there is anything we can do to make it better let me know.

    Good luck!

    Steve

     

  • krisek 16 posts 103 karma points
    Oct 01, 2014 @ 13:26
    krisek
    0

    I went again through the link and then back to your article. Everything is working fine! 

    All because of my stupidity  :)

     

    But the next question is: whats next... how to handle everything I need, for example how to hide a link if user is logged in but is NOT a member of certain group?

    For example: I will have 2 users in 2 groups: UserA in GroupA and UserB in GroupB: how to make the redirects after they log in: UserA loggs in and he is redirected to MySiteA, UserB loggs in and he is redirected to MySiteB...how to do the redirect?


    And second question: i have a menu like that in my master:

                <nav>
                <ul>
                        <li><a href="/open">Open</a></li>
           <li><a href="/protected">Protected</a></li>
    <li><a href="/protectedother">Protected other</a></li>
    <li><a href="/register">Register</a></li>
                    </ul>
                </nav>

           

    how can I show the links based on Role the user is in ? 

    For example for UserA i want to show the "Protected" link and hide the "Protected other" link. 

     

     

     

     

     

     

     

  • Oscar Svedberg 19 posts 82 karma points
    Jan 30, 2015 @ 00:09
    Oscar Svedberg
    0

    Not sure if this is super old and no longer interesting, but just for the heck of it I thought I'd add a little something i did on this solution.

    I really didn't want to add the Node ID for my login page in code like so:

    var loginNodeID = 1056;
    
    if (checkUrl !=  @Umbraco.Content(loginNodeID).Url) {
            HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
    }
    

    So instead I did the following check, which works like a charm:

    if (this.CurrentPage.Url != Request.RawUrl)
    {
        HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
    }
    

    CurrentPage is the Login-page where I'm rendering my Login macro, and the Request.RawUrl gives me the url to the page where I'm trying to navigate.

Please Sign in or register to post replies

Write your reply to:

Draft