public ActionResult ApproveNSFW(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.NSFW; db.SaveChanges(); } return Json(true); } } else { return View("Error"); } }
public ActionResult Mine(int? after) { if (!Request.IsAuthenticated) { return View("Error"); } ViewBag.CurrentPage = "mine"; // Reset to 0 if negative or null int afterSpray = after ?? 0; if (afterSpray < 0) afterSpray = 0; SprayListModel sprays = new SprayListModel(); sprays.Start = afterSpray; sprays.Prev = afterSpray - SPRAYS_PER_PAGE < 0 ? 0 : afterSpray - SPRAYS_PER_PAGE; using (var db = new SprayContext()) { long steamId64 = long.Parse(User.Identity.Name); sprays.Sprays = db.Sprays.Where(s => s.Creator.SteamId == steamId64).Where(s => s.Status != Status.DELETED).OrderByDescending(s => s.DateAdded).Skip(afterSpray).Take(SPRAYS_PER_PAGE).ToList(); } sprays.Next = sprays.Sprays.Count < SPRAYS_PER_PAGE ? afterSpray : afterSpray + SPRAYS_PER_PAGE; return View(sprays); }
public ActionResult Privatize(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.ACTIVE; db.SaveChanges(); } } return RedirectToRoute("View Spray"); } } else { return View("Error"); } }
private User CreateUser(long steamID64, SprayContext db, SteamWebAPI.SteamAPISession.User player) { //Add the user if they're new User user = new User { SteamId = steamID64, NickName = player.nickname, AvatarURI = player.avatarUrl, LastUpdated = DateTime.Now }; db.Users.Add(user); return user; }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); ViewBag.CurrentPage = "default"; ViewBag.UserName = "******"; ViewBag.AvatarUrl = ""; // TODO Default avatar URI if (Request.IsAuthenticated) { using (var db = new SprayContext()) { _baseSteamId = long.Parse(User.Identity.Name); _isLoggedIn = true; var user = db.Users.FirstOrDefault(x => x.SteamId == _baseSteamId); if (user != null) { ViewBag.UserName = user.NickName; ViewBag.AvatarUrl = user.AvatarURI; } } } }
public ActionResult Index() { DateTime lastGenerated; long totalSprays; long publishedSprays; long pendingSprays; long unlistedSprays; long privateSprays; long regularSprays; long nsfwSprays; long animatedSprays; long fadingSprays; long anonymousSprays; long loggedInSprays; List<ThingsOverTime> lastWeekSprays; long numUsers; if (cache.Contains("LastGenerated")) { lastGenerated = (DateTime)cache.Get("LastGenerated"); totalSprays = (long)cache.Get("TotalSprays"); publishedSprays = (long)cache.Get("PublishedSprays"); pendingSprays = (long)cache.Get("PendingSprays"); unlistedSprays = (long)cache.Get("UnlistedSprays"); privateSprays = (long)cache.Get("PrivateSprays"); regularSprays = (long)cache.Get("RegularSprays"); nsfwSprays = (long)cache.Get("NSFWSprays"); animatedSprays = (long)cache.Get("AnimatedSprays"); fadingSprays = (long)cache.Get("FadingSprays"); anonymousSprays = (long)cache.Get("AnonymousSprays"); loggedInSprays = (long)cache.Get("LoggedInSprays"); lastWeekSprays = (List<ThingsOverTime>)cache.Get("LastWeekSprays"); numUsers = (long)cache.Get("NumUsers"); } else { using (var db = new SprayContext()) { totalSprays = db.Sprays.LongCount(s => s.Status != Status.DELETED); anonymousSprays = db.Sprays.LongCount(s => s.Creator == null); loggedInSprays = totalSprays - anonymousSprays; publishedSprays = db.Sprays.LongCount(s => s.Status == Status.PUBLIC); pendingSprays = db.Sprays.LongCount(s => s.Status == Status.UNMODERATED); unlistedSprays = db.Sprays.LongCount(s => s.Status == Status.UNLISTED); privateSprays = totalSprays - publishedSprays - unlistedSprays - anonymousSprays; regularSprays = db.Sprays.LongCount(s => !s.NSFW && !s.Animated && !s.Fading && s.Status != Status.DELETED && s.Creator != null); nsfwSprays = db.Sprays.LongCount(s => s.NSFW && s.Status != Status.DELETED && s.Creator != null); animatedSprays = db.Sprays.LongCount(s => s.Animated && s.Status != Status.DELETED && s.Creator != null); fadingSprays = db.Sprays.LongCount(s => s.Fading && s.Status != Status.DELETED && s.Creator != null); DateTime oldestDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(30)); var a = db.Sprays.Where(s => s.DateAdded >= oldestDate).OrderBy(s => s.DateAdded).ToList(); var b = a.GroupBy(x => x.DateAdded.Date); var c = b.Select(y => new ThingsOverTime { Date = y.Key.Date, SprayCount = y.LongCount() }); lastWeekSprays = c.ToList(); numUsers = db.Users.LongCount(); } lastGenerated = DateTime.Now; // Remake the cache CacheItemPolicy slidingExpires = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(10) }; cache.Add("LastGenerated", lastGenerated, slidingExpires); cache.Add("TotalSprays", totalSprays, slidingExpires); cache.Add("PublishedSprays", publishedSprays, slidingExpires); cache.Add("PendingSprays", pendingSprays, slidingExpires); cache.Add("UnlistedSprays", unlistedSprays, slidingExpires); cache.Add("PrivateSprays", privateSprays, slidingExpires); cache.Add("RegularSprays", regularSprays, slidingExpires); cache.Add("NSFWSprays", nsfwSprays, slidingExpires); cache.Add("AnimatedSprays", animatedSprays, slidingExpires); cache.Add("FadingSprays", fadingSprays, slidingExpires); cache.Add("AnonymousSprays", anonymousSprays, slidingExpires); cache.Add("LoggedInSprays", loggedInSprays, slidingExpires); cache.Add("LastWeekSprays", lastWeekSprays, slidingExpires); cache.Add("NumUsers", numUsers, slidingExpires); } /* * Charts */ #region publishedChart Highcharts publishedChart = new Highcharts("publishedStatus") .InitChart(new Chart { PlotShadow = false }) .SetTitle(new Title { Text = "Spray Status" }) .SetSubtitle(new Subtitle { Text = "(Does not include anonymous sprays)" }) .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { AllowPointSelect = true, Cursor = Cursors.Pointer, DataLabels = new PlotOptionsPieDataLabels { Color = ColorTranslator.FromHtml("#000000"), ConnectorColor = ColorTranslator.FromHtml("#000000"), Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %'; }" } } }) .SetCredits(new Credits { Enabled = false }) .SetSeries(new Series { Type = ChartTypes.Pie, Name = "Percent of Each Status", Data = new Data(new object[] { new object[] { "Published", publishedSprays }, new object[] { "Pending Moderation", pendingSprays }, new object[] { "Unlisted", unlistedSprays }, new object[] { "Private", privateSprays } }) }); #endregion #region creatorChart Highcharts anonymousChart = new Highcharts("creatorStatus") .InitChart(new Chart { PlotShadow = false }) .SetTitle(new Title { Text = "Spray Creators" }) .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" }) .SetPlotOptions(new PlotOptions { Pie = new PlotOptionsPie { AllowPointSelect = true, Cursor = Cursors.Pointer, DataLabels = new PlotOptionsPieDataLabels { Color = ColorTranslator.FromHtml("#000000"), ConnectorColor = ColorTranslator.FromHtml("#000000"), Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %'; }" } } }) .SetCredits(new Credits { Enabled = false }) .SetSeries(new Series { Type = ChartTypes.Pie, Data = new Data(new object[] { new object[] { "Anonymous", anonymousSprays }, new object[] { "Logged In", loggedInSprays }, }) }); #endregion #region sprayTypesChart Highcharts sprayTypes = new Highcharts("sprayTypes") .InitChart(new Chart { PlotShadow = false }) .SetTitle(new Title { Text = "Spray Types" }) .SetXAxis(new XAxis { Categories = new[] { "Animated", "Fading", "NSFW", "(Plain)" }, Title = new XAxisTitle { Text = String.Empty } }) .SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = "# of Sprays", Align = AxisTitleAligns.High } }) .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" }) .SetPlotOptions(new PlotOptions { Bar = new PlotOptionsBar { DataLabels = new PlotOptionsBarDataLabels { Enabled = true, } } }) .SetLegend(new Legend { Enabled = false }) .SetCredits(new Credits { Enabled = false }) .SetSeries(new Series { Type = ChartTypes.Bar, Data = new Data(new object[] { new object[] { "Animated", animatedSprays }, new object[] { "Fading", fadingSprays }, new object[] { "NSFW", nsfwSprays }, new object[] { "(Plain)", regularSprays } }) }); #endregion #region createdChart var cats = lastWeekSprays.Select(x => x.Date.ToShortDateString()).Take(30).ToList(); cats.Add("Today (so far)"); Highcharts weeklySprayChart = new Highcharts("weeklySprays") .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line, ClassName = "chart" }) .SetTitle(new Title { Text = "Sprays Added Over the Last Month", X = -20 }) .SetXAxis(new XAxis { Categories = cats.ToArray(), Title = new XAxisTitle { Text = "Date" }, Labels = new XAxisLabels { Rotation = -45, Step = 7 }, Max = 31 }) .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "# of Sprays Created" }, PlotLines = new[] { new XAxisPlotLines { Value = 0, Width = 1, Color = ColorTranslator.FromHtml("#808080") } }, Min = 0 }) .SetTooltip(new Tooltip { Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; }" }) .SetLegend(new Legend { Enabled = false }) .SetCredits(new Credits { Enabled = false }) .SetSeries(new[] { new Series { Name = "Sprays Created", Data = new Data(lastWeekSprays.Select(x => x.SprayCount).Cast<object>().ToArray()) }, } ); #endregion Stats stats = new Stats { AnimatedSprays = animatedSprays, AnonymousSprays = anonymousSprays, FadingSprays = fadingSprays, LastGenerated = lastGenerated, LoggedInSprays = loggedInSprays, NSFWSprays = nsfwSprays, NumUsers = numUsers, PendingSprays = pendingSprays, PublishedSprays = publishedSprays, PrivateSprays = privateSprays, TotalSprays = totalSprays, UnlistedSprays = unlistedSprays, PublishedChart = publishedChart, AnonymousChart = anonymousChart, SprayTypeChart = sprayTypes, WeeklyChart = weeklySprayChart }; return View(stats); }
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(); } }
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"); }
public ActionResult Manage(int? after) { /* CHANGEME - This is my Steam ID. If I logged in, I got extra admin options */ if (!Request.IsAuthenticated || (User.Identity.Name != "76561197999489042")) return View("Error"); ViewBag.CurrentPage = "manage"; ViewBag.BrowseMode = "newest"; // Reset to 0 if negative or null int afterSpray = after ?? 0; if (afterSpray < 0) afterSpray = 0; SprayListModel sprays = new SprayListModel(); sprays.Start = afterSpray; sprays.Prev = afterSpray - SPRAYS_PER_PAGE < 0 ? 0 : afterSpray - SPRAYS_PER_PAGE; using (var db = new SprayContext()) { sprays.Sprays = db.Sprays.Where(s => s.Status == Status.UNMODERATED).OrderBy(s => s.DateAdded).Skip(afterSpray).Take(SPRAYS_PER_PAGE).ToList(); } sprays.Next = sprays.Sprays.Count < SPRAYS_PER_PAGE ? afterSpray : afterSpray + SPRAYS_PER_PAGE; return View(sprays); }
public ActionResult ViewSpray(string id) { ViewBag.CurrentPage = "browse"; Guid providedId; if (!Guid.TryParse(id, out providedId)) { return View("Error"); } Spray spray; bool saved = false; bool mine = false; using (var db = new SprayContext()) { spray = db.Sprays.Where(s => s.Id == providedId).FirstOrDefault(); if (Request.IsAuthenticated) { long steamId64 = long.Parse(User.Identity.Name); if (spray.SavedBy.Where(u => u.SteamId == steamId64).Count() != 0) saved = true; if (spray.Creator != null && spray.Creator.SteamId == steamId64) mine = true; } // Don't show unapproved sprays if (spray.Status == Status.ACTIVE && !mine) { spray = null; } } if (spray == null) return View("Error"); if(spray.Safeness == Safeness.NSFW) ViewBag.AdultAds = true; return View("View", new SprayViewModel { Spray = spray, SavedByCurrent = saved, IsCurrentUsersSpray = mine }); }
public ActionResult Unsave(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); User u = db.Users.FirstOrDefault(x => x.SteamId == steamId64); if(u.Saved.Contains(spray)){ u.Saved.Remove(spray); spray.Saves--; db.SaveChanges(); } } return RedirectToRoute("View Spray"); } } else { return View("Error"); } }