Authorization works with roles properly. Added authorization examples to Sample project.

This commit is contained in:
JudahGabriel
2017-09-06 11:49:33 -05:00
parent ea3a6cbdd3
commit 6fc83d4ea3
9 changed files with 87 additions and 19 deletions
+20 -1
View File
@@ -6,14 +6,19 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Sample.Models;
using Raven.Client;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
namespace Sample.Controllers
{
public class HomeController : RavenController
{
public HomeController(IAsyncDocumentSession dbSession)
private UserManager<AppUser> userManager;
public HomeController(IAsyncDocumentSession dbSession, UserManager<AppUser> userManager)
: base(dbSession)
{
this.userManager = userManager;
}
public async Task<IActionResult> Index()
@@ -27,6 +32,20 @@ namespace Sample.Controllers
return View();
}
// Require that the user be logged in.
[Authorize]
public IActionResult Auth()
{
return View();
}
// Require that the user be in the Admin role.
[Authorize(Roles = "Admin")]
public IActionResult AuthAdmin()
{
return View();
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";