Episerver Mixed-mode auth. Login controller
namespace MyNamespace.Controllers | |
{ | |
public class LoginController : Controller | |
{ | |
private UIUserProvider UIUserProvider => ServiceLocator.Current.GetInstance<UIUserProvider>(); | |
private UISignInManager UISignInManager => ServiceLocator.Current.GetInstance<UISignInManager>(); | |
public ActionResult Index() | |
{ | |
return View("/Views/Shared/Login.cshtml"); | |
} | |
[HttpPost] | |
[AllowAnonymous] | |
[ValidateAntiForgeryToken] | |
[ValidateInput(false)] | |
public ActionResult Index(LoginViewModel model) | |
{ | |
if (ModelState.IsValid) | |
{ | |
var resFromSignIn = UISignInManager.SignIn(UIUserProvider.Name, model.Username, model.Password); | |
if (resFromSignIn) | |
{ | |
return Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage)); | |
} | |
} | |
// If we got this far, something failed, redisplay form | |
ModelState.AddModelError("LoginError", "Login failed"); | |
return View("/Views/Shared/Login.cshtml", model); | |
} | |
[HttpPost] | |
[AllowAnonymous] | |
[ValidateAntiForgeryToken] | |
[ValidateInput(false)] | |
public ActionResult AdfsLogin(string returnUrl) | |
{ | |
if (ModelState.IsValid) | |
{ | |
var properties = new AuthenticationProperties { RedirectUri = returnUrl }; | |
HttpContext.GetOwinContext().Authentication.Challenge(properties, WsFederationAuthenticationDefaults.AuthenticationType); | |
} | |
return View("/Views/Shared/Login.cshtml"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment