Last active
August 29, 2015 14:09
-
-
Save BryanWilhite/ba1a8f082471bde0780e to your computer and use it in GitHub Desktop.
ASP.NET MVC: ActionResult LogOn(LoginModel model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using System.Web.Security; | |
namespace Fox.Studio.SCLogic.Web.Controllers | |
{ | |
using Fox.Studio.SCLogic.ModelContext; | |
using Fox.Web.Mvc.Models; | |
public class ClientController : Controller | |
{ | |
[Authorize] | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpGet] | |
public ActionResult LogOn() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public ActionResult LogOn(LoginModel model) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
ModelState.AddModelError(string.Empty, "Invalid user name or password."); | |
return View(); | |
} | |
if (!SCLogicContext.IsUserValid(model.UserName, model.Password)) | |
{ | |
ModelState.AddModelError(string.Empty, "Invalid user name or password."); | |
return View(); | |
} | |
FormsAuthentication.SetAuthCookie(model.UserName, true); | |
return RedirectToAction("index", "client"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment