1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Added download action tracking to uploads/pastes/rss

This commit is contained in:
Uncled1023 2016-06-16 13:00:00 -07:00
parent 8348d53e04
commit 77aa0fe8bc
7 changed files with 28 additions and 25 deletions

View File

@ -520,15 +520,15 @@ Thank you for your continued use of Teknik!
bool noData = true; bool noData = true;
// Any blog comments? // Any blog comments?
var blogCom = db.BlogComments.Include("Users").Where(c => c.UserId == user.UserId); var blogCom = db.BlogComments.Where(c => c.UserId == user.UserId);
noData &= !(blogCom != null && blogCom.Any()); noData &= !(blogCom != null && blogCom.Any());
// Any blog posts? // Any blog posts?
var blogPosts = db.BlogPosts.Include("Blog").Include("Blog.Users").Where(p => p.Blog.UserId == user.UserId); var blogPosts = db.BlogPosts.Where(p => p.Blog.UserId == user.UserId);
noData &= !(blogPosts != null && blogPosts.Any()); noData &= !(blogPosts != null && blogPosts.Any());
// Any podcast comments? // Any podcast comments?
var podCom = db.PodcastComments.Include("Users").Where(p => p.UserId == user.UserId); var podCom = db.PodcastComments.Where(p => p.UserId == user.UserId);
noData &= !(podCom != null && podCom.Any()); noData &= !(podCom != null && podCom.Any());
// Any email? // Any email?

View File

@ -27,7 +27,7 @@ namespace Teknik.Areas.Home.Controllers
List<BlogPost> lastSite = new List<BlogPost>(); List<BlogPost> lastSite = new List<BlogPost>();
if (db.BlogPosts.Count() > 0) if (db.BlogPosts.Count() > 0)
{ {
var foundSite = db.BlogPosts.Include("Blog").Include("Blog.User").OrderByDescending(post => post.DatePosted).Where(p => p.Published && p.System).Take(5); var foundSite = db.BlogPosts.OrderByDescending(post => post.DatePosted).Where(p => p.Published && p.System).Take(5);
if (foundSite != null) if (foundSite != null)
lastSite = foundSite.ToList(); lastSite = foundSite.ToList();
} }
@ -35,7 +35,7 @@ namespace Teknik.Areas.Home.Controllers
List<BlogPost> lastPosts = new List<BlogPost>(); List<BlogPost> lastPosts = new List<BlogPost>();
if (db.BlogPosts.Count() > 0) if (db.BlogPosts.Count() > 0)
{ {
var foundPosts = db.BlogPosts.Include("Blog").Include("Blog.User").OrderByDescending(post => post.DatePosted).Where(p => p.Published && !p.System).Take(5); var foundPosts = db.BlogPosts.OrderByDescending(post => post.DatePosted).Where(p => p.Published && !p.System).Take(5);
if (foundPosts != null) if (foundPosts != null)
lastPosts = foundPosts.ToList(); lastPosts = foundPosts.ToList();
} }

View File

