@@ -3,16 +3,38 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Shortener.Models; | |||
using Teknik.Controllers; | |||
using Teknik.Models; | |||
namespace Teknik.Areas.Shortener.Controllers | |||
{ | |||
public class ShortenerController : DefaultController | |||
{ | |||
// GET: Shortener/Shortener | |||
private TeknikEntities db = new TeknikEntities(); | |||
[AllowAnonymous] | |||
public ActionResult Index() | |||
{ | |||
return View(); | |||
} | |||
[AllowAnonymous] | |||
public ActionResult RedirectToUrl(string url) | |||
{ | |||
ShortenedUrl shortUrl = db.ShortenedUrls.Where(s => s.ShortUrl == url).FirstOrDefault(); | |||
if (shortUrl != null) | |||
{ | |||
return RedirectToUrl(shortUrl.OriginalUrl); | |||
} | |||
return Redirect(Url.SubRouteUrl("error", "Error.Http404")); | |||
} | |||
[HttpPost] | |||
public ActionResult ShortenUrl(string url) | |||
{ | |||
return Json(new { result = true }); | |||
} | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Web; | |||
using Teknik.Areas.Profile.Models; | |||
namespace Teknik.Areas.Shortener.Models | |||
{ | |||
public class ShortenedUrl | |||
{ | |||
public int ShortenId { get; set; } | |||
public int? UserId { get; set; } | |||
public User User { get; set; } | |||
public string ShortUrl { get; set; } | |||
public string OriginalUrl { get; set; } | |||
public DateTime DateAdded { get; set; } | |||
} | |||
} |
@@ -29,8 +29,8 @@ namespace Teknik.Areas.Shortener | |||
"Shortener.View", // Route name | |||
new List<string>() { "dev", "*" }, // Subdomains | |||
new List<string>() { config.ShortenerConfig.ShortenerHost }, // domains | |||
"", // URL with parameters | |||
new { controller = "Shortener", action = "View" }, // Parameter defaults | |||
"{url}", // URL with parameters | |||
new { controller = "Shortener", action = "RedirectToUrl" }, // Parameter defaults | |||
new[] { typeof(Controllers.ShortenerController).Namespace } | |||
); | |||
} |
@@ -0,0 +1,12 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Web; | |||
using Teknik.ViewModels; | |||
namespace Teknik.Areas.Shortener.ViewModels | |||
{ | |||
public class ShortenViewModel : ViewModelBase | |||
{ | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
@model Teknik.Areas.Shortener.ViewModels.ShortenViewModel | |||
<div class="container"> | |||
<div class="row"> | |||
<div class="col-sm-12"> | |||
</div> | |||
</div> | |||
<div class="row"> | |||
<div class="col-sm-12 text-center"> | |||
<form class="form-horizontal" name="shortenerForm" method="post" action="@Url.SubRouteUrl("shortener", "Shortener.Action", new { action = "ShortenUrl" })"> | |||
<div class="form-group"> | |||
<div class="col-sm-10 col-sm-offset-1"> | |||
<input type="text" class="form-control" name="Url" id="url" placeholder="https://www.example.com/really/long/url"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<button type="submit" class="btn btn-primary" id="shortenSubmit">Shorten</button> | |||
</div> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
@@ -0,0 +1,3 @@ | |||
@{ | |||
Layout = "~/Views/Shared/_Layout.cshtml"; | |||
} |
@@ -9,6 +9,7 @@ using Teknik.Areas.Upload.Models; | |||
using Teknik.Areas.Paste.Models; | |||
using Teknik.Areas.Podcast.Models; | |||
using Teknik.Areas.Transparency.Models; | |||
using Teknik.Areas.Shortener.Models; | |||
namespace Teknik.Models | |||
{ | |||
@@ -39,6 +40,8 @@ namespace Teknik.Models | |||
// Transparency | |||
public DbSet<Transaction> Transactions { get; set; } | |||
public DbSet<Takedown> Takedowns { get; set; } | |||
// Url Shortener | |||
public DbSet<ShortenedUrl> ShortenedUrls { get; set; } | |||
protected override void OnModelCreating(DbModelBuilder modelBuilder) | |||
{ | |||
@@ -108,6 +111,8 @@ namespace Teknik.Models | |||
// Transparency | |||
modelBuilder.Entity<Transaction>().ToTable("Transactions"); | |||
modelBuilder.Entity<Takedown>().ToTable("Takedowns"); | |||
// Shortened Urls | |||
modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls"); | |||
base.OnModelCreating(modelBuilder); | |||
} |
@@ -208,7 +208,9 @@ | |||
<Compile Include="Areas\RSS\Controllers\RSSController.cs" /> | |||
<Compile Include="Areas\RSS\RSSAreaRegistration.cs" /> | |||
<Compile Include="Areas\Shortener\Controllers\ShortenerController.cs" /> | |||
<Compile Include="Areas\Shortener\Models\ShortenedUrl.cs" /> | |||
<Compile Include="Areas\Shortener\ShortenerAreaRegistration.cs" /> | |||
<Compile Include="Areas\Shortener\ViewModels\ShortenViewModel.cs" /> | |||
<Compile Include="Areas\Stream\Controllers\StreamController.cs" /> | |||
<Compile Include="Areas\Stream\StreamAreaRegistration.cs" /> | |||
<Compile Include="Areas\Stream\ViewModels\StreamViewModel.cs" /> | |||
@@ -479,6 +481,8 @@ | |||
<Content Include="Areas\Stream\Views\_ViewStart.cshtml" /> | |||
<Content Include="Areas\Stream\Views\Stream\Index.cshtml" /> | |||
<Content Include="Areas\Shortener\Views\web.config" /> | |||
<Content Include="Areas\Shortener\Views\_ViewStart.cshtml" /> | |||
<Content Include="Areas\Shortener\Views\Shortener\Index.cshtml" /> | |||
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" /> | |||
<None Include="Properties\PublishProfiles\Teknik Production.pubxml" /> | |||
<None Include="Scripts\jquery-2.1.4.intellisense.js" /> | |||
@@ -569,9 +573,7 @@ | |||
<Folder Include="Areas\Privacy\Models\" /> | |||
<Folder Include="Areas\Privacy\Views\Shared\" /> | |||
<Folder Include="Areas\Profile\Views\Shared\" /> | |||
<Folder Include="Areas\Shortener\Models\" /> | |||
<Folder Include="Areas\Shortener\Views\Shared\" /> | |||
<Folder Include="Areas\Shortener\Views\Shortener\" /> | |||
<Folder Include="Areas\Stream\Views\Shared\" /> | |||
<Folder Include="Areas\Transparency\Views\Shared\" /> | |||
<Folder Include="Areas\Upload\Views\Shared\" /> |