public void SeedUsers(MyContext context) { var usersStore = new UserStore <LibUser>(context); var usersManager = new UserManager <LibUser>(usersStore); LibUser admin = new LibUser(); admin.FullName = "Chukwuka Ugwu"; admin.Email = "*****@*****.**"; admin.UserName = "******"; admin.PhoneNumber = "(312)555-0690"; admin.NIN = "BC6788899"; var password = "******"; if (usersManager.FindByEmail(admin.Email) == null) { var result = usersManager.Create(admin, password); if (result.Succeeded) { //add necessary roles to admin usersManager.AddToRole(admin.Id, "Administrator"); //usersManager.AddToRole(admin.Id, "Staff"); //usersManager.AddToRole(admin.Id, "User"); } } }
public ActionResult DeleteConfirmed(int id) { LibUser libUser = db.LibUsers.Find(id); db.LibUsers.Remove(libUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,UserName,Email,Phone")] LibUser libUser) { if (ModelState.IsValid) { db.Entry(libUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(libUser)); }
public ActionResult Create([Bind(Include = "UserID,FirstName,LastName,UserName,Email,Phone")] LibUser libUser) { if (ModelState.IsValid) { db.LibUsers.Add(libUser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(libUser)); }
// GET: LibUsers/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LibUser libUser = db.LibUsers.Find(id); if (libUser == null) { return(HttpNotFound()); } return(View(libUser)); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new LibUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { var user = new LibUser() { UserName = model.Email, Email = model.Email, Name = model.Name, Surname = model.Surname }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.EmailService.SendAsync(new IdentityMessage() { Body = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>", Destination = user.Email, Subject = "Confirm your account" }); return RedirectToAction("Create", "Library", new {@id = user.Id}); } AddErrors(result); // If we got this far, something failed, redisplay form return View(model); }