user stuff, restyled SingleQuote to not be so hideous

This commit is contained in:
tmont 2011-02-21 23:59:06 +00:00
parent 8522cf50b0
commit c4b93c46fa
28 changed files with 425 additions and 102 deletions

View File

@ -1,15 +0,0 @@
using JetBrains.Annotations;
namespace VideoGameQuotes.Api {
/// <summary>
/// Provides an interface for identifying the current user
/// </summary>
public interface ICurrentUserProvider {
/// <summary>
/// Returns the user currently performing actions on the site, or <c>null</c>
/// if the user cannot be identified
/// </summary>
[CanBeNull]
User CurrentUser { get; }
}
}

View File

@ -1,12 +1,22 @@
using System; using System;
using System.Linq;
using JetBrains.Annotations;
using Portoa.Persistence; using Portoa.Persistence;
namespace VideoGameQuotes.Api.Persistence { namespace VideoGameQuotes.Api.Persistence {
public interface IUserService { public interface IUserService {
User Save(User user); User Save(User user);
[CanBeNull]
User FindByUsername(string name); User FindByUsername(string name);
[CanBeNull]
User FindByIpAddress(string ipAddress); User FindByIpAddress(string ipAddress);
void Delete(int id);
void Ban(User user);
[CanBeNull]
User FindByUsernameOrIp(string usernameOrIp);
[NotNull]
User FindById(int id);
} }
public class UserService : IUserService { public class UserService : IUserService {
@ -30,5 +40,27 @@ namespace VideoGameQuotes.Api.Persistence {
public User FindByIpAddress(string ipAddress) { public User FindByIpAddress(string ipAddress) {
return repository.FindByIpAddress(ipAddress); return repository.FindByIpAddress(ipAddress);
} }
[UnitOfWork]
public void Delete(int id) {
repository.Delete(id);
}
[UnitOfWork]
public void Ban(User user) {
throw new NotImplementedException();
}
[UnitOfWork]
public User FindByUsernameOrIp(string usernameOrIp) {
return repository
.Records
.FirstOrDefault(user => user.Username == usernameOrIp || user.IpAddress == usernameOrIp);
}
[UnitOfWork]
public User FindById(int id) {
return repository.FindById(id);
}
} }
} }

View File

@ -24,4 +24,10 @@ namespace VideoGameQuotes.Api {
return passwordProtector.VerifyPassword(potentialPassword); return passwordProtector.VerifyPassword(potentialPassword);
} }
} }
public static class UserExtensions {
public static string GetUsernameOrIp(this User user) {
return user.Username ?? user.IpAddress;
}
}
} }

View File

@ -69,7 +69,6 @@
<Compile Include="Category.cs" /> <Compile Include="Category.cs" />
<Compile Include="CriterionHandler.cs" /> <Compile Include="CriterionHandler.cs" />
<Compile Include="Game.cs" /> <Compile Include="Game.cs" />
<Compile Include="ICurrentUserProvider.cs" />
<Compile Include="Search\IQuoteSearcher.cs" /> <Compile Include="Search\IQuoteSearcher.cs" />
<Compile Include="Search\ISearchIndexLocator.cs" /> <Compile Include="Search\ISearchIndexLocator.cs" />
<Compile Include="Search\Lucene\LuceneQuoteSearcher.cs" /> <Compile Include="Search\Lucene\LuceneQuoteSearcher.cs" />

View File

