BuildFeed/Areas/admin/Controllers/usersController.cs

86 lines
2.5 KiB
C#
Raw Normal View History

2015-03-22 03:29:21 +08:00
using RedisAuth;
using System;
2014-10-11 06:57:02 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace BuildFeed.Areas.admin.Controllers
{
2014-12-16 22:43:26 +08:00
[Authorize(Roles = "Administrators")]
2014-10-11 06:57:02 +08:00
public class usersController : Controller
{
// GET: admin/users
public ActionResult index()
2014-10-11 06:57:02 +08:00
{
return View(Membership.GetAllUsers().Cast<MembershipUser>().OrderByDescending(m => m.IsApproved).ThenBy(m => m.UserName));
2014-10-11 06:57:02 +08:00
}
2014-12-16 22:43:26 +08:00
public ActionResult admins()
{
List<MembershipUser> admins = new List<MembershipUser>();
2015-05-03 23:47:04 +08:00
foreach (var m in Roles.GetUsersInRole("Administrators"))
2014-12-16 22:43:26 +08:00
{
admins.Add(Membership.GetUser(m));
}
return View(admins.OrderByDescending(m => m.UserName));
}
public ActionResult promote(string id)
{
Roles.AddUserToRole(id, "Administrators");
return RedirectToAction("Index");
}
public ActionResult demote(string id)
{
Roles.RemoveUserFromRole(id, "Administrators");
return RedirectToAction("Index");
}
public ActionResult approve(Guid id)
2014-10-11 06:57:02 +08:00
{
var provider = (Membership.Provider as RedisMembershipProvider);
provider.ChangeApproval(id, true);
return RedirectToAction("Index");
}
public ActionResult unapprove(Guid id)
2014-10-11 06:57:02 +08:00
{
var provider = (Membership.Provider as RedisMembershipProvider);
provider.ChangeApproval(id, false);
return RedirectToAction("Index");
}
public ActionResult @lock(Guid id)
{
var provider = (Membership.Provider as RedisMembershipProvider);
provider.ChangeLockStatus(id, true);
return RedirectToAction("Index");
}
public ActionResult unlock(Guid id)
{
var provider = (Membership.Provider as RedisMembershipProvider);
provider.ChangeLockStatus(id, false);
return RedirectToAction("Index");
}
2015-05-03 23:47:04 +08:00
public ActionResult cleanup()
{
var users = Membership.GetAllUsers();
foreach (MembershipUser user in users)
{
if(!user.IsApproved && (user.CreationDate.AddDays(30) < DateTime.Now))
{
Membership.DeleteUser(user.UserName);
}
}
return RedirectToAction("index");
}
2014-10-11 06:57:02 +08:00
}
}