Ejemplo n.º 1
0
        public ActionResult LogIn(LogInModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (membership.ValidateUser(model.UserName, model.Password))
                {
                    SiteContext db = new SiteContext();
                    User u = db.Users.Single(x => x.Username.ToLower() == model.UserName.ToLower());
                    SiteAuthentication.SetAuthCookie(u, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Core");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 2
0
        public static void Rebuild()
        {
            var db = new SiteContext();

            RemoveAll();
            AddUpdate(db.Articles);
            Optimize();
        }
Ejemplo n.º 3
0
        public static User GetUserCookie()
        {
            HttpCookie encCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (encCookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encCookie.Value);
                SiteContext db = new SiteContext();

                User user = db.Users.Single(x => x.ID == new Guid(ticket.UserData));

                db.Entry(user).State = EntityState.Modified;
                return user;
            }

            return null;
        }
Ejemplo n.º 4
0
        public static void RegisterHit(Guid target)
        {
            var db = new SiteContext();

            var ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if(ip == null || ip.ToLower() == "unknown") ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            db.PageHits.Add(new PageHit
            {
                ID = Guid.NewGuid(),
                ClientAddress = ip,
                Target = target,
                Time = DateTime.Now
            });

            db.SaveChanges();
        }