Last active
August 29, 2015 14:15
-
-
Save davidknipe/d9fdd37ff86b37794e46 to your computer and use it in GitHub Desktop.
Claims helper block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model ListAllClaimsModel | |
<div> | |
<h3>@Model.BlockTitle</h3> | |
<table class="table table-striped table-condensed"> | |
@*<thead> | |
<tr> | |
<th>Claims</th> | |
</tr> | |
</thead>*@ | |
<tbody> | |
@foreach (var claim in Model.AllClaims) | |
{ | |
<tr> | |
<td> | |
@claim.Type <br /> | |
<strong> | |
@if (claim.Value.Length > 80) | |
{ | |
@claim.Value.Substring(0, 80) | |
} | |
else | |
{ | |
@claim.Value | |
} | |
</strong> | |
</td> | |
</tr> | |
} | |
</tbody> | |
</table> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.DataAbstraction; | |
using System.ComponentModel.DataAnnotations; | |
namespace EPiServerFS.Models.Blocks | |
{ | |
[SiteContentType(GUID = "9442B0A5-A683-4811-BD25-31BC0232F83E")] | |
public class ListAllClaimsBlock : SiteBlockData | |
{ | |
[Display(Order = 1, Name = "List title", GroupName = SystemTabNames.Content)] | |
public virtual string BlockTitle { get; set; } | |
public override void SetDefaultValues(ContentType contentType) | |
{ | |
base.SetDefaultValues(contentType); | |
this.BlockTitle = "List of all claims for user:"; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.Web.Mvc; | |
using EPiServerFS.Models.Blocks; | |
using EPiServerFS.Models.ViewModels; | |
using System.Security.Claims; | |
using System.Web.Mvc; | |
namespace EPiServerFS.Controllers | |
{ | |
public class ListAllClaimsBlockController : BlockController<ListAllClaimsBlock> | |
{ | |
public override ActionResult Index(ListAllClaimsBlock currentBlock) | |
{ | |
ListAllClaimsModel model = new ListAllClaimsModel(); | |
model.BlockTitle = currentBlock.BlockTitle; | |
if (this.User != null && (this.User as ClaimsPrincipal) != null && (this.User as ClaimsPrincipal).Identity.IsAuthenticated) | |
{ | |
model.AllClaims = (this.User as ClaimsPrincipal).Claims; | |
} | |
return PartialView(model); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Security.Claims; | |
namespace EPiServerFS.Models.ViewModels | |
{ | |
public class ListAllClaimsModel | |
{ | |
public string BlockTitle; | |
public IEnumerable<Claim> AllClaims; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment