Browse Source

Added separate page for viewing service data.

Added ability to delete any service data if logged in.
core
Teknikode 3 years ago
parent
commit
93fc385f0b
  1. 2
      Teknik/Areas/Admin/Views/Admin/UploadResult.cshtml
  2. 2
      Teknik/Areas/Help/Views/Help/API/v1/Upload.cshtml
  3. 26
      Teknik/Areas/Paste/Controllers/PasteController.cs
  4. 18
      Teknik/Areas/Shortener/Controllers/ShortenerController.cs
  5. 32
      Teknik/Areas/Upload/Controllers/UploadController.cs
  6. 40
      Teknik/Areas/User/Controllers/UserController.cs
  7. 21
      Teknik/Areas/User/ViewModels/ViewServiceDataViewModel.cs
  8. 145
      Teknik/Areas/User/Views/User/ViewProfile.cshtml
  9. 157
      Teknik/Areas/User/Views/User/ViewServiceData.cshtml
  10. 3
      Teknik/Areas/User/Views/User/_LoginPartial.cshtml
  11. 4
      Teknik/Areas/Vault/Controllers/VaultController.cs
  12. 2
      Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml
  13. 36
      Teknik/Routes.cs
  14. 68
      Teknik/Scripts/User/Profile.js
  15. 54
      Teknik/Scripts/User/ViewServiceData.js
  16. 2
      Teknik/Scripts/Vault/Vault.js
  17. 7
      Teknik/bundleconfig.json

2
Teknik/Areas/Admin/Views/Admin/UploadResult.cshtml

@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
</div>
<div class="col-sm-2 text-center">
@{
string deleteUrl = (string.IsNullOrEmpty(Model.DeleteKey)) ? string.Empty : Url.SubRouteUrl("u", "Upload.Delete", new { file = Model.Url, key = Model.DeleteKey });
string deleteUrl = (string.IsNullOrEmpty(Model.DeleteKey)) ? string.Empty : Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = Model.Url, key = Model.DeleteKey });
}
<p id="delete-upload"><button role="button" class="btn btn-danger delete-upload-button" id="@deleteUrl" data-upload-id="@Model.Url">Delete</button></p>
</div>

2
Teknik/Areas/Help/Views/Help/API/v1/Upload.cshtml

@ -306,7 +306,7 @@ @@ -306,7 +306,7 @@
</td>
<td>
<strong>Optional</strong>
The deletion key for file. Use it as follows: <code>@Url.SubRouteUrl("u", "Upload.Delete", new { file = "file.jpg", key = "deletionKey" })</code>
The deletion key for file. Use it as follows: <code>@Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = "file.jpg", key = "deletionKey" })</code>
</td>
</tr>
</tbody>

26
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -181,5 +181,31 @@ namespace Teknik.Areas.Paste.Controllers @@ -181,5 +181,31 @@ namespace Teknik.Areas.Paste.Controllers
}
return View("~/Areas/Paste/Views/Paste/Index.cshtml", model);
}
[HttpPost]
public IActionResult Delete(string id)
{
Models.Paste foundPaste = _dbContext.Pastes.Where(p => p.Url == id).FirstOrDefault();
if (foundPaste != null)
{
if (foundPaste.User.Username == User.Identity.Name)
{
string filePath = foundPaste.FileName;
// Delete from the DB
_dbContext.Pastes.Remove(foundPaste);
_dbContext.SaveChanges();
// Delete the File
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
return Json(new { result = true });
}
return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
}
return Json(new { error = new { message = "This Paste does not exist" } });
}
}
}

18
Teknik/Areas/Shortener/Controllers/ShortenerController.cs

