Admin auth functionally complete
This commit is contained in:
@@ -24,6 +24,18 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(DataService.GetUser(id));
|
||||
}
|
||||
|
||||
public JsonResult UsernameAvailable(string username)
|
||||
{
|
||||
var user = DataService.FindUserByUsername(username);
|
||||
return Json(user == null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public JsonResult EmailAvailable(string email)
|
||||
{
|
||||
var user = DataService.FindUserByEmail(email);
|
||||
return Json(user == null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult Create()
|
||||
{
|
||||
var vm = new CreateUserViewModel
|
||||
@@ -111,7 +123,7 @@ namespace MileageTraker.Web.Controllers
|
||||
}
|
||||
|
||||
TempData["StatusMessage"] = "Changes saved for " + user.Username;
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("Details", new { id = viewModel.UserId});
|
||||
}
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -132,7 +144,6 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// ChangePassword will throw an exception rather than return false in certain failure scenarios.
|
||||
try
|
||||
{
|
||||
DataService.UpdateUserPassword(viewModel.UserId, viewModel.NewPassword);
|
||||
@@ -149,6 +160,58 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ActionResult DisableUser(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
user.IsApproved = false;
|
||||
DataService.UpdateUser(user);
|
||||
|
||||
TempData["StatusMessage"] = user.Username + " disabled";
|
||||
|
||||
if (Request.UrlReferrer != null)
|
||||
return Redirect(Request.UrlReferrer.AbsolutePath);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult EnableUser(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
user.IsApproved = true;
|
||||
DataService.UpdateUser(user);
|
||||
|
||||
TempData["StatusMessage"] = user.Username + " enabled";
|
||||
|
||||
if (Request.UrlReferrer != null)
|
||||
return Redirect(Request.UrlReferrer.AbsolutePath);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult UnlockUser(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
user.IsLockedOut = false;
|
||||
user.PasswordFailuresSinceLastSuccess = 0;
|
||||
DataService.UpdateUser(user);
|
||||
|
||||
TempData["StatusMessage"] = user.Username + " unlocked";
|
||||
|
||||
if (Request.UrlReferrer != null)
|
||||
return Redirect(Request.UrlReferrer.AbsolutePath);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkID=177550 for
|
||||
|
||||
Reference in New Issue
Block a user