Skip to content

Instantly share code, notes, and snippets.

Ibrahim Šuta Ibro

Block or report user

Report or block Ibro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CategoriesController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
{
var authorizationResult = await _authorizationService.AuthorizeAsync(User, category, new InsertCategoryRequirement());
if (!authorizationResult.Succeeded) // If user has no access show him 403
{
return new ForbidResult();
}
View InsertCategoryRequirement.cs
public class InsertCategoryHandler : AuthorizationHandler<InsertCategoryRequirement, Category>, IAuthorizationRequirement
{
private readonly ISecurityService _securityService;
public InsertCategoryHandler(ISecurityService securityService) => _securityService = securityService;
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context,
InsertCategoryRequirement requirement, Category category)
{
@Ibro
Ibro / CategoriesController.cs
Created Apr 24, 2018
Categories - create with AuthService in action
View CategoriesController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
{
ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", category.UserId);
// If ModelState isn't valid, return to view immediately
if (!ModelState.IsValid)
{
return View(category);
View CategoriesController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,UserId")] Category category)
{
// Populate UserId select list.
ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", category.UserId);
// If ModelState isn't valid, return to view immediately
if (!ModelState.IsValid)
{
View ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Category> Categories { get; set; }
}
@Ibro
Ibro / Category.cs
Created Apr 24, 2018
ASP.NET Core Authorization - Managing permissions for resources - Category class
View Category.cs
public class Category
{
public string Id { get; set; }
public string Name { get; set; }
public ApplicationUser User { get; set; }
public string UserId { get; set; }
}
View Set.js
let arr = [ 13, 11, 15, 21, 13, 11, 17, 17, 19, 19, 21 ];
let uniqueArray = [...new Set(arr)];
console.log(uniqueArray); // [13, 11, 15, 21, 17, 19]
View Map.js
let obj = {};
console.log(obj['toString'])
console.log(obj['hasOwnProperty'])
console.log(obj['constructor'])
View Set.js
let set = new Set([9, 15]);
set.add(44);
let arr = [...set];
console.log(arr); // [9, 15, 44]
View Set.js
let set = new Set([3, 5, true, 'This is a string, obviously.']);
for (let item of set) {
console.log(item);
}
You can’t perform that action at this time.