Url.Action("LogOn") Custom Login Popup

Topics: Administration, Core, Customizing Orchard, General, Writing modules
Nov 7, 2014 at 9:36 AM
Edited Nov 7, 2014 at 9:41 AM
Hello,

i'm trying to write my custom login popup in my custom theme
i had some problems with implementation of it when my popup login form show there is nothing happen for redirecting or get loing authentication session how i can implement the correct method for this

here is parts of my related code

Layout.cshtml
@using Orchard.ContentManagement;

@{
    Style.Include("http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600,700&subset=latin,latin-ext");
    Style.Include("main.css");
    Style.Include("site.min.css");

    Script.Include("~/Core/Shapes/Scripts/html5.js").UseCondition("lt IE 9").AtHead();
    Script.Include("custom.js");
    Script.Include("isotope.pkgd.min.js");
    Script.Include("jquery.custombox.js");
    Script.Include("jquery.parallax-1.1.3.js");
    Script.Include("jquery.singlePageNav.min.js");
    Script.Include("mediaelement-and-player.min.js");
    Script.Include("respond.min.js");
    Script.Require("jQuery").AtHead();
    Script.Require("jQueryUI").AtHead();
    Script.Require("Bootstrap");


}
@functions {

    // To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.
    string CalcuClassify(string[] zoneNames, string classNamePrefix) {
        var zoneCounter = 0;
        var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : "";}).ToArray());
        return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
    }


}
@{
    //Display.Insertions();
    /* Some useful shortcuts or settings
    ***************************************************************/

    Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones
    var homeURL = "http://localhost:30321/OrchardLocal/";

    /* Last bit of code to prep the layout wrapper
    ***************************************************************/
    
    Model.Id = "wrapper";
    var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model
}

@tag.StartElement

@if (Request.Url.ToString().Equals(homeURL))
{
    if (Model.Header != null) { 
    <header id="header">
            @Display.Branding()
            
            @if (Model.Navigation != null) {
                @Display(Model.Navigation)
            }

        <a href="#login_modal" id="btn_login" class="btn btn-default btn-sm modal_btn">@T("LOGIN")</a>
            <nav class="change_language">
                <a href="#">TR</a>
            </nav><!-- /.change_language -->

        </header>
    }
  }
else
{
            <header id="header" class="dark">
                @Display.Branding()
                @Display(Model.Navigation)

                <a href="#login_modal" id="btn_login" class="btn btn-default btn-sm modal_btn">@T("LOGIN")</a>
                
                <nav class="change_language">
                    <a href="#">TR</a>
                </nav><!-- /.change_language -->

            </header>
        }
<header id="mobile_header">
    @Display.Branding()

    @if (Model.Navigation != null)
    {
       @Zone(Model.Navigation)
    }
</header><!-- /#mobile_header -->

@* the model content for the page is in the Content zone @ the default position (nothing, zero, zilch) *@
    @if (Model.Content != null) {
                    @Zone(Model.Content)
      }
        
    @if (Model.AsideSecond != null) {
                @Zone(Model.AsideSecond)
        }
        
@using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new { ReturnUrl = Request.QueryString["ReturnUrl"] })))
{

<div id="login_modal" class="modal">
    <div class="modal_close" onclick="$.fn.custombox('close');"><i class="icon_close"></i></div>
@using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new { ReturnUrl = Request.QueryString["ReturnUrl"] })))
{
        <div class="modal-example-body">
            <h4>USER LOGIN</h4>
            <div class="form-group">
                <div class="input-group">
                    <div class="input-group-addon"><i class="icon_user"></i></div>
                    <input type="text" class="form-control" placeholder="Username">
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <div class="input-group-addon"><i class="icon_key"></i></div>
                    <input type="password" class="form-control" placeholder="Password">
                </div>
            </div>
            <div class="text-right">
                <a href="member.html" id="lm_forgot">Forgot Password</a>
            </div>
        </div><!-- /.modal-example-body -->
        <button type="submit" class="btn btn-danger">LOGIN</button>
}
</div><!-- /.modal -->
}
    