@ -76,6 +76,24 @@ namespace Teknik.Areas.Shortener.Controllers @@ -76,6 +76,24 @@ namespace Teknik.Areas.Shortener.Controllers
return Json(new { error = "Must be a valid Url" });
}
[HttpPost]
public IActionResult Delete(string id)
{
ShortenedUrl shortenedUrl = _dbContext.ShortenedUrls.Where(s => s.ShortUrl == id).FirstOrDefault();
if (shortenedUrl != null)
{
if (shortenedUrl.User.Username == User.Identity.Name)
{
_dbContext.ShortenedUrls.Remove(shortenedUrl);
_dbContext.SaveChanges();
return Json(new { result = true });
}
return Json(new { error = new { message = "You do not have permission to edit this Shortened URL" } });
}
return Json(new { error = new { message = "This Shortened URL does not exist" } });
}
[AllowAnonymous]
public IActionResult Verify()
{

32
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -125,7 +125,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -125,7 +125,7 @@ namespace Teknik.Areas.Upload.Controllers
_dbContext.SaveChanges();
}
}
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), contentType = upload.ContentType, contentLength = StringHelper.GetBytesReadable(upload.ContentLength), deleteUrl = Url.SubRouteUrl("u", "Upload.Delete", new { file = upload.Url, key = upload.DeleteKey }) } });
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }), contentType = upload.ContentType, contentLength = StringHelper.GetBytesReadable(upload.ContentLength), deleteUrl = Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = upload.Url, key = upload.DeleteKey }) } });
}
}
return Json(new { error = new { message = "Unable to upload file" } });
@ -419,7 +419,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -419,7 +419,7 @@ namespace Teknik.Areas.Upload.Controllers
[HttpGet]
[AllowAnonymous]
public IActionResult Delete(string file, string key)
public IActionResult DeleteByKey(string file, string key)
{
ViewBag.Title = "File Delete - " + file + " - " + _config.Title;
Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault();
@ -462,11 +462,37 @@ namespace Teknik.Areas.Upload.Controllers @@ -462,11 +462,37 @@ namespace Teknik.Areas.Upload.Controllers
upload.DeleteKey = delKey;
_dbContext.Entry(upload).State = EntityState.Modified;
_dbContext.SaveChanges();
return Json(new { result = new { url = Url.SubRouteUrl("u", "Upload.Delete", new { file = file, key = delKey }) } });
return Json(new { result = new { url = Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = file, key = delKey }) } });
}
return Json(new { error = new { message = "You do not own this upload" } });
}
return Json(new { error = new { message = "Invalid URL" } });
}
[HttpPost]
public IActionResult Delete(string id)
{
Models.Upload foundUpload = _dbContext.Uploads.Where(u => u.Url == id).FirstOrDefault();
if (foundUpload != null)
{
if (foundUpload.User.Username == User.Identity.Name)
{
string filePath = foundUpload.FileName;
// Delete from the DB
_dbContext.Uploads.Remove(foundUpload);
_dbContext.SaveChanges();
// Delete the File
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
return Json(new { result = true });
}
return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
}
return Json(new { error = new { message = "This Paste does not exist" } });
}
}
}

40
Teknik/Areas/User/Controllers/UserController.cs

