Skip to content

Instantly share code, notes, and snippets.

@xivSolutions
Created February 6, 2014 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xivSolutions/8843504 to your computer and use it in GitHub Desktop.
Save xivSolutions/8843504 to your computer and use it in GitHub Desktop.
// LOGIN PARTIAL:
// Change the Views => Shared => _LoginPartial to match this:
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
// THIS is the line we changed:
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Edit", "Account", routeValues: new { id = User.Identity.GetUserName() }, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
// "EDIT" VIEW:
// Make the following change to the Edit View:
@model AspNetRoleBasedSecurity.Models.EditUserViewModel
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
// Add a "Change Password" link which points to "Manage":
@Html.ActionLink("Change Password", "Manage")
@using (Html.BeginForm())
{
// . . . Code . . .
}
// "MANAGE" METHOD OF ACCOUNT CONTROLLER:
// Change the Edit method of AccountController like so:
[Authorize(Roles = "Admin")]
public ActionResult Manage(ManageMessageId? message)
{
// Add this slightly hackey code to get you started. You can imrpove from here:
if(message == ManageMessageId.ChangePasswordSuccess)
{
return RedirectToAction("Edit", new { id = User.Identity.GetUserName() });
}
ViewBag.StatusMessage =
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
: message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
: message == ManageMessageId.Error ? "An error has occurred."
: "";
ViewBag.HasLocalPassword = HasPassword();
ViewBag.ReturnUrl = Url.Action("Manage");
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment