Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active December 17, 2015 19:49
Show Gist options
  • Save Maarten88/5662689 to your computer and use it in GitHub Desktop.
Save Maarten88/5662689 to your computer and use it in GitHub Desktop.
@helper LoggedInUser()
{
if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
{
@:Hello, @Html.ActionLink(User.Identity.Name ?? "naam onbekend", "Manage", "Account")
}
else
{
@Html.ActionLink("Register", "Register", "Account")
}
}
@helper ActiveItem(string actionName, string controllerName, string areaName)
{
if (ViewContext.RouteData.Values["action"].ToString() == actionName &&
ViewContext.RouteData.Values["controller"].ToString() == controllerName &&
(ViewContext.RouteData.DataTokens["area"] == null || ViewContext.RouteData.DataTokens["area"].ToString() == areaName))
{
@:active
}
}
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Cloud Auction</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="@ActiveItem("Index", "Home", null)">@Html.ActionLink("Home", "Index", "Home")</li>
<li class="@ActiveItem("About", "Home", null)">@Html.ActionLink("About", "About", "Home")</li>
<li class="@ActiveItem("Contact", "Home", null)">@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@if (Request.IsAuthenticated)
{
<ul class="nav pull-right">
<li><div class="nav navbar-text">@LoggedInUser()</div></li>
<li class="divider-vertical"></li>
<li>
<div class="nav navbar-text">
@*<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>*@
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, htmlAttributes: new { id = "logoutForm", @class = "navbar-form" }))
{
<button type="submit" class="btn-link">Log Off</button>
@Html.AntiForgeryToken()
}
</div>
</li>
</ul>
}
else
{
<ul class="nav pull-right">
<li class="@ActiveItem("Register", "Account", null)">@Html.ActionLink("Register", "Register", "Account", new { ReturnUrl = this.Request.Url.AbsolutePath }, new { id = "registerLink", data_dialog_title = "Registration" })</li>
<li class="@ActiveItem("Login", "Account", null)">@Html.ActionLink("Login", "Login", "Account", new { ReturnUrl = this.Request.Url.AbsolutePath }, new { id = "loginLink", data_dialog_title = "Identification" })</li>
</ul>
}
</div><!--/.nav-collapse -->
</div>
</div>
</div>
@model Auction.Web.Models.LoginModel
@{
ViewBag.Title = "Log in";
}
<h1>@ViewBag.Title <small>with local or social network account</small></h1>
<div class="row-fluid">
<div class="span6">
@using (Html.BeginForm(null, null, new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal well" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>using a local account</legend>
@Html.EditorFor(m => m.UserName, new { @class = "input-small" })
@Html.EditorFor(m => m.Password, new { @class = "input-small" })
@Html.EditorFor(m => m.RememberMe)
<input class="btn btn-primary" type="submit" value="Log in" />
&nbsp; or @Html.ActionLink("Register", "Register") if you don't have an account.
</fieldset>
}
</div>
<div class="span6">
@Html.Action("ExternalLoginsList", new { ReturnUrl = ViewBag.ReturnUrl })
</div>
</div> <!-- row-fluid -->
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment