* flagged quote admin page
* fixed issue in user provider where if the app restarts you're still logged in but the app doesn't recognize you as such
This commit is contained in:
parent
99cb4defbe
commit
0dd343cc06
@ -126,6 +126,15 @@ namespace VideoGameQuotes.Api {
|
||||
return text.Substring(0, Math.Min(text.Length, 50));
|
||||
}
|
||||
|
||||
public static string GetAbbreviatedText(this Quote quote) {
|
||||
if (quote.Text.Length < 100) {
|
||||
return quote.Text;
|
||||
}
|
||||
|
||||
//ellipses ftw
|
||||
return quote.Text.Substring(0, 100) + Char.ConvertFromUtf32(0x2026);
|
||||
}
|
||||
|
||||
public static string GetHumanReadableTimeSinceCreated(this Quote quote) {
|
||||
var timespan = DateTime.UtcNow.Subtract(quote.Created);
|
||||
if (timespan.TotalDays >= 365) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Portoa.Web;
|
||||
using Portoa.Web.ErrorHandling;
|
||||
using VideoGameQuotes.Api;
|
||||
@ -50,5 +51,11 @@ namespace VideoGameQuotes.Web.Controllers {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Flags() {
|
||||
var flaggedQuotes = adminService.GetFlaggedQuotes();
|
||||
return View(flaggedQuotes);
|
||||
}
|
||||
}
|
||||
}
|
9
Src/VideoGameQuotes.Web/Models/QuoteFlagModel.cs
Normal file
9
Src/VideoGameQuotes.Web/Models/QuoteFlagModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace VideoGameQuotes.Web.Models {
|
||||
public class QuoteFlagModel {
|
||||
public int FlagCount { get; set; }
|
||||
public string AbbreviatedText { get; set; }
|
||||
public string UrlSafeText { get; set; }
|
||||
public int QuoteId { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -20,20 +20,25 @@ namespace VideoGameQuotes.Web.Security {
|
||||
var user = sessionStore["user"] as User;
|
||||
|
||||
if (user == null) {
|
||||
//identify user by IP address
|
||||
var ipAddress = httpContext.Request.UserHostAddress;
|
||||
if (string.IsNullOrEmpty(ipAddress)) {
|
||||
return null;
|
||||
}
|
||||
//if we're logged in, then use the authenticated user (this inconsistency between cookie/session occurs when the app restarts)
|
||||
if (httpContext.Request.IsAuthenticated) {
|
||||
user = userService.FindByUsername(httpContext.User.Identity.Name);
|
||||
} else {
|
||||
//identify user by IP address
|
||||
var ipAddress = httpContext.Request.UserHostAddress;
|
||||
if (string.IsNullOrEmpty(ipAddress)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
user = userService.FindByIpAddress(ipAddress);
|
||||
if (user == null) {
|
||||
user = new User {
|
||||
IpAddress = ipAddress,
|
||||
Group = UserGroup.User
|
||||
};
|
||||
user = userService.FindByIpAddress(ipAddress);
|
||||
if (user == null) {
|
||||
user = new User {
|
||||
IpAddress = ipAddress,
|
||||
Group = UserGroup.User
|
||||
};
|
||||
|
||||
user = userService.Save(user);
|
||||
user = userService.Save(user);
|
||||
}
|
||||
}
|
||||
|
||||
sessionStore["user"] = user;
|
||||
|
@ -1,22 +1,35 @@
|
||||
using Portoa.Persistence;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Portoa.Persistence;
|
||||
using VideoGameQuotes.Api;
|
||||
using VideoGameQuotes.Api.Persistence;
|
||||
|
||||
namespace VideoGameQuotes.Web.Services {
|
||||
public interface IAdministrationService {
|
||||
User SaveUser(User user);
|
||||
IEnumerable<Quote> GetFlaggedQuotes();
|
||||
}
|
||||
|
||||
public class AdministrationService : IAdministrationService {
|
||||
private readonly IUserRepository userRepository;
|
||||
private readonly IRepository<User> userRepository;
|
||||
private readonly IRepository<Quote> quoteRepository;
|
||||
|
||||
public AdministrationService(IUserRepository userRepository) {
|
||||
public AdministrationService(IRepository<User> userRepository, IRepository<Quote> quoteRepository) {
|
||||
this.userRepository = userRepository;
|
||||
this.quoteRepository = quoteRepository;
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public User SaveUser(User user) {
|
||||
return userRepository.Save(user);
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public IEnumerable<Quote> GetFlaggedQuotes() {
|
||||
return quoteRepository.Records
|
||||
.Where(quote => quote.Flags.Any())
|
||||
.ToArray()
|
||||
.OrderByDescending(quote => quote.Flags.Count());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@
|
||||
<Compile Include="Models\QualifiedBrowseModel.cs" />
|
||||
<Compile Include="Models\PagedQuoteCollectionModel.cs" />
|
||||
<Compile Include="Models\QuoteCollectionModel.cs" />
|
||||
<Compile Include="Models\QuoteFlagModel.cs" />
|
||||
<Compile Include="Models\QuoteModel.cs" />
|
||||
<Compile Include="Models\ReportModel.cs" />
|
||||
<Compile Include="Models\SearchModel.cs" />
|
||||
@ -130,6 +131,8 @@
|
||||
<Content Include="media\images\search.png" />
|
||||
<Content Include="media\js\jquery.cookie.js" />
|
||||
<Content Include="media\js\vgquotes.js" />
|
||||
<Content Include="Views\Admin\FlaggedQuote.ascx" />
|
||||
<Content Include="Views\Admin\Flags.aspx" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Views\Admin\Password.aspx" />
|
||||
<Content Include="Views\Admin\PasswordSuccessfullyChanged.aspx" />
|
||||
|
10
Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx
Normal file
10
Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx
Normal file
@ -0,0 +1,10 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VideoGameQuotes.Api.Quote>" %>
|
||||
<%@ Import Namespace="VideoGameQuotes.Api" %>
|
||||
|
||||
<div class="flagged-quote">
|
||||
<span class="flag-count"><%: Model.Flags.Count() %></span>
|
||||
|
||||
<p>
|
||||
<%= Html.ActionLink(Model.GetAbbreviatedText(), "quote", "quote", new { id = Model.Id, text = Model.GetUrlFriendlyText() }, null) %>
|
||||
</p>
|
||||
</div>
|
12
Src/VideoGameQuotes.Web/Views/Admin/Flags.aspx
Normal file
12
Src/VideoGameQuotes.Web/Views/Admin/Flags.aspx
Normal file
@ -0,0 +1,12 @@
|
||||
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<VideoGameQuotes.Api.Quote>>" MasterPageFile="~/Views/Shared/Site.Master" %>
|
||||
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Quote Flags</asp:Content>
|
||||
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
|
||||
<h2>Flagged Quotes</h2>
|
||||
|
||||
<%
|
||||
foreach (var quote in Model) {
|
||||
Html.RenderPartial("FlaggedQuote", quote);
|
||||
}
|
||||
%>
|
||||
|
||||
</asp:Content>
|
@ -6,7 +6,7 @@
|
||||
<ul>
|
||||
<li><%= Html.ActionLink("Create admin", "create", "admin") %></li>
|
||||
<li><%= Html.ActionLink("Change password", "password", "admin") %></li>
|
||||
<li><%= Html.ActionLink("View reports", "reports", "admin") %></li>
|
||||
<li><%= Html.ActionLink("View quote flags", "flags", "admin") %></li>
|
||||
<li><%= Html.ActionLink("Manage users", "users", "admin") %></li>
|
||||
</ul>
|
||||
</asp:Content>
|
Loading…
Reference in New Issue
Block a user