Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Last active August 29, 2015 14:09
Show Gist options
  • Save BryanWilhite/ba1a8f082471bde0780e to your computer and use it in GitHub Desktop.
Save BryanWilhite/ba1a8f082471bde0780e to your computer and use it in GitHub Desktop.
ASP.NET MVC: ActionResult LogOn(LoginModel model)
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