Browse Source

Fixed exception on bad post ID for blogs.

Re-ordered pgp key on profile.
master
Teknikode 6 years ago
parent
commit
d9e9a488fe
  1. 7
      Teknik/Areas/Blog/Controllers/BlogController.cs
  2. 5
      Teknik/Areas/Blog/ViewModels/PostViewModel.cs
  3. 4
      Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml
  4. 8
      Teknik/Areas/Stream/Controllers/StreamController.cs
  5. 8
      Teknik/Areas/User/Views/User/Index.cshtml

7
Teknik/Areas/Blog/Controllers/BlogController.cs

@ -81,13 +81,14 @@ namespace Teknik.Areas.Blog.Controllers @@ -81,13 +81,14 @@ namespace Teknik.Areas.Blog.Controllers
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PostViewModel model = new PostViewModel();
// find the post specified
bool isAuth = User.IsInRole("Admin");
var post = db.BlogPosts.Include("Blog").Include("Blog.User").Where(p => (p.Blog.User.Username == username && p.BlogPostId == id) &&
(p.Published || p.Blog.User.Username == User.Identity.Name || isAuth)).FirstOrDefault();
if (post != null)
{
PostViewModel model = new PostViewModel(post);
model = new PostViewModel(post);
if (post.System)
{
@ -106,7 +107,9 @@ namespace Teknik.Areas.Blog.Controllers @@ -106,7 +107,9 @@ namespace Teknik.Areas.Blog.Controllers
}
return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", model);
}
return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", null);
model.Error = true;
model.ErrorMessage = "Blog Post does not exist.";
return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", model);
}
[HttpPost]

5
Teknik/Areas/Blog/ViewModels/PostViewModel.cs

@ -34,6 +34,11 @@ namespace Teknik.Areas.Blog.ViewModels @@ -34,6 +34,11 @@ namespace Teknik.Areas.Blog.ViewModels
public List<BlogPostComment> Comments { get; set; }
public PostViewModel()
{
}
public PostViewModel(BlogPost post)
{
BlogId = post.BlogId;

4
Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
@Scripts.Render("~/bundles/blog")
<div class="container">
@if (Model != null)
@if (!Model.Error)
{
if (User.IsInRole("Admin") || Model.Blog.User.Username == User.Identity.Name)
{
@ -148,7 +148,7 @@ else @@ -148,7 +148,7 @@ else
{
<div class="row">
<div class="col-sm-12 text-center">
<h2>That post does not exist</h2>
<h2>@Model.ErrorMessage</h2>
</div>
</div>
}

8
Teknik/Areas/Stream/Controllers/StreamController.cs

@ -22,7 +22,7 @@ namespace Teknik.Areas.Stream.Controllers @@ -22,7 +22,7 @@ namespace Teknik.Areas.Stream.Controllers
[HttpGet]
[AllowAnonymous]
public ActionResult ViewStream(int id)
public FileStreamResult ViewStream(int id)
{
try
{
@ -40,14 +40,12 @@ namespace Teknik.Areas.Stream.Controllers @@ -40,14 +40,12 @@ namespace Teknik.Areas.Stream.Controllers
return File(fileResp.GetResponseStream(), fileResp.ContentType);
}
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
}
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
catch (Exception ex)
catch (Exception)
{
return Redirect(Url.SubRouteUrl("error", "Error.Exception", new { exception = ex }));
}
return null;
}
}
}

8
Teknik/Areas/User/Views/User/Index.cshtml

@ -67,15 +67,15 @@ @@ -67,15 +67,15 @@
<div class="col-sm-3"><!--left col-->
<ul class="list-group">
<li class="list-group-item text-muted">Profile</li>
@if (!string.IsNullOrEmpty(pgpFingerprint))
{
<li class="list-group-item text-right"><span class="pull-left"><strong>Public Key</strong></span> <a href="#" data-toggle="modal" data-target="#pgpSignature">@pgpFingerprint64.AddStringAtInterval(4, " ")</a></li>
}
<li class="list-group-item text-right"><span class="pull-left"><strong>Joined</strong></span> <time datetime="@Model.LastSeen.ToString("o")">@Model.JoinDate.ToString("MMMM dd, yyyy")</time></li>
@if (OwnProfile && User.Identity.IsAuthenticated)
{
<li class="list-group-item text-right"><span class="pull-left"><strong>Last Seen</strong></span> <time datetime="@Model.LastSeen.ToString("o")">@Model.LastSeen.ToString("MMMM dd, yyyy")</time></li>
}
@if (!string.IsNullOrEmpty(pgpFingerprint))
{
<li class="list-group-item text-right"><span class="pull-left"><strong>Public Key</strong></span> <a href="#" data-toggle="modal" data-target="#pgpSignature">@pgpFingerprint64.AddStringAtInterval(4, " ")</a></li>
}
@if (!string.IsNullOrEmpty(Model.Email))
{
<li class="list-group-item text-right"><span class="pull-left"><strong>Email</strong></span> <a href="mailto:@Model.Email">@Model.Email</a></li>

Loading…
Cancel
Save