Exemple #1
0
        private ActionResult LogOn(Identifier identifier)
        {
            //Remove the unnecessary portion of the identifier
            string steamIDString = identifier.ToString().Replace("http://steamcommunity.com/openid/id/", "");
            long   steamId64     = long.Parse(steamIDString);

            using (var db = new SprayContext())
            {
                var user = db.Users.FirstOrDefault(x => x.SteamId == steamId64);

                SteamWebAPI.SteamAPISession session = new SteamWebAPI.SteamAPISession();
                session.accessToken = ""; /* CHANGEME - Steam Web API access token */
                var userInfo = session.GetUserInfo(steamId64.ToString());

                if (user == null)
                {
                    //Add the user if they're new
                    user = CreateUser(steamId64, db, userInfo);
                }
                else
                {
                    // Or update the relevant information
                    user.AvatarURI   = userInfo.avatarUrl;
                    user.NickName    = userInfo.nickname;
                    user.LastUpdated = DateTime.Now;
                }

                int recordsAffected = db.SaveChanges();
                FormsAuthentication.SetAuthCookie(steamId64.ToString(), true);
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemple #2
0
        public ActionResult ApproveSketchy(string id)
        {
            if (Request.IsAuthenticated && (User.Identity.Name == "76561197999489042")) /* CHANGEME - This is my Steam ID. If I logged in, I got extra admin options */
            {
                Guid providedId;
                if (!Guid.TryParse(id, out providedId))
                {
                    return(View("Error"));
                }

                using (var db = new SprayContext())
                {
                    Spray spray = db.Sprays.Where(s => s.Id == providedId).FirstOrDefault();
                    if (spray != null)
                    {
                        spray.Status   = Status.PUBLIC;
                        spray.Safeness = Safeness.SKETCHY;
                        db.SaveChanges();
                    }

                    return(Json(true));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
Exemple #3
0
        public ActionResult Save(string id)
        {
            if (Request.IsAuthenticated)
            {
                Guid providedId;
                if (!Guid.TryParse(id, out providedId))
                {
                    return(View("Error"));
                }

                using (var db = new SprayContext())
                {
                    Spray spray = db.Sprays.Where(s => s.Id == providedId).Where(s => s.Status != Status.DELETED).Where(s => s.DateExpires > DateTime.Now).ToList().FirstOrDefault();
                    if (spray != null)
                    {
                        long steamId64 = long.Parse(User.Identity.Name);
                        User u         = db.Users.FirstOrDefault(x => x.SteamId == steamId64);

                        if (!u.Saved.Contains(spray))
                        {
                            u.Saved.Add(spray);
                            spray.Saves++;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToRoute("View Spray"));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
Exemple #4
0
        public ActionResult Delete(string id)
        {
            if (Request.IsAuthenticated)
            {
                Guid providedId;
                if (!Guid.TryParse(id, out providedId))
                {
                    return(View("Error"));
                }

                using (var db = new SprayContext())
                {
                    Spray spray = db.Sprays.Where(s => s.Id == providedId).FirstOrDefault();
                    if (spray != null)
                    {
                        long steamId64 = long.Parse(User.Identity.Name);

                        if (spray.Creator.SteamId == steamId64 || User.Identity.Name == "76561197999489042") /* CHANGEME - This is my Steam ID. If I logged in, I got extra admin options */
                        {
                            spray.Status = Status.DELETED;
                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Mine", "Browse"));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
Exemple #5
0
        public ActionResult Publish(string id)
        {
            if (Request.IsAuthenticated)
            {
                Guid providedId;
                if (!Guid.TryParse(id, out providedId))
                {
                    return(View("Error"));
                }

                using (var db = new SprayContext())
                {
                    Spray spray = db.Sprays.Where(s => s.Id == providedId).FirstOrDefault();
                    if (spray != null)
                    {
                        long steamId64 = long.Parse(User.Identity.Name);

                        /* CHANGEME - This is my Steam ID. If I logged in, I got extra admin options */
                        if ((spray.Creator.SteamId == steamId64 || User.Identity.Name == "76561197999489042") && spray.Status != Status.PUBLIC) // So we don't have to re-moderate
                        {
                            spray.Status = Status.UNMODERATED;
                            db.SaveChanges();
                        }
                    }

                    return(RedirectToRoute("View Spray"));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
Exemple #6
0
        private void g_Static_ProcessingComplete(object sender, ProcessCompleteEventArgs e)
        {
            Guid g = Guid.NewGuid();

            var context = GlobalHost.ConnectionManager.GetHubContext <ProgressHub>();

            context.Clients.Client(_progressId).changePercent("100", "Processing");

            // UPLOAD NEW SPRAY
            AmazonS3Client   client  = new AmazonS3Client("KEY", "SECRET", RegionEndpoint.USWest1); /* CHANGEME - Amazon S3 Key/Secret */
            PutObjectRequest request = new PutObjectRequest();

            request.PutObjectProgressEvent += request_Static_PutObjectProgressEvent;
            request.BucketName              = _isLoggedIn ? BUCKET_REGISTERED_VTF : BUCKET_ANONYMOUS_VTF;
            request.Key             = string.Format("{0}.vtf", g);
            request.InputStream     = e.outputStream;
            request.CannedACL       = S3CannedACL.PublicRead;
            request.AutoCloseStream = true;
            client.PutObject(request);

            // UPLOAD NEW PREVIEW
            NameValueCollection nvc = Request.Form;
            XDocument           doc = XDocument.Parse(nvc["s3Response"]);
            var location            = UploadToBlitline(g, doc, false);

            // SAVE TO DATABASE
            using (var db = new SprayContext())
            {
                User     u       = null;
                DateTime expires = new DateTime(9999, 12, 31);

                if (_isLoggedIn)
                {
                    u = db.Users.FirstOrDefault(x => x.SteamId == _baseSteamId);
                }
                else
                {
                    expires = DateTime.Now.AddDays(7);
                }

                // Make a new spray object
                Spray spray = new Spray()
                {
                    Animated     = e.Animated,
                    DateAdded    = DateTime.Now,
                    DateExpires  = expires,
                    Fading       = e.Fading,
                    Id           = g,
                    NSFW         = false,
                    Safeness     = Models.Safeness.SFW,
                    PreviewImage = string.Format("https://{0}/{1}{2}", _isLoggedIn ? BUCKET_REGISTERED_GIF : BUCKET_ANONYMOUS_GIF, g, location.ToString().EndsWith(".gif") ? ".gif" : ".png"),
                    Status       = Status.ACTIVE,
                    Saves        = 0,
                    Url          = string.Format("https://{0}/{1}", request.BucketName, request.Key),
                    Creator      = u
                };

                // Tell the client to show the spray
                context.Clients.Client(_progressId).showImage(spray.PreviewImage, spray.Url, "/Create/VMT/" + g.ToString(), spray.Animated, "/Spray/" + g.ToString());

                db.Sprays.Add(spray);
                db.SaveChanges();
            }
        }