@tag.EndElement

<div id="back_to_top">
    <a href="#" class="btn btn-default btn-xs">BACK TO TOP <i class="icon_arrow_up"></i></a>
</div><!-- /#back_to_top -->
LogOn.cshtml
@using Orchard.ContentManagement

@{
    var userCanRegister = WorkContext.CurrentSite.As<Orchard.Users.Models.RegistrationSettingsPart>().UsersCanRegister;
    var enableLostPassword = WorkContext.CurrentSite.As<Orchard.Users.Models.RegistrationSettingsPart>().EnableLostPassword;
}


@if (Model.Title == "Access Denied")
{
    <div class="alert alert-dismissable alert-danger">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <strong>@Html.TitleForPage(T("Access Denied").ToString())</strong>
        <p>@T("You do not have permission to complete your request.")</p>
    </div>
}

@if (Html.ValidationSummary() != null)
{
    <div class="alert alert-dismissable alert-danger">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <strong>@T("Login was unsuccessful. Please correct the errors and try again.")</strong>
        <p>@Html.ValidationSummary()</p>
    </div>
}

<h1 class="page-title">@Html.TitleForPage((string)Model.Title)</h1>
<p>
    @T("Please enter your username and password.")
    @if (userCanRegister)
    { @Html.ActionLink(T("Register").Text, "Register", new { ReturnUrl = Request.QueryString["ReturnUrl"] }) @T(" if you don't have an account.") }
    @if (enableLostPassword)
    { <text> </text> @Html.ActionLink(T("Lost your Password?").Text, "RequestLostPassword") }
</p>

@using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new { ReturnUrl = Request.QueryString["ReturnUrl"] })))
{
    <fieldset class="login-form group">
        <legend>@T("Account Information")</legend>
        <div>
            <label for="username-email">@T("Username")</label>
            @Html.TextBox("userNameOrEmail", "", new { id = "username-email", autofocus = "autofocus", @class = "validate[required]" })
            @Html.ValidationMessage("userNameOrEmail")
        </div>
        <div>
            <label for="password">@T("Password")</label>
            @Html.Password("password", null, new { @class = "validate[required]" })
            @Html.ValidationMessage("password")
        </div>
        <div class="checkbox">
            <label class="forcheckbox" for="remember-me">
                @Html.CheckBox("rememberMe", new { id = "remember-me" }) @T("Remember Me")
            </label>
        </div>
        <div>
            <button class="primaryAction" type="submit">@T("LOGIN")</button>
        </div>
    </fieldset>
}
User.cshtml
@using System.Web.Mvc;

<div class="user-display">
    @if (WorkContext.CurrentUser != null) {
        <span class="user-actions welcome">
            @T("Welcome, <strong>{0}</strong>!", "<a href=\"" + @Url.Action("ChangePassword", new { Controller = "Account", Area = "Orchard.Users" }) + "\">" + @Html.ItemDisplayText(WorkContext.CurrentUser) + "</a>")
        </span>
        <span class="user-actions">
            @Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl }, new { rel = "nofollow" })
            @if (AuthorizedFor(Orchard.Security.StandardPermissions.AccessAdminPanel)) {
                @Html.ActionLink(T("Dashboard").ToString(), "Index", new {Area = "Dashboard", Controller = "Admin"})
            }
        </span>
    } else {
        <span class="user-actions">@Html.ActionLink(T("Sign In").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = (Request.QueryString["ReturnUrl"] ?? Request.RawUrl) }, new { rel = "nofollow" })</span>
    }
</div>
Nov 7, 2014 at 7:05 PM
Edited Nov 7, 2014 at 7:05 PM
Hi!

I think you must specify the whole route in your layout, because the layout lives now in the Theme namespace.

Try like this:
....
@using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn","Account", new {area="Orchard.Users"}, new { ReturnUrl = Request.QueryString["ReturnUrl"] })))
....