2018-06-29 19:52:40 +02:00
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Web.Models;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Core;
|
2018-07-06 17:36:33 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UmbLoginController : SurfaceController
|
|
|
|
|
|
{
|
2018-07-06 17:36:33 +02:00
|
|
|
|
public UmbLoginController()
|
2019-01-21 15:57:48 +01:00
|
|
|
|
{ }
|
2018-07-06 17:36:33 +02:00
|
|
|
|
|
2019-01-18 15:05:20 +01:00
|
|
|
|
public UmbLoginController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, ILogger logger, IProfilingLogger profilingLogger)
|
|
|
|
|
|
: base(umbracoContext, databaseFactory, services, appCaches, logger, profilingLogger)
|
2019-01-21 15:57:48 +01: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]
|
2018-06-29 19:52:40 +02:00
|
|
|
|
public ActionResult HandleLogin([Bind(Prefix = "loginModel")]LoginModel model)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ModelState.IsValid == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CurrentUmbracoPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Members.Login(model.Username, model.Password) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
//don't add a field level error, just model level
|
|
|
|
|
|
ModelState.AddModelError("loginModel", "Invalid username or password");
|
|
|
|
|
|
return CurrentUmbracoPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TempData["LoginSuccess"] = true;
|
|
|
|
|
|
|
|
|
|
|
|
//if there is a specified path to redirect to then use it
|
|
|
|
|
|
if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
// validate the redirect url
|
|
|
|
|
|
// if it's not a local url we'll redirect to the root of the current site
|
|
|
|
|
|
return Redirect(Url.IsLocalUrl(model.RedirectUrl)
|
|
|
|
|
|
? model.RedirectUrl
|
|
|
|
|
|
: CurrentPage.AncestorOrSelf(1).Url);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//redirect to current page by default
|
|
|
|
|
|
|
|
|
|
|
|
return RedirectToCurrentUmbracoPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|