2016-09-01 19:06:08 +02:00
|
|
|
|
using System.Web.Mvc;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
using Umbraco.Web.Models;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
2014-03-07 19:13:25 +11:00
|
|
|
|
using Umbraco.Core;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UmbLoginController : SurfaceController
|
|
|
|
|
|
{
|
|
|
|
|
|
[HttpPost]
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public ActionResult HandleLogin([Bind(Prefix = "loginModel")]LoginModel model)
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
2014-03-07 19:13:25 +11:00
|
|
|
|
if (ModelState.IsValid == false)
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return CurrentUmbracoPage();
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-07 19:13:25 +11:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-27 14:56:42 +02:00
|
|
|
|
TempData["LoginSuccess"] = true;
|
|
|
|
|
|
|
2014-03-07 19:13:25 +11:00
|
|
|
|
//if there is a specified path to redirect to then use it
|
|
|
|
|
|
if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
// validate the redirect url
|
|
|
|
|
|
// if it's not a local url we'll redirect to the root of the current site
|
2017-07-20 11:21:28 +02:00
|
|
|
|
return Redirect(Url.IsLocalUrl(model.RedirectUrl)
|
|
|
|
|
|
? model.RedirectUrl
|
2017-05-12 14:49:44 +02:00
|
|
|
|
: CurrentPage.AncestorOrSelf(1).Url);
|
2014-03-07 19:13:25 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//redirect to current page by default
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2014-03-13 14:12:02 +11:00
|
|
|
|
return RedirectToCurrentUmbracoPage();
|
|
|
|
|
|
//return RedirectToCurrentUmbracoUrl();
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|