@ -314,7 +314,45 @@ namespace Teknik.Areas.Users.Controllers @@ -314,7 +314,45 @@ namespace Teknik.Areas.Users.Controllers
}
return View(model);
}
public IActionResult ViewServiceData()
{
string username = User.Identity.Name;
ViewServiceDataViewModel model = new ViewServiceDataViewModel();
ViewBag.Title = "User Does Not Exist - " + _config.Title;
ViewBag.Description = "The User does not exist";
try
{
User user = UserHelper.GetUser(_dbContext, username);
if (user != null)
{
ViewBag.Title = "Service Data - " + _config.Title;
ViewBag.Description = "Viewing all of your service data";
model.Uploads = _dbContext.Uploads.Where(u => u.UserId == user.UserId).OrderByDescending(u => u.DateUploaded).ToList();
model.Pastes = _dbContext.Pastes.Where(u => u.UserId == user.UserId).OrderByDescending(u => u.DatePosted).ToList();
model.ShortenedUrls = _dbContext.ShortenedUrls.Where(s => s.UserId == user.UserId).OrderByDescending(s => s.DateAdded).ToList();
model.Vaults = _dbContext.Vaults.Where(v => v.UserId == user.UserId).OrderByDescending(v => v.DateCreated).ToList();
return View(model);
}
model.Error = true;
model.ErrorMessage = "The user does not exist";
}
catch (Exception ex)
{
model.Error = true;
model.ErrorMessage = ex.GetFullMessage(true);
}
return View(model);
}
public IActionResult Settings()
{
return Redirect(Url.SubRouteUrl("user", "User.ProfileSettings"));

21
Teknik/Areas/User/ViewModels/ViewServiceDataViewModel.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Teknik.ViewModels;
namespace Teknik.Areas.Users.ViewModels
{
public class ViewServiceDataViewModel : ViewModelBase
{
public DateTime LastSeen { get; set; }
public List<Upload.Models.Upload> Uploads { get; set; }
public List<Paste.Models.Paste> Pastes { get; set; }
public List<Shortener.Models.ShortenedUrl> ShortenedUrls { get; set; }
public List<Vault.Models.Vault> Vaults { get; set; }
}
}

145
Teknik/Areas/User/Views/User/ViewProfile.cshtml

@ -2,11 +2,6 @@ @@ -2,11 +2,6 @@
@using Teknik.Utilities.Cryptography
<script>
var generateDeleteKeyURL = '@Url.SubRouteUrl("u", "Upload.GenerateDeleteKey")';
var deleteVaultURL = '@Url.SubRouteUrl("v", "Vault.DeleteVault")';
</script>
<div class="container">
@if (!Model.Error)
{
@ -129,147 +124,7 @@ @@ -129,147 +124,7 @@
<div class="col-sm-9">
@if (OwnProfile)
{
<ul class="nav nav-tabs" id="myTab">
<li><a href="#about" data-toggle="tab"> About Myself </a></li>
<li><a href="#uploads" data-toggle="tab"> Uploads </a></li>
<li><a href="#pastes" data-toggle="tab"> Pastes </a></li>
<li><a href="#shortenedUrls" data-toggle="tab"> Shortened Urls </a></li>
<li><a href="#vaults" data-toggle="tab"> Vaults </a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="about">
<div class="col-sm-12" id="markdown_body">@Html.Markdown(@Model.UserSettings.About)</div>
</div><!--/tab-pane-->
@if (OwnProfile)
{
<div class="tab-pane" id="uploads" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Upload.Models.Upload upload in Model.Uploads)
{
<div class="panel panel-default">
<div class="panel-heading text-center">
<a id="upload-url" href="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url })">@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url })</a>
</div>
<div class="panel-body">
<div class="col-sm-2 text-center">
<label for="size">Size</label>
<p id="size">@StringHelper.GetBytesReadable(upload.ContentLength)</p>
</div>
<div class="col-sm-3 text-center">
<label for="type">Type</label>
<p id="type">@upload.ContentType</p>
</div>
<div class="col-sm-3 text-center">
<label for="dateUploaded">Date Uploaded</label>
<p id="dateUploaded"><time datetime="@upload.DateUploaded.ToString("s")">@upload.DateUploaded.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="downloads">Downloads</label>
<p id="downloads">@upload.Downloads</p>
</div>
<div class="col-sm-2 text-center" style="overflow-x: hidden">
@{
string deleteUrl = (string.IsNullOrEmpty(upload.DeleteKey)) ? string.Empty : Url.SubRouteUrl("u", "Upload.Delete", new { file = upload.Url, key = upload.DeleteKey });
}
<p id="delete-upload"><button role="button" class="btn btn-danger delete-upload-button" id="@deleteUrl" data-upload-id="@upload.Url">Delete</button></p>
</div>
</div>
</div>
}
</div><!--/tab-pane-->
<div class="tab-pane" id="pastes" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Paste.Models.Paste paste in Model.Pastes)
{
<div class="panel panel-default">
<div class="panel-heading text-center">
<a href="@Url.SubRouteUrl("paste", "Paste.View", new { url = paste.Url })">@(string.IsNullOrEmpty(paste.Title) ? "Untitled Paste" : paste.Title)</a>
</div>
<div class="panel-body">
<div class="col-sm-2 text-center">
<label for="syntax">Syntax</label>
<p id="syntax">@paste.Syntax</p>
</div>
<div class="col-sm-3 text-center">
<label for="datePosted">Date Posted</label>
<p id="datePosted"><time datetime="@paste.DatePosted.ToString("s")">@paste.DatePosted.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-3 text-center">
<label for="expireDate">Expire Date</label>
@{
string expireDate = "Never";
if (paste.ExpireDate != null)
{
expireDate = "<time datetime=\"" + paste.ExpireDate.Value.ToString("s") + "\">" + paste.ExpireDate.Value.ToString("MMMM dd, yyyy") + "</time>";
}
}
<p id="expireDate">@Html.Raw(expireDate)</p>
</div>
<div class="col-sm-2 text-center">
<label for="maxViews">Max Views</label>
<p id="maxViews">@paste.MaxViews</p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@paste.Views</p>
</div>
</div>
</div>
}
</div>
<div class="tab-pane" id="shortenedUrls" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Shortener.Models.ShortenedUrl url in Model.ShortenedUrls)
{
string shortUrl = string.Format("{0}://{1}/{2}", Context.Request.Scheme, Config.ShortenerConfig.ShortenerHost, url.ShortUrl);
if (Config.DevEnvironment)
{
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = url.ShortUrl });
}
<div class="panel panel-default">
<div class="panel-heading text-center">
<a href="@url.OriginalUrl">@url.OriginalUrl</a>
</div>
<div class="panel-body">
<div class="col-sm-5 text-center">
<label for="shortUrl">Short Url</label>
<p id="shortUrl"><a href="@shortUrl">@shortUrl</a></p>
</div>
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Added</label>
<p id="dateAdded"><time datetime="@url.DateAdded.ToString("s")">@url.DateAdded.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@url.Views</p>
</div>
</div>
</div>
}
</div>
<div class="tab-pane" id="vaults" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Vault.Models.Vault vault in Model.Vaults)
{
<div class="panel panel-default">
<div class="panel-heading text-center">
<a href="@Url.SubRouteUrl("v", "Vault.ViewVault", new { id = vault.Url })">@(string.IsNullOrEmpty(vault.Title) ? "Vault" : vault.Title)</a>
</div>
<div class="panel-body">
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Created</label>
<p id="dateAdded"><time datetime="@vault.DateCreated.ToString("s")">@vault.DateCreated.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Edited</label>
<p id="dateAdded"><time datetime="@vault.DateEdited.ToString("s")">@vault.DateEdited.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@vault.Views</p>
</div>
</div>
</div>
}
</div>
}
</div><!--/tab-content-->
}
else
{

157
Teknik/Areas/User/Views/User/ViewServiceData.cshtml

@ -0,0 +1,157 @@ @@ -0,0 +1,157 @@
@model Teknik.Areas.Users.ViewModels.ViewServiceDataViewModel
<script>
var deleteUploadURL = '@Url.SubRouteUrl("u", "Upload.Delete")';
var deletePasteURL = '@Url.SubRouteUrl("p", "Paste.Delete")';
var deleteShortenURL = '@Url.SubRouteUrl("s", "Shortener.Delete")';
var deleteVaultURL = '@Url.SubRouteUrl("v", "Vault.Delete")';
</script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<ul class="nav nav-tabs" id="myTab">
<li><a href="#uploads" data-toggle="tab"> Uploads </a></li>
<li><a href="#pastes" data-toggle="tab"> Pastes </a></li>
<li><a href="#shortenedUrls" data-toggle="tab"> Shortened Urls </a></li>
<li><a href="#vaults" data-toggle="tab"> Vaults </a></li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="uploads">
@foreach (Teknik.Areas.Upload.Models.Upload upload in Model.Uploads)
{
<div class="panel panel-default" id="@upload.Url">
<div class="panel-heading text-center">
<a id="upload-url" href="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url })">@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url })</a>
</div>
<div class="panel-body">
<div class="col-sm-2 text-center">
<label for="size">Size</label>
<p id="size">@StringHelper.GetBytesReadable(upload.ContentLength)</p>
</div>
<div class="col-sm-3 text-center">
<label for="type">Type</label>
<p id="type">@upload.ContentType</p>
</div>
<div class="col-sm-3 text-center">
<label for="dateUploaded">Date Uploaded</label>
<p id="dateUploaded"><time datetime="@upload.DateUploaded.ToString("s")">@upload.DateUploaded.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="downloads">Downloads</label>
<p id="downloads">@upload.Downloads</p>
</div>
<div class="col-sm-2 text-center" style="overflow-x: hidden">
<p id="delete-upload"><button role="button" class="btn btn-danger delete-upload-button" data-upload-id="@upload.Url">Delete</button></p>
</div>
</div>
</div>
}
</div><!--/tab-pane-->
<div class="tab-pane" id="pastes">
@foreach (Teknik.Areas.Paste.Models.Paste paste in Model.Pastes)
{
<div class="panel panel-default" id="@paste.Url">
<div class="panel-heading text-center">
<a href="@Url.SubRouteUrl("paste", "Paste.View", new { url = paste.Url })">@(string.IsNullOrEmpty(paste.Title) ? "Untitled Paste" : paste.Title)</a>
</div>
<div class="panel-body">
<div class="col-sm-1 text-center">
<label for="syntax">Syntax</label>
<p id="syntax">@paste.Syntax</p>
</div>
<div class="col-sm-2 text-center">
<label for="datePosted">Date Posted</label>
<p id="datePosted"><time datetime="@paste.DatePosted.ToString("s")">@paste.DatePosted.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="expireDate">Expire Date</label>
@{
string expireDate = "Never";
if (paste.ExpireDate != null)
{
expireDate = "<time datetime=\"" + paste.ExpireDate.Value.ToString("s") + "\">" + paste.ExpireDate.Value.ToString("MMMM dd, yyyy") + "</time>";
}
}
<p id="expireDate">@Html.Raw(expireDate)</p>
</div>
<div class="col-sm-2 text-center">
<label for="maxViews">Max Views</label>
<p id="maxViews">@paste.MaxViews</p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@paste.Views</p>
</div>
<div class="col-sm-1 text-center">
<p id="delete-paste"><button role="button" class="btn btn-danger delete-paste-button" data-paste-id="@paste.Url">Delete</button></p>
</div>
</div>
</div>
}
</div>
<div class="tab-pane" id="shortenedUrls">
@foreach (Teknik.Areas.Shortener.Models.ShortenedUrl url in Model.ShortenedUrls)
{
string shortUrl = string.Format("{0}://{1}/{2}", Context.Request.Scheme, Config.ShortenerConfig.ShortenerHost, url.ShortUrl);
if (Config.DevEnvironment)
{
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = url.ShortUrl });
}
<div class="panel panel-default" id="@url.ShortUrl">
<div class="panel-heading text-center">
<a href="@url.OriginalUrl">@url.OriginalUrl</a>
</div>
<div class="panel-body">
<div class="col-sm-5 text-center">
<label for="shortUrl">Short Url</label>
<p id="shortUrl"><a href="@shortUrl">@shortUrl</a></p>
</div>
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Added</label>
<p id="dateAdded"><time datetime="@url.DateAdded.ToString("s")">@url.DateAdded.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@url.Views</p>
</div>
<div class="col-sm-1 text-center">
<p id="delete-shorten"><button role="button" class="btn btn-danger delete-shorten-button" data-shorten-id="@url.ShortUrl">Delete</button></p>
</div>
</div>
</div>
}
</div>
<div class="tab-pane" id="vaults">
@foreach (Teknik.Areas.Vault.Models.Vault vault in Model.Vaults)
{
<div class="panel panel-default" id="@vault.Url">
<div class="panel-heading text-center">
<a href="@Url.SubRouteUrl("v", "Vault.ViewVault", new { id = vault.Url })">@(string.IsNullOrEmpty(vault.Title) ? "Vault" : vault.Title)</a>
</div>
<div class="panel-body">
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Created</label>
<p id="dateAdded"><time datetime="@vault.DateCreated.ToString("s")">@vault.DateCreated.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Edited</label>
<p id="dateAdded"><time datetime="@vault.DateEdited.ToString("s")">@vault.DateEdited.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="views">Views</label>
<p id="views">@vault.Views</p>
</div>
<div class="col-sm-1 text-center">
<p id="delete-vault"><button role="button" class="btn btn-danger delete-vault-button" data-vault-id="@vault.Url">Delete</button></p>
</div>
</div>
</div>
}
</div>
</div><!--/tab-content-->
</div>
</div>
</div>
<bundle src="js/user.serviceData.min.js" append-version="true"></bundle>

