Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created August 3, 2017 09:23
Show Gist options
  • Save DmitrySikorsky/9973f520223d09ee3416bfabe4ba2d13 to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/9973f520223d09ee3416bfabe4ba2d13 to your computer and use it in GitHub Desktop.
@inject AspNetCoreCustomUserManager.IUserManager UserManager
@using System.Security.Claims
<h1>ASP.NET Core<br />Custom User Manager</h1>
<div class="form__field field">
<span class="marker marker--secondary">User.Identity.IsAuthenticated:</span> @User.Identity.IsAuthenticated
</div>
@if (this.User.Identity.IsAuthenticated)
{
<div class="form__field field">
<span class="marker marker--secondary">UserManager.GetCurrentUser(this.Context).Name:</span> @UserManager.GetCurrentUser(this.Context).Name
</div>
<div class="form__field field">
<span class="marker marker--secondary">User.HasClaim(ClaimTypes.Role, "Administrator"):</span> @User.HasClaim(ClaimTypes.Role, "Administrator")
</div>
<div class="form__field field">
<span class="marker marker--secondary">User.HasClaim("Permission", "DoEverything"):</span> @User.HasClaim("Permission", "DoEverything")
</div>
}
@if (this.User.Identity.IsAuthenticated)
{
<form class="form" action="/home/logout" method="post">
<div class="form__buttons buttons">
<button type="submit">Logout user</button>
</div>
</form>
}
else
{
<form class="form" action="/home/login" method="post">
<div class="form__buttons buttons">
<button type="submit">Login user</button>
</div>
</form>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment