Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://localhost:50693/Pessoas
- http://localhost:50693/Home/Login
- http://localhost:50693/Home/Login?ReturnUrl=%2fPessoas
- [HttpPost]
- public ActionResult Login(string email, string senha, string ReturnUrl)
- {
- Pessoas usuarios = db.Pessoas.Where(t => t.Email == email && t.Senha == senha).ToList().FirstOrDefault();
- if (usuarios != null)
- {
- string permissoes = "";
- permissoes += usuarios.TipoUsuario + ",";
- permissoes = permissoes.Substring(0, permissoes.Length - 1);
- FormsAuthentication.SetAuthCookie(usuarios.Nome, false);
- FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, usuarios.Email, DateTime.Now, DateTime.Now.AddMinutes(30), false, permissoes);
- string hash = FormsAuthentication.Encrypt(ticket);
- HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
- if (ticket.IsPersistent)
- cookie.Expires = ticket.Expiration;
- Response.Cookies.Add(cookie);
- if (String.IsNullOrEmpty(ReturnUrl))
- return RedirectToAction("Index", "Pessoas");
- else
- {
- var decodedUrl = Server.UrlDecode(ReturnUrl);
- if (Url.IsLocalUrl(decodedUrl))
- return Redirect(decodedUrl);
- else
- return RedirectToAction("Index", "Pessoas");
- }
- }
- else
- {
- ModelState.AddModelError("", "Usuário/Senha inválidos");
- return View();
- }
- }
- [Authorize]
- public class PessoasController : Controller{...}
Add Comment
Please, Sign In to add comment