@ -1,23 +1,42 @@
using System.Web.Mvc; using System.Linq;
using System.Net;
using System.Web.Mvc;
using Portoa.Persistence; using Portoa.Persistence;
using Portoa.Web; using Portoa.Web;
using Portoa.Web.ErrorHandling; using Portoa.Web.ErrorHandling;
using Portoa.Web.Results;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
using VideoGameQuotes.Web.Models; using VideoGameQuotes.Web.Models;
using VideoGameQuotes.Web.Security; using VideoGameQuotes.Web.Security;
using VideoGameQuotes.Web.Services; using VideoGameQuotes.Web.Services;
namespace VideoGameQuotes.Web.Controllers { namespace VideoGameQuotes.Web.Controllers {
[IsValidUser(Group = UserGroup.Admin)] [VerifyUser(Group = UserGroup.Admin)]
public class AdminController : Controller { public class AdminController : Controller {
private readonly ICurrentUserProvider userProvider; private readonly ICurrentUserProvider<User> userProvider;
private readonly IAdministrationService adminService; private readonly IAdministrationService adminService;
public AdminController(ICurrentUserProvider userProvider, IAdministrationService adminService) { public AdminController(ICurrentUserProvider<User> userProvider, IAdministrationService adminService) {
this.userProvider = userProvider; this.userProvider = userProvider;
this.adminService = adminService; this.adminService = adminService;
} }
public ActionResult Users(int start = 1, int end = 20) {
if (start < 1 || start > end || end < 1) {
return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest };
}
var model = new PagedModelWithUser<User> {
Start = start,
End = end,
Records = adminService.GetPagedUsers(start, end),
TotalCount = adminService.GetAllUsers().Count(),
CurrentUser = userProvider.CurrentUser
};
return View(model);
}
[HttpGet] [HttpGet]
public ActionResult Create() { public ActionResult Create() {
var model = new CreateAdminModel(); var model = new CreateAdminModel();

View File

@ -4,6 +4,7 @@ using System.Net.Mail;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Web.Mvc; using System.Web.Mvc;
using Portoa.Web;
using Portoa.Web.Controllers; using Portoa.Web.Controllers;
using Portoa.Web.Security; using Portoa.Web.Security;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
@ -12,7 +13,7 @@ using VideoGameQuotes.Web.Models;
namespace VideoGameQuotes.Web.Controllers { namespace VideoGameQuotes.Web.Controllers {
public class HomeController : Controller { public class HomeController : Controller {
private readonly IAuthenticationService authenticationService; private readonly IAuthenticationService authenticationService;
private readonly ICurrentUserProvider userProvider; private readonly ICurrentUserProvider<User> userProvider;
private static readonly string[] answers = new[] { private static readonly string[] answers = new[] {
"I AM ERROR.", "I AM ERROR.",
@ -26,7 +27,7 @@ namespace VideoGameQuotes.Web.Controllers {
"ryu huyabasa" "ryu huyabasa"
}; };
public HomeController(IAuthenticationService authenticationService, ICurrentUserProvider userProvider) { public HomeController(IAuthenticationService authenticationService, ICurrentUserProvider<User> userProvider) {
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
this.userProvider = userProvider; this.userProvider = userProvider;
} }

View File

@ -6,6 +6,7 @@ using System.Web.Mvc;
using JetBrains.Annotations; using JetBrains.Annotations;
using Portoa.Persistence; using Portoa.Persistence;
using Portoa.Validation.DataAnnotations; using Portoa.Validation.DataAnnotations;
using Portoa.Web;
using Portoa.Web.Controllers; using Portoa.Web.Controllers;
using Portoa.Web.Results; using Portoa.Web.Results;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
@ -17,10 +18,10 @@ using VideoGameQuotes.Web.Services;
namespace VideoGameQuotes.Web.Controllers { namespace VideoGameQuotes.Web.Controllers {
public class QuoteController : Controller { public class QuoteController : Controller {
private readonly IQuoteService quoteService; private readonly IQuoteService quoteService;
private readonly ICurrentUserProvider currentUserProvider; private readonly ICurrentUserProvider<User> currentUserProvider;
private readonly IQuoteSearcher quoteSearcher; private readonly IQuoteSearcher quoteSearcher;
public QuoteController(IQuoteService quoteService, ICurrentUserProvider currentUserProvider, IQuoteSearcher quoteSearcher) { public QuoteController(IQuoteService quoteService, ICurrentUserProvider<User> currentUserProvider, IQuoteSearcher quoteSearcher) {
this.quoteService = quoteService; this.quoteService = quoteService;
this.currentUserProvider = currentUserProvider; this.currentUserProvider = currentUserProvider;
this.quoteSearcher = quoteSearcher; this.quoteSearcher = quoteSearcher;
@ -37,7 +38,7 @@ namespace VideoGameQuotes.Web.Controllers {
}); });
} }
[HttpPost, IsValidUser] [HttpPost, VerifyUser]
public JsonResult Report(ReportModel model) { public JsonResult Report(ReportModel model) {
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Invalid request")); return Json(this.CreateJsonErrorResponse("Invalid request"));
@ -48,12 +49,12 @@ namespace VideoGameQuotes.Web.Controllers {
quote.AddFlag(model.Comment, model.FlagType, currentUserProvider.CurrentUser); quote.AddFlag(model.Comment, model.FlagType, currentUserProvider.CurrentUser);
quoteService.SaveQuote(quote); quoteService.SaveQuote(quote);
return Json(this.CreateJsonResponse()); return Json(this.CreateJsonResponse());
} catch (Exception e) { } catch {
return Json(this.CreateJsonErrorResponse("Unable to create your report")); return Json(this.CreateJsonErrorResponse("Unable to create your report"));
} }
} }
[HttpPost, IsValidUser] [HttpPost, VerifyUser]
public JsonResult Vote(VoteModel model) { public JsonResult Vote(VoteModel model) {
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Invalid request")); return Json(this.CreateJsonErrorResponse("Invalid request"));
@ -89,9 +90,9 @@ namespace VideoGameQuotes.Web.Controllers {
return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest }; return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest };
} }
return View(new PagedQuoteCollectionModel { return View(new PagedModelWithUser<Quote> {
Quotes = quoteService.GetBestQuotes(start, end), Records = quoteService.GetBestQuotes(start, end),
User = currentUserProvider.CurrentUser, CurrentUser = currentUserProvider.CurrentUser,
Start = start, Start = start,
End = end End = end
}); });
@ -106,7 +107,7 @@ namespace VideoGameQuotes.Web.Controllers {
return RedirectToAction("Quote", new { id = quote.Id, text = quote.GetUrlFriendlyText() }); return RedirectToAction("Quote", new { id = quote.Id, text = quote.GetUrlFriendlyText() });
} }
[HttpPost, IsValidUser(Group = UserGroup.Admin)] [HttpPost, VerifyUser(Group = UserGroup.Admin)]
public ActionResult DismissFlag([GreaterThanZero]int quoteId, [GreaterThanZero]int flagId) { public ActionResult DismissFlag([GreaterThanZero]int quoteId, [GreaterThanZero]int flagId) {
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("quote/flag is invalid")); return Json(this.CreateJsonErrorResponse("quote/flag is invalid"));
@ -127,7 +128,7 @@ namespace VideoGameQuotes.Web.Controllers {
} }
} }
[HttpGet, IsValidUser(Group = UserGroup.Admin)] [HttpGet, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Edit(int id) { public ActionResult Edit(int id) {
try { try {
var model = new EditQuoteModel(quoteService.GetQuote(id)); var model = new EditQuoteModel(quoteService.GetQuote(id));
@ -138,19 +139,19 @@ namespace VideoGameQuotes.Web.Controllers {
} }
} }
[HttpPost, IsValidUser(Group = UserGroup.Admin)] [HttpPost, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Edit(EditQuoteModel model) { public ActionResult Edit(EditQuoteModel model) {
return CreateOrEditQuote(model, "Edit"); return CreateOrEditQuote(model, "Edit");
} }
[IsValidUser] [VerifyUser]
public ActionResult Submit() { public ActionResult Submit() {
var model = new EditQuoteModel(); var model = new EditQuoteModel();
ResetEditQuoteModel(model); ResetEditQuoteModel(model);
return View(model); return View(model);
} }
[HttpPost, IsValidUser] [HttpPost, VerifyUser]
public ActionResult Submit(EditQuoteModel model) { public ActionResult Submit(EditQuoteModel model) {
return CreateOrEditQuote(model, "Submit"); return CreateOrEditQuote(model, "Submit");
} }
@ -276,7 +277,7 @@ namespace VideoGameQuotes.Web.Controllers {
} }
} }
[IsValidUser(Group = UserGroup.Admin)] [VerifyUser(Group = UserGroup.Admin)]
public ActionResult Flags(int id) { public ActionResult Flags(int id) {
try { try {
var model = new QuoteModel { var model = new QuoteModel {
@ -290,7 +291,7 @@ namespace VideoGameQuotes.Web.Controllers {
} }
} }
[HttpPost, IsValidUser] [HttpPost, VerifyUser]
public JsonResult CreateCategory(Category category) { public JsonResult CreateCategory(Category category) {
try { try {
category = quoteService.SaveCategory(category); category = quoteService.SaveCategory(category);

View File

@ -0,0 +1,91 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Web.Mvc;
using Portoa.Persistence;
using Portoa.Validation.DataAnnotations;
using Portoa.Web.Controllers;
using Portoa.Web.Results;
using VideoGameQuotes.Api;
using VideoGameQuotes.Api.Persistence;
using VideoGameQuotes.Web.Models;
using VideoGameQuotes.Web.Security;
namespace VideoGameQuotes.Web.Controllers {
public class UserController : Controller {
private readonly IUserService userService;
public UserController(IUserService userService) {
this.userService = userService;
}
[HttpPost, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Delete([GreaterThanZero]int id) {
if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Invalid user id"));
}
try {
userService.Delete(id);
return Json(this.CreateJsonResponse());
} catch (Exception e) {
return Json(this.CreateJsonErrorResponse(e));
}
}
[HttpPost, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Ban([GreaterThanZero]int id) {
if (!ModelState.IsValid) {
return Json(this.CreateJsonErrorResponse("Invalid user id"));
}
try {
userService.Delete(id);
return Json(this.CreateJsonResponse());
} catch (Exception e) {
return Json(this.CreateJsonErrorResponse(e));
}
}
[HttpGet, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Edit([Required]string usernameOrIp) {
if (!ModelState.IsValid) {
return GetUsernameNotFoundResult(usernameOrIp);
}
var user = userService.FindByUsernameOrIp(usernameOrIp);
if (user == null) {
return GetUsernameNotFoundResult(usernameOrIp);
}
return View(new EditUserModel { Id = user.Id, Username = user.Username, IpAddress = user.IpAddress, Group = user.Group });
}
[HttpPost, VerifyUser(Group = UserGroup.Admin)]
public ActionResult Edit(EditUserModel model) {
if (!ModelState.IsValid) {
return View(model);
}
try {
var user = userService.FindById(model.Id);
user.Username = model.Username;
user.IpAddress = model.IpAddress;
user.Group = model.Group;
user = userService.Save(user);
return RedirectToAction("Edit", new { usernameOrIp = user.Username ?? user.IpAddress });
} catch (EntityNotFoundException) {
ModelState.AddModelError("Id", "Invalid user ID");
return View(model);
}
}
private ActionResult GetUsernameNotFoundResult(string usernameOrIp) {
return new StatusOverrideResult(View("InvalidUsername", new InvalidUsernameModel { UsernameOrIp = usernameOrIp })) {
StatusCode = HttpStatusCode.NotFound
};
}
}
}

View File

@ -1,10 +1,14 @@
using System.Collections.Specialized; using System;
using System.Collections.Specialized;
using System.Configuration; using System.Configuration;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing; using System.Web.Routing;
using Microsoft.Practices.Unity; using Microsoft.Practices.Unity;
using Portoa.Logging; using Portoa.Logging;
using Portoa.Web; using Portoa.Web;
using Portoa.Web.Controllers;
using Portoa.Web.ErrorHandling;
using Portoa.Web.Models; using Portoa.Web.Models;
using Portoa.Web.Security; using Portoa.Web.Security;
using Portoa.Web.Unity; using Portoa.Web.Unity;
@ -19,7 +23,7 @@ using VideoGameQuotes.Web.Security;
using VideoGameQuotes.Web.Services; using VideoGameQuotes.Web.Services;
namespace VideoGameQuotes.Web { namespace VideoGameQuotes.Web {
public class MvcApplication : MvcApplicationBase { public class MvcApplication : MvcApplicationBase<User> {
protected override void ConfigureModelBinders(ModelBinderDictionary binders) { protected override void ConfigureModelBinders(ModelBinderDictionary binders) {
binders binders
@ -37,8 +41,8 @@ namespace VideoGameQuotes.Web {
Container Container
.AddNewExtension<LogAllMethodCalls>() .AddNewExtension<LogAllMethodCalls>()
.RegisterType<ICurrentUserProvider, SessionBasedUserProvider>() .RegisterType<ICurrentUserProvider<User>, SessionBasedUserProvider>()
.RegisterType<IsValidUserAttribute>(new InjectionProperty<IsValidUserAttribute>(attr => attr.UserProvider)) .RegisterType<VerifyUserAttribute>(new InjectionProperty<VerifyUserAttribute>(attr => attr.UserProvider))
.RegisterType<IUserService, UserService>() .RegisterType<IUserService, UserService>()
.RegisterType<IAdministrationService, AdministrationService>() .RegisterType<IAdministrationService, AdministrationService>()
.RegisterType<IQuoteService, QuoteService>() .RegisterType<IQuoteService, QuoteService>()
@ -68,7 +72,11 @@ namespace VideoGameQuotes.Web {
//bullshit route so that RenderAction works //bullshit route so that RenderAction works
routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" });
routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }); routes.MapRoute("users-paged", "admin/users/{start}-{end}", new { controller = "Admin", action = "Users" }, new { start = @"\d+", end = @"\d+" });
routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" });
routes.MapRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" });
routes.MapRoute("user-default", "user/{action}/{id}", new { controller = "User", action = "delete|ban", id = UrlParameter.Optional });
routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" });
routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" });

View File

@ -0,0 +1,5 @@
namespace VideoGameQuotes.Web.Models {
public class InvalidUsernameModel {
public string UsernameOrIp { get; set; }
}
}

View File

@ -0,0 +1,8 @@
using Portoa.Web.Models;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Models {
public class PagedModelWithUser<T> : PagedModel<T> {
public User CurrentUser { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
namespace VideoGameQuotes.Web.Models {
public class PagedQuoteCollectionModel : QuoteCollectionModel {
public int Start { get; set; }
public int End { get; set; }
public int PageSize { get { return End - Start + 1; } }
public int NextStart { get { return End + 1; } }
public int NextEnd { get { return End + PageSize; } }
public int PreviousStart { get { return Math.Max(0, Start - PageSize); } }
public int PreviousEnd { get { return Math.Max(PageSize - 1, End - PageSize); } }
public bool HasPrevious { get { return Start > 0; } }
}
}

View File

@ -2,6 +2,12 @@
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Models { namespace VideoGameQuotes.Web.Models {
public class PagedUserModel {
public int Start { get; set; }
public int End { get; set; }
}
public class QuoteModel { public class QuoteModel {
[NotNull] [NotNull]
public Quote Quote { get; set; } public Quote Quote { get; set; }

View File

@ -0,0 +1,28 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Models {
public class UserModel {
public User CurrentUser { get; set; }
public User User { get; set; }
}
public class EditUserModel {
[Required]
public int Id { get; set; }
public string Username { get; set; }
[Required]
public UserGroup Group { get; set; }
public string IpAddress { get; set; }
public IEnumerable<SelectListItem> GetGroupList(UserGroup selectedGroup) {
return Enum.GetValues(typeof(UserGroup))
.Cast<UserGroup>()
.Select(group => new SelectListItem { Text = group.ToString(), Value = group.ToString()/*, Selected = group == selectedGroup*/ });
}
}
}

View File

@ -1,10 +1,11 @@
using System.Web; using System.Web;
using Portoa.Web;
using Portoa.Web.Session; using Portoa.Web.Session;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
using VideoGameQuotes.Api.Persistence; using VideoGameQuotes.Api.Persistence;
namespace VideoGameQuotes.Web.Security { namespace VideoGameQuotes.Web.Security {
public class SessionBasedUserProvider : ICurrentUserProvider { public class SessionBasedUserProvider : ICurrentUserProvider<User> {
private readonly IUserService userService; private readonly IUserService userService;
private readonly ISessionStore sessionStore; private readonly ISessionStore sessionStore;
private readonly HttpContextBase httpContext; private readonly HttpContextBase httpContext;

View File

@ -6,12 +6,12 @@ using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Security { namespace VideoGameQuotes.Web.Security {
[NeedsBuildUp] [NeedsBuildUp]
public class IsValidUserAttribute : ActionFilterAttribute { public class VerifyUserAttribute : ActionFilterAttribute {
public IsValidUserAttribute() { public VerifyUserAttribute() {
Group = UserGroup.User; Group = UserGroup.User;
} }
public ICurrentUserProvider UserProvider { get; set; } public ICurrentUserProvider<User> UserProvider { get; set; }
public UserGroup Group { get; set; } public UserGroup Group { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { public override void OnActionExecuting(ActionExecutingContext filterContext) {

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Portoa.Persistence; using Portoa.Persistence;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
@ -9,6 +10,7 @@ namespace VideoGameQuotes.Web.Services {
IEnumerable<Quote> GetFlaggedQuotes(); IEnumerable<Quote> GetFlaggedQuotes();
User GetUser(int id); User GetUser(int id);
IEnumerable<User> GetAllUsers(); IEnumerable<User> GetAllUsers();
IEnumerable<User> GetPagedUsers(int start, int end);
} }
public class AdministrationService : IAdministrationService { public class AdministrationService : IAdministrationService {
@ -42,5 +44,15 @@ namespace VideoGameQuotes.Web.Services {
public IEnumerable<User> GetAllUsers() { public IEnumerable<User> GetAllUsers() {
return userRepository.Records; return userRepository.Records;
} }
[UnitOfWork]
public IEnumerable<User> GetPagedUsers(int start, int end) {
return userRepository
.Records
.OrderBy(user => user.Username)
.ThenBy(user => user.IpAddress)
.Skip(start - 1)
.Take(end - start + 1);
}
} }
} }

View File

@ -87,24 +87,27 @@
<Compile Include="Controllers\AdminController.cs" /> <Compile Include="Controllers\AdminController.cs" />
<Compile Include="Controllers\ApiController.cs" /> <Compile Include="Controllers\ApiController.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="Models\ApiModel.cs" /> <Compile Include="Models\ApiModel.cs" />
<Compile Include="Models\BrowseModel.cs" /> <Compile Include="Models\BrowseModel.cs" />
<Compile Include="Models\BrowseModelBinder.cs" /> <Compile Include="Models\BrowseModelBinder.cs" />
<Compile Include="Models\ChangePasswordModel.cs" /> <Compile Include="Models\ChangePasswordModel.cs" />
<Compile Include="Models\CreateAdminModel.cs" /> <Compile Include="Models\CreateAdminModel.cs" />
<Compile Include="Models\InvalidUsernameModel.cs" />
<Compile Include="Models\MainMenuModel.cs" /> <Compile Include="Models\MainMenuModel.cs" />
<Compile Include="Models\QualifiedBrowseModel.cs" /> <Compile Include="Models\QualifiedBrowseModel.cs" />
<Compile Include="Models\PagedQuoteCollectionModel.cs" /> <Compile Include="Models\PagedModelWithUser.cs" />
<Compile Include="Models\QuoteCollectionModel.cs" /> <Compile Include="Models\QuoteCollectionModel.cs" />
<Compile Include="Models\QuoteFlagModel.cs" /> <Compile Include="Models\QuoteFlagModel.cs" />
<Compile Include="Models\QuoteModel.cs" /> <Compile Include="Models\QuoteModel.cs" />
<Compile Include="Models\ReportModel.cs" /> <Compile Include="Models\ReportModel.cs" />
<Compile Include="Models\SearchModel.cs" /> <Compile Include="Models\SearchModel.cs" />
<Compile Include="Models\UserModel.cs" />
<Compile Include="Models\VoteModel.cs" /> <Compile Include="Models\VoteModel.cs" />
<Compile Include="Services\AdministrationService.cs" /> <Compile Include="Services\AdministrationService.cs" />
<Compile Include="Services\FormsAuthenticationService.cs" /> <Compile Include="Services\FormsAuthenticationService.cs" />
<Compile Include="Validation\NonEmptyText.cs" /> <Compile Include="Validation\NonEmptyText.cs" />
<Compile Include="Security\IsValidUserAttribute.cs" /> <Compile Include="Security\VerifyUserAttribute.cs" />
<Compile Include="Controllers\QuoteController.cs" /> <Compile Include="Controllers\QuoteController.cs" />
<Compile Include="Services\QuoteService.cs" /> <Compile Include="Services\QuoteService.cs" />
<Compile Include="Default.aspx.cs"> <Compile Include="Default.aspx.cs">
@ -139,10 +142,12 @@
<Content Include="Views\Admin\Index.aspx" /> <Content Include="Views\Admin\Index.aspx" />
<Content Include="Views\Admin\Password.aspx" /> <Content Include="Views\Admin\Password.aspx" />
<Content Include="Views\Admin\PasswordSuccessfullyChanged.aspx" /> <Content Include="Views\Admin\PasswordSuccessfullyChanged.aspx" />
<Content Include="Views\Admin\SingleUser.ascx" />
<Content Include="Views\Admin\Users.aspx" />
<Content Include="Views\Home\About.aspx" /> <Content Include="Views\Home\About.aspx" />
<Content Include="Views\Home\Contact.aspx" /> <Content Include="Views\Home\Contact.aspx" />
<Content Include="Views\Home\ContactSuccess.aspx" /> <Content Include="Views\Home\ContactSuccess.aspx" />
<Content Include="Views\Quote\BadPaging.aspx" /> <Content Include="Views\Shared\BadPaging.aspx" />
<Content Include="Views\Quote\Best.aspx" /> <Content Include="Views\Quote\Best.aspx" />
<Content Include="Views\Quote\Edit.aspx" /> <Content Include="Views\Quote\Edit.aspx" />
<Content Include="Views\Quote\EditQuoteForm.ascx" /> <Content Include="Views\Quote\EditQuoteForm.ascx" />
@ -163,6 +168,8 @@
<Content Include="Views\Shared\RecursiveExceptionView.ascx" /> <Content Include="Views\Shared\RecursiveExceptionView.ascx" />
<Content Include="Views\Shared\SingleQuote.ascx" /> <Content Include="Views\Shared\SingleQuote.ascx" />
<Content Include="Views\Shared\Unknown.aspx" /> <Content Include="Views\Shared\Unknown.aspx" />
<Content Include="Views\User\Edit.aspx" />
<Content Include="Views\User\InvalidUsername.aspx" />
<Content Include="Web.config" /> <Content Include="Web.config" />
<Content Include="Web.Debug.config"> <Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon> <DependentUpon>Web.config</DependentUpon>

View File

@ -0,0 +1,26 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VideoGameQuotes.Web.Models.UserModel>" %>
<%@ Import Namespace="VideoGameQuotes.Api" %>
<div class="user-container">
<p>
<strong><%: Model.User.Username ?? "<no username>" %></strong>
[<em><%: Model.User.IpAddress %></em>]
</p>
<dl>
<dt>Created</dt>
<dd><%: Model.User.Created %></dd>
<dt>Group</dt>
<dd><%: Model.User.Group %></dd>
</dl>
<% if (Model.CurrentUser.Group == UserGroup.Admin) { %>
<div class="user-admin">
<%= Html.ActionLink("edit", "edit", "User", new { usernameOrIp = Model.User.Username ?? Model.User.IpAddress }, null) %> |
<%= Html.ActionLink("delete", "delete", "User", new { id = Model.User.Id }, null)%> |
<%= Html.ActionLink("ban", "ban", "User", new { id = Model.User.Id }, null)%>
</div>
<% } %>
<hr />
</div>

View File

@ -0,0 +1,19 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedModelWithUser<VideoGameQuotes.Api.User>>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="VideoGameQuotes.Web.Models" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Manage Users</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<h2>Users</h2>
<p>
<% if (Model.HasPrevious) { %>
<%= Html.ActionLink("previous", "users", new { start = Model.PreviousStart, end = Model.PreviousEnd }) %>
<% } %>
<%= Html.ActionLink("next", "users", new { start = Model.NextStart, end = Model.NextEnd }) %>
</p>
<%
foreach (var user in Model.Records) {
Html.RenderPartial("SingleUser", new UserModel { CurrentUser = Model.CurrentUser, User = user });
}
%>
</asp:Content>

View File

@ -1,4 +1,4 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedQuoteCollectionModel>" MasterPageFile="~/Views/Shared/Site.Master" %> <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedModelWithUser<VideoGameQuotes.Api.Quote>>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="VideoGameQuotes.Web.Models" %> <%@ Import Namespace="VideoGameQuotes.Web.Models" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Best: <%= Model.Start %> &ndash; <%= Model.End %></asp:Content> <asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Best: <%= Model.Start %> &ndash; <%= Model.End %></asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent"> <asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
@ -11,8 +11,8 @@
</p> </p>
<% <%
foreach (var quote in Model.Quotes) { foreach (var quote in Model.Records) {
Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.User }); Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.CurrentUser });
} }
%> %>
</asp:Content> </asp:Content>

View File

@ -1,5 +1,6 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.QuoteModel>" MasterPageFile="~/Views/Shared/Site.Master" %> <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.QuoteModel>" MasterPageFile="~/Views/Shared/Site.Master" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent"><%: Model.Quote.Game.Name %></asp:Content> <%@ Import Namespace="VideoGameQuotes.Api" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent"><%: Model.Quote.GetAbbreviatedText() %></asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent"> <asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<% Html.RenderPartial("SingleQuote", Model); %> <% Html.RenderPartial("SingleQuote", Model); %>
</asp:Content> </asp:Content>

View File

@ -19,31 +19,35 @@
</div> </div>
</div> </div>
<p class="quote-text"> <div class="quote-text">
<%: Model.Quote.Text %> <%: Model.Quote.Text %>
</p>
</div>
<div class="clearfix">
<div class="quote-links">
<a class="quote-report-link" href="#" title="report this quote as inaccurate, fake, spam, duplicate, etc.">report</a>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
| <%= Html.ActionLink("flags", "flags", "quote", new { id = Model.Quote.Id }, null) %>
| <%= Html.ActionLink("edit", "edit", "quote", new { id = Model.Quote.Id }, null) %>
<% } %>
</div> </div>
</div> </div>
<div class="quote-details"> <div class="clearfix">
<dl> <p class="quote-details-created">
<dt>Game</dt> <span title="<%: Model.Quote.Created %>">added <%: Model.Quote.GetHumanReadableTimeSinceCreated() %></span>
<dd><%= Html.ActionLink(Model.Quote.Game.Name, "browse", "Quote", new { qualifiers = "game/" + Model.Quote.Game.Id }, null) %></dd> <% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
<dt>Added</dt> by <%= Html.ActionLink(Model.Quote.Creator.GetUsernameOrIp(), "edit", "user", new { usernameOrIp = Model.Quote.Creator.GetUsernameOrIp()}, null) %>
<dd><%: Model.Quote.GetHumanReadableTimeSinceCreated() %></dd> <% } %>
<dt>Categories</dt> </p>
<dd>
<%= Model.Quote.Categories.Implode(category => Html.ActionLink(category.Name, "browse", "Quote", new { qualifiers = "category/" + category.Id }, null).ToString(), ", ")%> <p class="quote-links">
</dd> <a class="quote-report-link" href="#" title="report this quote as inaccurate, fake, spam, duplicate, etc.">report</a> |
</dl> <%= Html.ActionLink("permalink", "quote", "quote", new { id = Model.Quote.Id, text = Model.Quote.GetUrlFriendlyText() }, new { title = "permanent link to this quote" })%>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
| <%= Html.ActionLink("edit", "edit", "quote", new { id = Model.Quote.Id }, null) %>
(<%= Model.Quote.Flags.Count() %> flags)
<% } %>
</p>
</div>
<div class="quote-categories">
<ul class="menu clearfix">
<li><%= Html.ActionLink(Model.Quote.Game.Name, "browse", "Quote", new { qualifiers = "game/" + Model.Quote.Game.Id }, new { @class = "quote-game-link", title = string.Format("browse quotes from the game \"{0}\"", Model.Quote.Game.Name) }) %></li>
<% foreach (var category in Model.Quote.Categories.OrderBy(category => category.Name)) { %>
<li><%= Html.ActionLink(category.Name, "browse", "Quote", new { qualifiers = "category/" + category.Id }, new { title = string.Format("browse quotes categorized as \"{0}\"", category.Name) })%></li>
<% } %>
</ul>
</div> </div>
</div> </div>

View File

@ -1,13 +1,9 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Portoa.Web.ErrorHandling.ErrorModel>" MasterPageFile="~/Views/Shared/Site.Master" %> <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Portoa.Web.ErrorHandling.ErrorModel<VideoGameQuotes.Api.User>>" MasterPageFile="~/Views/Shared/Site.Master" %>
<asp:Content runat="server" ID="SubTitle" ContentPlaceHolderID="TitleContent">Unknown Error</asp:Content> <asp:Content runat="server" ID="SubTitle" ContentPlaceHolderID="TitleContent">Unknown Error</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent"> <asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<h2>WTF&#x2048;</h2> <h2>WTF&#x2048;</h2>
<div class="error-image">
<img src="/media/images/unknown.png" alt="BLARGH!!" title="BLARGH!!"/>
</div>
<p class="info"> <p class="info">
WTF&#x2048; How did this even happen&#x2048; WTF&#x2048; How did this even happen&#x2048;
</p> </p>

View File

@ -0,0 +1,31 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.EditUserModel>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="Portoa.Web.Util" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Edit User</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<h2>Edit User</h2>
<% using (Html.BeginForm()) { %>
<%= Html.HiddenFor(user => user.Id) %>
<p>
<%= Html.LabelFor(user => user.Username) %>
<br />
<%= Html.TextBoxFor(user => user.Username) %>
</p>
<p>
<%= Html.LabelFor(user => user.IpAddress) %>
<br />
<%= Html.TextBoxFor(user => user.IpAddress) %>
</p>
<p>
<%= Html.LabelFor(user => user.Group) %>
<br />
<%= Html.DropDownListFor(user => user.Group, Model.GetGroupList(Model.Group))%>
</p>
<%= Html.Submit("Save") %>
<% } %>
</asp:Content>

View File

@ -0,0 +1,11 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.InvalidUsernameModel>" MasterPageFile="~/Views/Shared/Site.Master" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">User Not Found</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<p>
No user exists with username or IP address &quot;<%: Model.UsernameOrIp %>&quot;.
</p>
<p>
<%= Html.ActionLink("list of users", "Users", "Admin") %>
</p>
</asp:Content>

View File

@ -1,6 +1,8 @@
.quote-container { /* box shadow stuff from http://nicolasgallagher.com/css-drop-shadows-without-images/demo/ */
width: 500px;
margin: auto; .quote-container {
width: 600px;
margin: 0 auto 50px auto;
position: relative; position: relative;
} }
@ -8,8 +10,6 @@
float: left; float: left;
font-family: Georgia, serif; font-family: Georgia, serif;
padding: 5px; padding: 5px;
color: #FFFFFF;
background-color: #6699FF;
} }
.quote-score { .quote-score {
cursor: help; cursor: help;
@ -17,19 +17,59 @@
.quote-score, .vote-container { .quote-score, .vote-container {
text-align: center; text-align: center;
} }
.vote-container {
height: 20px;
}
.quote-data {
margin-bottom: 10px;
}
.vote-for, .vote-against { .vote-for, .vote-against {
cursor: pointer; cursor: pointer;
} }
.vote-for:hover, .vote-against:hover { .vote-for:hover, .vote-against:hover {
color: #FFFF99; color: #46C46E;
} }
.quote-container .quote-data .quote-text { .quote-text {
float: left; float: left;
font-weight: bold; font-weight: bold;
font-size: 20px; font-size: 20px;
} }
.quote-score-container {
width: 40px;
font-size: 20px;
}
.quote-text {
box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
-moz-box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
-webkit-box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
background-color: #FFFFFF;
padding: 1.5em 1em;
width: 500px;
position: relative;
}
.quote-game-link {
}
.quote-categories a {
border: 1px solid #999999 !important;
background-color: #BBBBBB;
padding: 5px 8px;
display: block;
color: #FFFFFF !important;
}
.quote-categories a:hover {
background-color: #999999;
border: 1px solid #BBBBBB !important;
}
.quote-categories li {
float: left;
margin-right: 2px;
}
.quote-details-created {
float: left;
}
.quote-links { .quote-links {
float: right; float: right;
} }