Пример #1
0
 public UsersAdminController()
 {
     context     = new ConceptMakerContext();
     UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
     RoleManager = new RoleManager <IdentityRole>(
         new RoleStore <IdentityRole>(new ApplicationDbContext()));
 }
Пример #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //itnializer
            Database.SetInitializer <ConceptMakerContext>(new ConceptMakerIntializer());
            ConceptMakerContext db = new ConceptMakerContext();

            db.Database.Initialize(true);
        }
Пример #3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var userManager = new UserManager <ApplicationUser>(
                new UserStore <ApplicationUser>(new ApplicationDbContext()));

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var result2 = userManager.AddToRole(user.Id, "Client");
                    using (var db = new ConceptMakerContext())
                    {
                        //   db.Profiles.Add(new Models.Profile { Username = model.Email, RegisteredDate = DateTime.Now, RoleId = 2 });
                        db.SaveChanges();
                    }
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Aby uzyskać więcej informacji o sposobie włączania potwierdzania konta i resetowaniu hasła, odwiedź stronę https://go.microsoft.com/fwlink/?LinkID=320771
                    // Wyślij wiadomość e-mail z tym łączem
                    // 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.SendEmailAsync(user.Id, "Potwierdź konto", "Potwierdź konto, klikając <a href=\"" + callbackUrl + "\">tutaj</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // Dotarcie do tego miejsca wskazuje, że wystąpił błąd, wyświetl ponownie formularz
            return(View(model));
        }