3
Teknik/Areas/User/Views/User/_LoginPartial.cshtml

@ -12,6 +12,9 @@ @@ -12,6 +12,9 @@
<li>
<a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = User.Identity.Name })">View Blog</a>
</li>
<li>
<a href="@Url.SubRouteUrl("user", "User.ViewServiceData")">Service Data</a>
</li>
<li>
<a href="@Url.SubRouteUrl("user", "User.Settings")">Settings</a>
</li>

4
Teknik/Areas/Vault/Controllers/VaultController.cs

@ -386,9 +386,9 @@ namespace Teknik.Areas.Vault.Controllers @@ -386,9 +386,9 @@ namespace Teknik.Areas.Vault.Controllers
}
[HttpPost]
public IActionResult DeleteVault(string url)
public IActionResult Delete(string id)
{
Vault.Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == url).FirstOrDefault();
Vault.Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == id).FirstOrDefault();
if (foundVault != null)
{
if (foundVault.User.Username == User.Identity.Name)

2
Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
var helpURL = '@Url.SubRouteUrl("help", "Help.Markdown")';
var validateItemURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = "ValidateItem" })';
var modifyVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Action", new { action = "EditVault" })';
var deleteVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.DeleteVault")';
var deleteVaultURL = '@Url.SubRouteUrl(Model.CurrentSub, "Vault.Delete")';
</script>
<div class="container">

