Admin controller supports generation of new users.

This commit is contained in:
Michael 2017-03-24 20:31:57 -04:00
parent 5253e1544b
commit 7206bca7d4
2 changed files with 58 additions and 0 deletions

View file

@ -55,6 +55,56 @@ public void DeleteCategoryRecursive(ForumCategory start)
}
public ActionResult CreateUser()
{
return View(new CreateUserModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateUser(CreateUserModel model)
{
var db = new ApplicationDbContext();
var user = new ApplicationUser();
user.AccessFailedCount = 0;
user.BannedAt = DateTime.Now;
user.Bio = "";
user.Codepoints = 0;
user.DisplayName = model.Username;
user.Email = model.Email;
user.EmailConfirmed = true;
user.FullName = "";
user.Hobbies = "";
user.Id = Guid.NewGuid().ToString();
user.IsBanned = false;
user.IsMuted = false;
user.IsPatreon = false;
user.JoinedAt = DateTime.Now;
user.LastKnownIPAddress = "127.0.0.1";
user.LastLogin = DateTime.Now;
user.LastMonthPaid = 0;
user.LockoutEnabled = false;
user.MajorVersion = 1;
user.MinorVersion = 0;
user.MutedAt = DateTime.Now;
user.PasswordHash = "ResetYourPassword.";
user.PhoneNumberConfirmed = false;
user.Revision = 0;
user.SecurityStamp = Guid.NewGuid().ToString();
user.ShiftnetSubscription = 0;
user.StoryPosition = 0;
user.TwoFactorEnabled = false;
user.UserName = model.Email;
db.Users.Add(user);
db.SaveChanges();
var uman = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
uman.AddToRole(user.Id, ACL.LowestPriorityRole().Name);
return RedirectToAction("Users");
}
public void DeleteTopic(ForumTopic topic)
{
foreach(var post in topic.Posts.ToArray())

View file

@ -28,6 +28,14 @@ public AdminAccessControlViewModel(Dictionary<string, ForumPermission[]> modelLi
public List<ForumPermission> ACLList { get; set; }
}
public class CreateUserModel
{
public string Email { get; set; }
public string Username { get; set; }
}
public class AddForumCategoryViewModel
{
public string Name { get; set; }