Esempio n. 1
0
        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");
                }
            }
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            LibUser libUser = db.LibUsers.Find(id);

            db.LibUsers.Remove(libUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        // 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));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }