61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
namespace LaaProductionWeb.Controllers
|
|
{
|
|
using LaaProductionWeb.App_Infrastructure;
|
|
using LaaProductionWeb.Services.Interfaces;
|
|
using LaaProductionWeb.Services.Models;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Web.Mvc;
|
|
|
|
[Authorize]
|
|
public class AccountController : Controller
|
|
{
|
|
private readonly IAccountService accountService;
|
|
|
|
public AccountController(IAccountService accountService)
|
|
=> this.accountService = accountService;
|
|
|
|
[HttpGet]
|
|
public ActionResult Authorize(string role)
|
|
{
|
|
var userId = this.User.NameIdentifier();
|
|
var permissionsModel = this.accountService
|
|
.GetPermissionModelForUser(userId, role);
|
|
|
|
return this.View(model: permissionsModel);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Authorize(PermissionsModel model)
|
|
{
|
|
if (this.ModelState.IsValid)
|
|
{
|
|
this.accountService.RequestPermissions(model);
|
|
}
|
|
|
|
return this.View(model);
|
|
}
|
|
|
|
[HttpGet]
|
|
[AllowedRoles("Admin")]
|
|
public ActionResult Permissions()
|
|
{
|
|
var model = this.accountService.GetUsersWithPendingRoles();
|
|
|
|
return this.View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[AllowedRoles("Admin")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Permissions(List<UserPermissions> model)
|
|
{
|
|
this.accountService.SaveUserPermissions(model);
|
|
|
|
model = this.accountService.GetUsersWithPendingRoles();
|
|
|
|
return this.View(model);
|
|
}
|
|
}
|
|
} |