Guest User

Untitled

a guest
Oct 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. http://localhost:50693/Pessoas
  2.  
  3. http://localhost:50693/Home/Login
  4.  
  5. http://localhost:50693/Home/Login?ReturnUrl=%2fPessoas
  6.  
  7. [HttpPost]
  8. public ActionResult Login(string email, string senha, string ReturnUrl)
  9. {
  10. Pessoas usuarios = db.Pessoas.Where(t => t.Email == email && t.Senha == senha).ToList().FirstOrDefault();
  11. if (usuarios != null)
  12. {
  13. string permissoes = "";
  14. permissoes += usuarios.TipoUsuario + ",";
  15. permissoes = permissoes.Substring(0, permissoes.Length - 1);
  16. FormsAuthentication.SetAuthCookie(usuarios.Nome, false);
  17. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, usuarios.Email, DateTime.Now, DateTime.Now.AddMinutes(30), false, permissoes);
  18. string hash = FormsAuthentication.Encrypt(ticket);
  19. HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
  20. if (ticket.IsPersistent)
  21. cookie.Expires = ticket.Expiration;
  22. Response.Cookies.Add(cookie);
  23. if (String.IsNullOrEmpty(ReturnUrl))
  24. return RedirectToAction("Index", "Pessoas");
  25. else
  26. {
  27. var decodedUrl = Server.UrlDecode(ReturnUrl);
  28. if (Url.IsLocalUrl(decodedUrl))
  29. return Redirect(decodedUrl);
  30. else
  31. return RedirectToAction("Index", "Pessoas");
  32. }
  33. }
  34. else
  35. {
  36. ModelState.AddModelError("", "Usuário/Senha inválidos");
  37. return View();
  38. }
  39. }
  40.  
  41. [Authorize]
  42. public class PessoasController : Controller{...}
Add Comment
Please, Sign In to add comment