Created
November 12, 2014 14:59
-
-
Save jmprado/88882be89c9909956060 to your computer and use it in GitHub Desktop.
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
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