2011-02-19 09:41:09 +00:00
|
|
|
|
using System.Web.Mvc;
|
2011-02-17 20:55:47 +00:00
|
|
|
|
using Portoa.Web;
|
|
|
|
|
using Portoa.Web.ErrorHandling;
|
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
using VideoGameQuotes.Web.Models;
|
|
|
|
|
using VideoGameQuotes.Web.Security;
|
|
|
|
|
using VideoGameQuotes.Web.Services;
|
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web.Controllers {
|
|
|
|
|
[IsValidUser(Group = UserGroup.Admin)]
|
|
|
|
|
public class AdminController : Controller {
|
|
|
|
|
private readonly ICurrentUserProvider userProvider;
|
|
|
|
|
private readonly IAdministrationService adminService;
|
|
|
|
|
|
|
|
|
|
public AdminController(ICurrentUserProvider userProvider, IAdministrationService adminService) {
|
|
|
|
|
this.userProvider = userProvider;
|
|
|
|
|
this.adminService = adminService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index() {
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ActionResult Password() {
|
|
|
|
|
return View(new ChangePasswordModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Password(ChangePasswordModel model) {
|
|
|
|
|
if (!ModelState.IsValid) {
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = userProvider.CurrentUser;
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return View("Unknown", new ErrorModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
user.ChangePassword(model.Password);
|
|
|
|
|
adminService.SaveUser(user);
|
|
|
|
|
return View("PasswordSuccessfullyChanged");
|
|
|
|
|
} catch {
|
|
|
|
|
ControllerContext.AddModelError("password", "Unable to change password");
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2011-02-18 01:46:02 +00:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ActionResult Flags() {
|
|
|
|
|
var flaggedQuotes = adminService.GetFlaggedQuotes();
|
|
|
|
|
return View(flaggedQuotes);
|
|
|
|
|
}
|
2011-02-17 20:55:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|