vgquotes/Src/VideoGameQuotes.Web/Controllers/AdminController.cs

57 lines
1.4 KiB
C#
Raw Normal View History

using System.Web.Mvc;
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);
}
}
[HttpGet]
public ActionResult Flags() {
var flaggedQuotes = adminService.GetFlaggedQuotes();
return View(flaggedQuotes);
}
}
}