36
Teknik/Routes.cs

@ -417,6 +417,13 @@ namespace Teknik @@ -417,6 +417,13 @@ namespace Teknik
template: "Download/{url}/{password?}",
defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" }
);
routes.MapSubdomainRoute(
name: "Paste.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "paste", "p" },
template: "Delete",
defaults: new { area = "Paste", controller = "Paste", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Paste.Action",
domains: new List<string>() { config.Host },
@ -510,6 +517,13 @@ namespace Teknik @@ -510,6 +517,13 @@ namespace Teknik
template: "",
defaults: new { area = "Shortener", controller = "Shortener", action = "Index" }
);
routes.MapSubdomainRoute(
name: "Shortener.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "shorten", "s" },
template: "Delete",
defaults: new { area = "Shortener", controller = "Shortener", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Shortener.Action",
domains: new List<string>() { config.Host },
@ -578,6 +592,13 @@ namespace Teknik @@ -578,6 +592,13 @@ namespace Teknik
template: "GenerateDeleteKey",
defaults: new { area = "Upload", controller = "Upload", action = "GenerateDeleteKey" }
);
routes.MapSubdomainRoute(
name: "Upload.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "upload", "u" },
template: "Delete",
defaults: new { area = "Upload", controller = "Upload", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Upload.Download",
domains: new List<string>() { config.Host },
@ -586,11 +607,11 @@ namespace Teknik @@ -586,11 +607,11 @@ namespace Teknik
defaults: new { area = "Upload", controller = "Upload", action = "Download" }
);
routes.MapSubdomainRoute(
name: "Upload.Delete",
name: "Upload.DeleteByKey",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "upload", "u" },
template: "{file}/{key}",
defaults: new { area = "Upload", controller = "Upload", action = "Delete" }
defaults: new { area = "Upload", controller = "Upload", action = "DeleteByKey" }
);
routes.MapSubdomainRoute(
name: "Upload.Action",
@ -708,6 +729,13 @@ namespace Teknik @@ -708,6 +729,13 @@ namespace Teknik
template: "VerifyEmail/{username}",
defaults: new { area = "User", controller = "User", action = "VerifyRecoveryEmail" }
);
routes.MapSubdomainRoute(
name: "User.ViewServiceData",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "user" },
template: "ServiceData",
defaults: new { area = "User", controller = "User", action = "ViewServiceData" }
);
routes.MapSubdomainRoute(
name: "User.ViewProfile",
domains: new List<string>() { config.Host },
@ -762,11 +790,11 @@ namespace Teknik @@ -762,11 +790,11 @@ namespace Teknik
defaults: new { area = "Vault", controller = "Vault", action = "EditVault" }
);
routes.MapSubdomainRoute(
name: "Vault.DeleteVault",
name: "Vault.Delete",
domains: new List<string>() { config.Host },
subDomains: new List<string>() { "vault", "v" },
template: "Delete",
defaults: new { area = "Vault", controller = "Vault", action = "DeleteVault" }
defaults: new { area = "Vault", controller = "Vault", action = "Delete" }
);
routes.MapSubdomainRoute(
name: "Vault.ViewVault",

68
Teknik/Scripts/User/Profile.js

@ -1,72 +1,4 @@ @@ -1,72 +1,4 @@
$(document).ready(function () {
$('.delete-upload-button').click(function () {
var deleteUrl = $(this).attr('id');
var uploadID = $(this).data('upload-id');
bootbox.confirm("Are you sure you want to delete this upload?", function (result) {
if (result) {
if (deleteUrl !== '') {
window.open(deleteUrl, '_blank');
window.location.reload();
}
else {
$.ajax({
type: "POST",
url: generateDeleteKeyURL,
data: { file: uploadID },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.open(response.result.url, '_blank');
window.location.reload();
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
}
});
});
$('.delete-vault-button').click(function () {
var vaultUrl = $(this).data('vault-url');
bootbox.confirm("Are you sure you want to delete this vault?", function (result) {
if (result) {
$.ajax({
type: "POST",
url: deleteVaultURL,
data: { url: vaultUrl },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
window.location = response.result.url;
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
});
});
$('#pgpKeyBlock').click(function () {
SelectAll('pgpKeyBlock');
});

54
Teknik/Scripts/User/ViewServiceData.js

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
$(document).ready(function () {
$('.delete-upload-button').click(function () {
var id = $(this).data('upload-id');
var element = $('#uploads [id="' + id + '"');
deleteItem(deleteUploadURL, id, element, "Are you sure you want to delete this upload?");
});
$('.delete-paste-button').click(function () {
var id = $(this).data('paste-id');
var element = $('#pastes [id="' + id + '"');
deleteItem(deletePasteURL, id, element, "Are you sure you want to delete this paste?");
});
$('.delete-shorten-button').click(function () {
var id = $(this).data('shorten-id');
var element = $('#shortenedUrls [id="' + id + '"');
deleteItem(deleteShortenURL, id, element, "Are you sure you want to delete this shortened url?");
});
$('.delete-vault-button').click(function () {
var id = $(this).data('vault-id');
var element = $('#vaults [id="' + id + '"');
deleteItem(deleteVaultURL, id, element, "Are you sure you want to delete this vault?");
});
});
function deleteItem(url, id, element, confirmationMsg) {
bootbox.confirm(confirmationMsg, function (result) {
if (result) {
$.ajax({
type: "POST",
url: url,
data: { id: id },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (response) {
if (response.result) {
element.remove();
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response) + '</div>');
}
},
error: function (response) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + parseErrorMessage(response.responseText) + '</div>');
}
});
}
});
}

2
Teknik/Scripts/Vault/Vault.js

@ -196,7 +196,7 @@ $(document).ready(function () { @@ -196,7 +196,7 @@ $(document).ready(function () {
$.ajax({
type: "POST",
url: deleteVaultURL,
data: { url: vaultUrl },
data: { id: vaultUrl },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true

7
Teknik/bundleconfig.json

@ -192,6 +192,13 @@ @@ -192,6 +192,13 @@
"./wwwroot/js/app/User/Profile.js"
]
},
{
"outputFileName": "./wwwroot/js/user.serviceData.min.js",
"inputFiles": [
"./wwwroot/lib/bootbox/js/bootbox.js",
"./wwwroot/js/app/User/ViewServiceData.js"
]
},
{
"outputFileName": "./wwwroot/js/user.reset.min.js",
"inputFiles": [

Loading…
Cancel
Save