Files
Umbraco-CMS/src/Umbraco.Web/Controllers/UmbLoginController.cs

44 lines
1.4 KiB
C#
Raw Normal View History

using System.Web.Mvc;
2013-11-07 17:16:22 +01:00
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
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
{
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
}
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)
{
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);
}
//redirect to current page by default
2017-05-12 14:49:44 +02:00
return RedirectToCurrentUmbracoPage();
//return RedirectToCurrentUmbracoUrl();
2013-11-07 17:16:22 +01:00
}
}
}