2020-11-18 16:52:40 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Core;
|
2018-07-06 17:36:33 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
2020-11-18 16:12:42 +01:00
|
|
|
|
using Umbraco.Core.Models.Security;
|
2018-07-06 17:36:33 +02:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2020-11-18 16:12:42 +01:00
|
|
|
|
using Umbraco.Core.Security;
|
2018-07-06 17:36:33 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
2020-11-18 16:12:42 +01:00
|
|
|
|
using Umbraco.Web.Common.Filters;
|
|
|
|
|
|
using Umbraco.Web.Routing;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2020-11-18 16:12:42 +01:00
|
|
|
|
namespace Umbraco.Web.Website.Controllers
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2020-11-18 16:52:40 +01:00
|
|
|
|
[UmbracoMemberAuthorize]
|
2018-06-29 19:52:40 +02:00
|
|
|
|
public class UmbLoginStatusController : SurfaceController
|
2018-06-19 18:53:25 +02:00
|
|
|
|
{
|
2020-11-18 16:12:42 +01:00
|
|
|
|
private readonly IUmbracoWebsiteSecurity _websiteSecurity;
|
2018-06-19 18:53:25 +02:00
|
|
|
|
|
2020-02-27 09:56:35 +01:00
|
|
|
|
public UmbLoginStatusController(IUmbracoContextAccessor umbracoContextAccessor,
|
2020-09-21 11:46:29 +02:00
|
|
|
|
IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches,
|
2020-11-18 16:12:42 +01:00
|
|
|
|
IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider, IUmbracoWebsiteSecurity websiteSecurity)
|
|
|
|
|
|
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
|
2019-01-31 15:09:31 +11:00
|
|
|
|
{
|
2020-11-18 16:12:42 +01:00
|
|
|
|
_websiteSecurity = websiteSecurity;
|
2019-01-31 15:09:31 +11:00
|
|
|
|
}
|
2018-07-06 17:36:33 +02:00
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
[HttpPost]
|
2018-12-20 16:58:01 +11:00
|
|
|
|
[ValidateAntiForgeryToken]
|
2019-07-13 23:56:29 +02:00
|
|
|
|
[ValidateUmbracoFormRouteString]
|
2020-11-18 16:52:40 +01:00
|
|
|
|
public async Task<IActionResult> HandleLogout([Bind(Prefix = "logoutModel")]PostRedirectModel model)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (ModelState.IsValid == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CurrentUmbracoPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-18 16:12:42 +01:00
|
|
|
|
if (_websiteSecurity.IsLoggedIn())
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2020-11-18 16:52:40 +01:00
|
|
|
|
await _websiteSecurity.LogOutAsync();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TempData["LogoutSuccess"] = true;
|
|
|
|
|
|
|
2020-11-18 16:12:42 +01:00
|
|
|
|
// If there is a specified path to redirect to then use it.
|
2018-06-29 19:52:40 +02:00
|
|
|
|
if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Redirect(model.RedirectUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-18 16:12:42 +01:00
|
|
|
|
// Redirect to current page by default.
|
2018-06-29 19:52:40 +02:00
|
|
|
|
return RedirectToCurrentUmbracoPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|