public HttpCookie AuthenticateUser(string email, string senha) { Usuario result; string senhaHash = GetHash(senha); result = usuarioRepository.SimpleWhere(u => u.Email == email && u.Senha == senhaHash).FirstOrDefault(); if (result == null) { throw new InternalException("Usuário inexistente ou senha inválida"); } UsuarioLogado usuarioLogado = new UsuarioLogado(result); UsuarioLogadoSerializable serializable = new UsuarioLogadoSerializable(result); string userData = new JavaScriptSerializer().Serialize(serializable); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, result.Email, DateTime.Now, DateTime.Now.AddHours(2), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpContext.Current.User = usuarioLogado; return(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); }
public void UpdateAuthenticationCookie(Usuario usuario) { UsuarioLogado usuarioLogado = new UsuarioLogado(usuario); UsuarioLogadoSerializable serializable = new UsuarioLogadoSerializable(usuario); string userData = new JavaScriptSerializer().Serialize(serializable); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, usuario.Email, DateTime.Now, DateTime.Now.AddHours(2), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpContext.Current.User = usuarioLogado; HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); }