public ActionResult Login(Usuario user) { UserApplication userApp = new UserApplication(this._contexto); var authenticatedUser = userApp.GetByUsernameAndPassword(user); SessionContext login = new SessionContext(); Usuario usuario = (from p in this._contexto.TabelaUsuarios where p.Username == user.Username select p).FirstOrDefault(); if ((authenticatedUser != null) & (login.logado() == false)) { context.SetAuthenticationToken(authenticatedUser.Name, false, authenticatedUser); return RedirectToAction("Index", "Home"); } ViewBag.Error = "Login inválido, tente novamente!"; return View(); }
public void SetAuthenticationToken(string name, bool isPersistant, Usuario userData) { string data = null; if (userData != null) data = new JavaScriptSerializer().Serialize(userData); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, name, DateTime.Now, DateTime.Now.AddYears(1), isPersistant, userData.Id.ToString() ); string cookieData = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieData) { HttpOnly = true, Expires = ticket.Expiration }; HttpContext.Current.Response.Cookies.Add(cookie); }
public void Inserir(Usuario novoUsuario) { this._contexto.TabelaUsuarios.Add(novoUsuario); this._contexto.SaveChanges(); }
public void Editar(Usuario usuarioEditado) { this._contexto.Entry(usuarioEditado).State = System.Data.Entity.EntityState.Modified; this._contexto.SaveChanges(); }
public Usuario GetByUsernameAndPassword(Usuario user) { return (from u in this._contexto.TabelaUsuarios where u.Username == user.Username & u.Password == user.Password select u).FirstOrDefault(); }
public Usuario GetByUsernameAndPassword(Usuario user) { UserRepository userRepo = new UserRepository(_contexto); return userRepo.GetByUsernameAndPassword(user); }