Skip to content

Instantly share code, notes, and snippets.

@jmprado
Created November 12, 2014 14:59
Show Gist options
  • Save jmprado/88882be89c9909956060 to your computer and use it in GitHub Desktop.
Save jmprado/88882be89c9909956060 to your computer and use it in GitHub Desktop.
public ActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(LoginModel login)
{
if (ModelState.IsValid)
{
var aluno = _alunoDal.RealizaLogin(login.Email, login.Senha);
if (aluno == null)
{
ModelState.AddModelError("Email", "Email ou senha inválidos");
return View();
}
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login.Email, DateTime.Now, DateTime.Now.AddMinutes(50), false, aluno.Nome, FormsAuthentication.FormsCookiePath);
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
LoggedUser user = new LoggedUser();
user.Nome = aluno.Nome;
user.Email = login.Email;
user.IdAluno = aluno.IdAluno;
Session["userdata"] = user;
return RedirectToAction("Index", "AreaAluno");
}
return View(login);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment