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
    Oct 02, 2014 @ 14:51
    krisek
    0

    Redirect after login

    Hello,

    how can I redirect user to certain page after the login process is successful ?

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 14:56
    Marcio Goularte
    1

    Hi Krisek,

    WebForms or MVC?


  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 14:57
    krisek
    0

    MVC, sorry

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 15:04
    Marcio Goularte
    1

    Use it in the return of action:

    return Redirect("url"); 

    This site has a great example

    http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller/


  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 15:11
    krisek
    0

    wait...where should I use it>? I have asp.net mvc background so I understand that this should go to controllers...but I don't have any controllers :/ this is my project (after downloading it)

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 15:16
    Marcio Goularte
    1

    Krisek,

    I always create a Controller class in App_Code . In this folder you can create by following the example of 24days site.

  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 15:18
    krisek
    0

    Okay, so step by step. 

    I totally didn't understand this:ple of 24days site what did you meant?

    So in App_Code I can create my own controller. thats good, I assume that this controller will inherit from SurfaceController-correct? 

    So what should I write there to connect my existing Login page?

    Or maybe I should create a new one?

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 15:31
    Marcio Goularte
    0

    I meant the website link.

    Yes. Their Controller must inherit the SurfaceController

    You can use the helper to create your form in the view or partial . @Html.BeginUmbracoForm<MySurfaceController>(...)

    what version of umbraco ?

  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 15:33
    krisek
    0

    the latest one which u can download. 7 something i think. 

    Look, I will go through this website u send me the link and if I step on any problem i will post here :)

    I'm not sure: i will add the controller+views +models (through the visual studio) and the will simply come up in the admin panel in web browser?>

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 15:50
    Marcio Goularte
    1

    ok. You can create your views and partials in visual studio that will appear in the admin panel (Back-Office). Except controller and models, only in visual studio. Any questions post here.

    regards!

  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 17:04
    krisek
    0

    I did as the tutorial was saying, but in my backend I don't see the new View (LoginMember in Partial folder).

    Where should I add this: @Html.Action("MemberLogin","MemberLoginSurface") ?

     that line of code i put into Master template, then I tried to put it into some other template. I'm getting this error:

    then I moved the controller from folder App_Code to "Controllers" (i created that folder) and this is the error:

     

     

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 18:33
    Marcio Goularte
    0

    Hi,

    what is the name of the controller?

    you created a partial?

    I do not understand why you're calling a  @Html.Action.

    Please, paste here the code of model , view and controller.

  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 18:39
    krisek
    0

    I did this tutorial: http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller/

    so the model:

    public class MemberLoginModel
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public bool RememberMe { get; set; }
    }

    controller:

    using System.Web.Mvc;
    using System.Web.Security;
    using Umbraco.Web.Mvc;
    
    [PluginController("CLC")]
    public class MemberLoginSurfaceController : SurfaceController
    {
        [HttpGet]
        [ActionName("MemberLogin")]
        public ActionResult MemberLoginGet()
        {
            return View("MemberLogin", new MemberLoginModel());
        }
    
        [HttpGet]
        public ActionResult MemberLogout()
        {
            Session.Clear();
            FormsAuthentication.SignOut();
            return Redirect("/");
        }
    
        [System.Web.Http.HttpPost]
        [System.Web.Http.ActionName("MemberLogin")]
        public ActionResult MemberLoginPost(MemberLoginModel model)
        {
            if (Membership.ValidateUser(model.Username, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                return RedirectToCurrentUmbracoPage();
            }
    
            TempData["Status"] = "Invalid username or password";
            return RedirectToCurrentUmbracoPage();        
        }
    }
    
    view (Views/Partials/)
     Umbraco.Web.Mvc.UmbracoTemplatePage 
    @model MemberLoginModel
    @{
        Layout = "Master.cshtml";
    }
    <hr/>
    This is the new login page
    
    @if (User.Identity.IsAuthenticated)
    {
        <p>Logged in: @User.Identity.Name</p>
        <p>@Html.ActionLink("Log out", "MemberLogout", "MemberLoginSurface")</p>
    }
    else
    {
        using (Html.BeginUmbracoForm("MemberLogin", "MemberLoginSurface"))
        {
            @Html.EditorFor(x => Model)
            <input type="submit" />
        }
    
        <p>@TempData["Status"]</p>
    }   
    
    <hr/>
  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 18:53
    Marcio Goularte
    100

    In the code the return of Action MemberLogin is a type View. Change so.

    return PartialView("MemberLogin", new MemberLoginModel());

     

  • krisek 16 posts 103 karma points
    Oct 02, 2014 @ 19:00
    krisek
    1

    Okay that looks promising, tell me please where should I call it and how? 

    for example let's say that I want to create from the backend admin panel a new content site and use it there 

  • Marcio Goularte 388 posts 1360 karma points
    Oct 02, 2014 @ 19:21
    Marcio Goularte
    0

    Will depend on the structure of your site . You can create a DocumentType for Login and create your content named login. The template for login has this code:
    @Html.Action("MemberLogin","MemberLoginSurface") 

  • krisek 16 posts 103 karma points
    Oct 06, 2014 @ 11:23
    krisek
    0

    Hi, added a new document and I pased there the line you showed and I'm still getting the error "

    Server Error in '/' Application.


    No route in the route table matches the supplied values.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: No route in the route table matches the supplied values.

    Source Error: 

    Line 1:  This is member login page

    Line 2: @Html.Action("MemberLogin","MemberLoginSurface") 

     

    Should I "tell" Umbraco that I created a new controller and he should be aware of it? Or its automatically done?

  • krisek 16 posts 103 karma points
    Oct 06, 2014 @ 12:38
    krisek
    0

    I started the project again, from scratch and now its working fine :( 

    don't know the issue, but thanks for the whole help! :)

  • Marcio Goularte 388 posts 1360 karma points
    Oct 06, 2014 @ 13:46
    Marcio Goularte
    0

    There is an alternative which is simpler but works well . You create a script file and use this code https://gist.github.com/joeriks/874194 as a macro.

     

    regards!

  • krisek 16 posts 103 karma points
    Oct 06, 2014 @ 13:49
    krisek
    0

    Now I have different problem. 

    1. First of all I did this:

     [HttpPost]
            public ActionResult Login(LoginModelView model)
            {
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, true);
    
                    var roles = System.Web.Security.Roles.GetRolesForUser();
                    var cur = UmbracoContext.Security.CurrentUser;
    
    both the roles and cur are null.... (of course the user exists and its validated properly). 
    Generally what now I want to do:
    I will have 2 master pages: A and B. 
    Page A belongs to Agroup
    Page B belongs to Bgroup. 
    When user logs in, I want to redirect him to the master page that he belongs to, for example the user A, from GroupA redirects to Page A. How can I achieve that?
    Second Issue:
    In POST of Login funtionality I have this:
    [HttpPost]
            public ActionResult Login(LoginModelView model)
            {
                if (Membership.ValidateUser(model.Username, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Username, true);
    
                    var roles = System.Web.Security.Roles.GetRolesForUser();
                    var cur = UmbracoContext.Security.CurrentUser;
    
                    return RedirectToCurrentUmbracoPage();
    
                }
    
                TempData["Status"] = "Invalid username or password";
                return RedirectToCurrentUmbracoPage();
            }
    
    when I'm calling this from view, I have an error saying: 

    Cannot redirect from a Child Action

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: Cannot redirect from a Child Action

    Source Error: 

    Line 3:      Layout = "umbLayout.cshtml";
    Line 4:  }
    Line 5: @Html.Action("Login","AccountSurface")


    How can I solve this?
Please Sign in or register to post replies

Write your reply to:

Draft