zero authorize

This commit is contained in:
2020-04-15 14:09:52 +02:00
parent 9f5d9bb920
commit ccc63b9602
23 changed files with 389 additions and 97 deletions
@@ -6,7 +6,6 @@ using zero.Core.Api;
namespace zero.Web.Controllers
{
[AllowAnonymous]
public class ApplicationsController : BackofficeController
{
private IApplicationsApi Api { get; set; }
@@ -4,11 +4,11 @@ using System;
using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Auth;
namespace zero.Web.Controllers
{
[AllowAnonymous]
[ZeroAuthorize]
public class AuthenticationController : BackofficeController
{
private IAuthenticationApi Api { get; set; }
@@ -22,8 +22,6 @@ namespace zero.Web.Controllers
/// <summary>
/// Get the currently logged in user
/// </summary>
[AllowAnonymous]
//[Authorize()]
public async Task<IActionResult> GetUser()
{
return Json(await Api.GetUser());
@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using zero.Core;
using zero.Core.Auth;
namespace zero.Web.Controllers
{
[ZeroAuthorize]
public abstract class BackofficeController : Controller
{
protected IZeroConfiguration Configuration { get; set; }
@@ -6,7 +6,6 @@ using zero.Core.Api;
namespace zero.Web.Controllers
{
[AllowAnonymous]
public class CountriesController : BackofficeController
{
private ICountriesApi Api { get; set; }
+2 -1
View File
@@ -2,11 +2,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using zero.Core;
using zero.Core.Auth;
using zero.Core.Extensions;
namespace zero.Web.Controllers
{
[AllowAnonymous]
[ZeroAuthorize(false)]
public class IndexController : BackofficeController
{
private ZeroOptions Options { get; set; }
@@ -7,7 +7,6 @@ using zero.Core.Api;
namespace zero.Web.Controllers
{
[AllowAnonymous]
public class PageTreeController : BackofficeController
{
private IPageTreeApi Api { get; set; }
@@ -5,7 +5,6 @@ using zero.Core.Api;
namespace zero.Web.Controllers
{
[AllowAnonymous]
public class SectionsController : BackofficeController
{
private ISectionsApi Api { get; set; }
@@ -5,7 +5,6 @@ using zero.Core.Api;
namespace zero.Web.Controllers
{
[AllowAnonymous]
public class SettingsController : BackofficeController
{
private ISettingsApi Api { get; set; }
+5 -4
View File
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
@@ -8,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
using zero.Core.Auth;
using zero.Core.Entities;
using zero.Core.Entities.Setup;
using zero.Core.Extensions;
@@ -15,7 +14,7 @@ using zero.Web.Controllers;
namespace zero.Web.Setup
{
[AllowAnonymous]
[ZeroAuthorize(false)]
public class SetupController : BackofficeController
{
protected ISetupApi Api { get; private set; }
@@ -32,6 +31,7 @@ namespace zero.Web.Setup
Options = options.CurrentValue;
}
public IActionResult Index()
{
if (!Configuration.ZeroVersion.IsNullOrEmpty())
@@ -42,6 +42,7 @@ namespace zero.Web.Setup
return View("/Views/Setup.cshtml");
}
[HttpPost]
public async Task<IActionResult> Install([FromBody] SetupModel model)
{
+25 -11
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using zero.Core;
@@ -23,15 +22,6 @@ namespace zero.Web.Controllers
}
[HttpGet]
public IActionResult GetUser()
{
return Json(new
{
user = HttpContext.User.Identity.IsAuthenticated
});
}
[HttpPost]
public async Task<IActionResult> Login([FromQuery] string username, [FromQuery] string password)
{
@@ -44,5 +34,29 @@ namespace zero.Web.Controllers
result
});
}
[ZeroAuthorize]
public async Task<IActionResult> GetUser()
{
User user = await SignInManager.UserManager.GetUserAsync(HttpContext.User);
return Json(new
{
user
});
}
[HttpPost]
public async Task<IActionResult> Logout()
{
await SignInManager.SignOutAsync();
return Json(new
{
success = true
});
}
}
}