@ -30,7 +30,7 @@ namespace Teknik.Areas.Paste.Controllers
return View(model); return View(model);
} }
[TrackPageView] [TrackDownload]
[AllowAnonymous] [AllowAnonymous]
public ActionResult ViewPaste(string type, string url, string password) public ActionResult ViewPaste(string type, string url, string password)
{ {

View File

@ -26,6 +26,7 @@ namespace Teknik.Areas.RSS.Controllers
return new RssResult(feed); return new RssResult(feed);
} }
[TrackDownload]
[AllowAnonymous] [AllowAnonymous]
public ActionResult Blog(string username) public ActionResult Blog(string username)
{ {
@ -37,12 +38,12 @@ namespace Teknik.Areas.RSS.Controllers
bool isSystem = string.IsNullOrEmpty(username); bool isSystem = string.IsNullOrEmpty(username);
if (isSystem) if (isSystem)
{ {
blog = db.Blogs.Include("BlogPosts").Include("User").Where(b => b.BlogId == Config.BlogConfig.ServerBlogId).FirstOrDefault(); blog = db.Blogs.Where(b => b.BlogId == Config.BlogConfig.ServerBlogId).FirstOrDefault();
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog"); blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
} }
else else
{ {
blog = db.Blogs.Include("BlogPosts").Include("User").Where(b => b.User.Username == username).FirstOrDefault(); blog = db.Blogs.Where(b => b.User.Username == username).FirstOrDefault();
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog", new { username = username }); blogUrl = Url.SubRouteUrl("blog", "Blog.Blog", new { username = username });
} }
if (blog != null) if (blog != null)
@ -83,11 +84,12 @@ namespace Teknik.Areas.RSS.Controllers
return new RssResult(badFeed); return new RssResult(badFeed);
} }
[TrackDownload]
[AllowAnonymous] [AllowAnonymous]
public ActionResult Podcast() public ActionResult Podcast()
{ {
List<SyndicationItem> items = new List<SyndicationItem>(); List<SyndicationItem> items = new List<SyndicationItem>();
List<Podcast.Models.Podcast> podcasts = db.Podcasts.Include("Files").Where(p => p.Published).ToList(); List<Podcast.Models.Podcast> podcasts = db.Podcasts.Where(p => p.Published).ToList();
if (podcasts != null) if (podcasts != null)
{ {
foreach (Podcast.Models.Podcast podcast in podcasts) foreach (Podcast.Models.Podcast podcast in podcasts)

View File

@ -142,6 +142,7 @@ namespace Teknik.Areas.Upload.Controllers
// User did not supply key // User did not supply key
[HttpGet] [HttpGet]
[TrackDownload]
[AllowAnonymous] [AllowAnonymous]
public ActionResult Download(string file) public ActionResult Download(string file)
{ {

View File

@ -254,7 +254,7 @@ namespace Teknik.Areas.Users.Utility
try try
{ {
// Update uploads // Update uploads
List<Upload.Models.Upload> uploads = db.Uploads.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<Upload.Models.Upload> uploads = db.Uploads.Where(u => u.User.Username == user.Username).ToList();
if (uploads != null) if (uploads != null)
{ {
foreach (Upload.Models.Upload upload in uploads) foreach (Upload.Models.Upload upload in uploads)
@ -265,7 +265,7 @@ namespace Teknik.Areas.Users.Utility
} }
// Update pastes // Update pastes
List<Paste.Models.Paste> pastes = db.Pastes.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<Paste.Models.Paste> pastes = db.Pastes.Where(u => u.User.Username == user.Username).ToList();
if (pastes != null) if (pastes != null)
{ {
foreach (Paste.Models.Paste paste in pastes) foreach (Paste.Models.Paste paste in pastes)
@ -276,7 +276,7 @@ namespace Teknik.Areas.Users.Utility
} }
// Update shortened urls // Update shortened urls
List<ShortenedUrl> shortUrls = db.ShortenedUrls.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<ShortenedUrl> shortUrls = db.ShortenedUrls.Where(u => u.User.Username == user.Username).ToList();
if (shortUrls != null) if (shortUrls != null)
{ {
foreach (ShortenedUrl shortUrl in shortUrls) foreach (ShortenedUrl shortUrl in shortUrls)
@ -287,14 +287,14 @@ namespace Teknik.Areas.Users.Utility
} }
// Delete Blogs // Delete Blogs
Blog.Models.Blog blog = db.Blogs.Include("BlogPosts").Include("BlogPosts.Comments").Include("User").Where(u => u.User.Username == user.Username).FirstOrDefault(); Blog.Models.Blog blog = db.Blogs.Where(u => u.User.Username == user.Username).FirstOrDefault();
if (blog != null) if (blog != null)
{ {
db.Blogs.Remove(blog); db.Blogs.Remove(blog);
} }
// Delete post comments // Delete post comments
List<BlogPostComment> postComments = db.BlogComments.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<BlogPostComment> postComments = db.BlogComments.Where(u => u.User.Username == user.Username).ToList();
if (postComments != null) if (postComments != null)
{ {
foreach (BlogPostComment postComment in postComments) foreach (BlogPostComment postComment in postComments)
@ -304,7 +304,7 @@ namespace Teknik.Areas.Users.Utility
} }
// Delete podcast comments // Delete podcast comments
List<Podcast.Models.PodcastComment> podComments = db.PodcastComments.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<Podcast.Models.PodcastComment> podComments = db.PodcastComments.Where(u => u.User.Username == user.Username).ToList();
if (podComments != null) if (podComments != null)
{ {
foreach (Podcast.Models.PodcastComment podComment in podComments) foreach (Podcast.Models.PodcastComment podComment in podComments)
@ -314,7 +314,7 @@ namespace Teknik.Areas.Users.Utility
} }
// Delete Recovery Email Verifications // Delete Recovery Email Verifications
List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Include("User").Where(r => r.User.Username == user.Username).ToList(); List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Where(r => r.User.Username == user.Username).ToList();
if (verCodes != null) if (verCodes != null)
{ {
foreach (RecoveryEmailVerification verCode in verCodes) foreach (RecoveryEmailVerification verCode in verCodes)
@ -324,7 +324,7 @@ namespace Teknik.Areas.Users.Utility
} }
// Delete Password Reset Verifications // Delete Password Reset Verifications
List<ResetPasswordVerification> verPass = db.ResetPasswordVerifications.Include("User").Where(r => r.User.Username == user.Username).ToList(); List<ResetPasswordVerification> verPass = db.ResetPasswordVerifications.Where(r => r.User.Username == user.Username).ToList();
if (verPass != null) if (verPass != null)
{ {
foreach (ResetPasswordVerification ver in verPass) foreach (ResetPasswordVerification ver in verPass)
@ -346,7 +346,7 @@ namespace Teknik.Areas.Users.Utility
public static string CreateRecoveryEmailVerification(TeknikEntities db, Config config, User user) public static string CreateRecoveryEmailVerification(TeknikEntities db, Config config, User user)
{ {
// Check to see if there already is a verification code for the user // Check to see if there already is a verification code for the user
List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Include("User").Where(r => r.User.Username == user.Username).ToList(); List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Where(r => r.User.Username == user.Username).ToList();
if (verCodes != null && verCodes.Any()) if (verCodes != null && verCodes.Any())
{ {
foreach (RecoveryEmailVerification verCode in verCodes) foreach (RecoveryEmailVerification verCode in verCodes)
@ -402,11 +402,11 @@ Thank you and enjoy!
public static bool VerifyRecoveryEmail(TeknikEntities db, Config config, string username, string code) public static bool VerifyRecoveryEmail(TeknikEntities db, Config config, string username, string code)
{ {
User user = GetUser(db, username); User user = GetUser(db, username);
RecoveryEmailVerification verCode = db.RecoveryEmailVerifications.Include("User").Where(r => r.User.Username == username && r.Code == code).FirstOrDefault(); RecoveryEmailVerification verCode = db.RecoveryEmailVerifications.Where(r => r.User.Username == username && r.Code == code).FirstOrDefault();
if (verCode != null) if (verCode != null)
{ {
// We have a match, so clear out the verifications for that user // We have a match, so clear out the verifications for that user
List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Include("User").Where(r => r.User.Username == username).ToList(); List<RecoveryEmailVerification> verCodes = db.RecoveryEmailVerifications.Where(r => r.User.Username == username).ToList();
if (verCodes != null && verCodes.Any()) if (verCodes != null && verCodes.Any())
{ {
foreach (RecoveryEmailVerification ver in verCodes) foreach (RecoveryEmailVerification ver in verCodes)
@ -427,7 +427,7 @@ Thank you and enjoy!
public static string CreateResetPasswordVerification(TeknikEntities db, Config config, User user) public static string CreateResetPasswordVerification(TeknikEntities db, Config config, User user)
{ {
// Check to see if there already is a verification code for the user // Check to see if there already is a verification code for the user
List<ResetPasswordVerification> verCodes = db.ResetPasswordVerifications.Include("User").Where(r => r.User.Username == user.Username).ToList(); List<ResetPasswordVerification> verCodes = db.ResetPasswordVerifications.Where(r => r.User.Username == user.Username).ToList();
if (verCodes != null && verCodes.Any()) if (verCodes != null && verCodes.Any())
{ {
foreach (ResetPasswordVerification verCode in verCodes) foreach (ResetPasswordVerification verCode in verCodes)
@ -479,11 +479,11 @@ If you recieved this email and you did not reset your password, you can ignore t
public static bool VerifyResetPassword(TeknikEntities db, Config config, string username, string code) public static bool VerifyResetPassword(TeknikEntities db, Config config, string username, string code)
{ {
User user = GetUser(db, username); User user = GetUser(db, username);
ResetPasswordVerification verCode = db.ResetPasswordVerifications.Include("User").Where(r => r.User.Username == username && r.Code == code).FirstOrDefault(); ResetPasswordVerification verCode = db.ResetPasswordVerifications.Where(r => r.User.Username == username && r.Code == code).FirstOrDefault();
if (verCode != null) if (verCode != null)
{ {
// We have a match, so clear out the verifications for that user // We have a match, so clear out the verifications for that user
List<ResetPasswordVerification> verCodes = db.ResetPasswordVerifications.Include("User").Where(r => r.User.Username == username).ToList(); List<ResetPasswordVerification> verCodes = db.ResetPasswordVerifications.Where(r => r.User.Username == username).ToList();
if (verCodes != null && verCodes.Any()) if (verCodes != null && verCodes.Any())
{ {
foreach (ResetPasswordVerification ver in verCodes) foreach (ResetPasswordVerification ver in verCodes)

View File

@ -80,7 +80,7 @@ namespace Teknik
using (TeknikEntities entities = new TeknikEntities()) using (TeknikEntities entities = new TeknikEntities())
{ {
User user = entities.Users.Include("Groups").Include("Groups.Roles").SingleOrDefault(u => u.Username == username); User user = entities.Users.SingleOrDefault(u => u.Username == username);
if (user != null) if (user != null)
{ {