public static bool Logout() { sec_sessions session = User; if (session == null) { return(true); } session.end_time = DateTime.Now; using (var db = new MainEntities()) { db.Entry(session).State = System.Data.Entity.EntityState.Modified; if (db.SaveChanges() == 0) { return(false); } } HttpContext.Current.Response.Cookies.Clear(); HttpContext.Current.Session.Clear(); return(true); }
public Sessions(Guid Token) { using (MainEntities ctx = new MainEntities()) { this.Entity = ctx.sec_sessions.Include("sec_users").Include("sec_users.tbl_accounts").SingleOrDefault(a => a.id == Token); } }
public ActionResult DeleteConfirmed(Guid id) { sec_sessions sec_sessions = db.sec_sessions.Find(id); db.sec_sessions.Remove(sec_sessions); db.SaveChanges(); return(RedirectToAction("Index")); }
public Sessions() { using (MainEntities ctx = new MainEntities()) { this.Entity = new sec_sessions(); this.Entity.id = Guid.NewGuid(); this.Entity.start_time = DateTime.Now; } }
public ActionResult DeleteConfirmed(Guid id) { sec_sessions sec_sessions = db.sec_sessions.Find(id); sec_sessions.end_time = DateTime.Now; db.Entry(sec_sessions).State = EntityState.Modified; //db.sec_sessions.Remove(sec_sessions); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id,user_id,start_time,end_time,ip,agent,browser,country,city,country_code,isp,lat,lon,timezone,paltform,device_id")] sec_sessions sec_sessions) { if (ModelState.IsValid) { db.Entry(sec_sessions).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.user_id = new SelectList(db.sec_users, "id", "pwd", sec_sessions.user_id); return(View(sec_sessions)); }
// GET: Sessions/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sec_sessions sec_sessions = db.sec_sessions.Find(id); if (sec_sessions == null) { return(HttpNotFound()); } return(View(sec_sessions)); }
// GET: Sessions/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sec_sessions sec_sessions = db.sec_sessions.Find(id); if (sec_sessions == null) { return(HttpNotFound()); } ViewBag.user_id = new SelectList(db.sec_users, "id", "pwd", sec_sessions.user_id); return(View(sec_sessions)); }
public static sec_sessions GetNewSession(sec_users usr, int platform = 1) { using (var ctx = new MainEntities()) { IPResult s = new IPResult(); string ip = ""; string agent = ""; IPResult iploc = new IPResult(); var request = HttpContext.Current.Request.ServerVariables; try { ip = request.Get("REMOTE_ADDR"); agent = request.Get("HTTP_USER_AGENT"); iploc = General.GetResponse("http://ip-api.com/json/" + ip); } catch (Exception ex) { // return APIResult<sec_sessions>.Error(ResponseCode.BackendServerRequest, ex.Message + "get location ip:" + ip + " agent:" + agent); } try { var userSessions = ctx.sec_sessions.Where(a => a.user_id == usr.id && a.end_time == null && a.paltform == platform && a.end_time == null).FirstOrDefault(); if (userSessions != null) { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("SESSION_ID", userSessions.id); return(userSessions); } sec_sessions ses = new sec_sessions(); ses.user_id = usr.id; ses.ip = request.Get("REMOTE_ADDR"); //IPiploc = new IPResult();// General.GetResponse("http://ip-api.com/json/" + ses.Entity.ip); ses.isp = iploc.isp; ses.lat = iploc.lat; ses.lon = iploc.lon; ses.timezone = iploc.timezone; ses.city = iploc.city; ses.country = iploc.country; ses.country_code = iploc.countryCode; ses.agent = request.Get("HTTP_USER_AGENT"); ses.paltform = platform; ses.browser = General.getAgent(ses.agent).name; ses.id = Guid.NewGuid(); ses.start_time = DateTime.Now; ctx.sec_sessions.Add(ses); ctx.SaveChanges(); HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("SESSION_ID", ses.id); return(ses); } catch (Exception ex) { return(null); } } }