コード例 #1
0
        public static void Initialize(DpContext context)
        {
            if (!context.Roles.Any(r => r.Name == "AppAdmin"))
            {
                var store   = new DpRoleStore(context);
                var manager = new DpRoleManager(store);
                var role    = new Role()
                {
                    Name = "AppAdmin"
                };

                manager.Create(role);
            }

            if (!context.Users.Any(u => u.UserName == "founder"))
            {
                var store   = new DpUserStore(context);
                var manager = new DpUserManager(store);
                var user    = new User {
                    UserName = "******"
                };

                manager.Create(user, "Password1!");
                manager.AddToRole(user.Id, "AppAdmin");
            }
            // Look for any students.
            if (context.Projects.Any())
            {
                return;   // DB has been seeded
            }

            context.Projects.Add(
                new Project
            {
                Name            = "Project 1",
                Description     = "Project 1 Description",
                CreatedDateTime = DateTime.Parse("2000-01-01"),
                TaskItems       = new[]
                {
                    new TaskItem {
                        Name = "Task1", Description = "Task 1 Description", CreatedDateTime = DateTime.Parse("2005-09-01"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task2", Description = "Task 2 Description", CreatedDateTime = DateTime.Parse("2015-11-15"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task3", Description = "Task 3 Description", CreatedDateTime = DateTime.Parse("2016-09-12"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task4", Description = "Task 4 Description", CreatedDateTime = DateTime.Parse("2004-01-12"), IsActive = true, ProjectId = 1
                    }
                }
            });

            context.SaveChanges();
        }
コード例 #2
0
        public static DpUserManager Create(
            IdentityFactoryOptions <DpUserManager> options, IOwinContext context)
        {
            var manager = new DpUserManager(
                new DpUserStore(context.Get <DpContext>()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <User, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };
            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = true,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true
            };
            // Register two factor authentication providers. This application uses Phone
            // and Emails as a step of receiving a code for verifying the user
            // You can write your own provider and plug in here.
            manager.RegisterTwoFactorProvider("PhoneCode",
                                              new PhoneNumberTokenProvider <User, int>
            {
                MessageFormat = "Your security code is: {0}"
            });
            manager.RegisterTwoFactorProvider("EmailCode",
                                              new EmailTokenProvider <User, int>
            {
                Subject    = "Security Code",
                BodyFormat = "Your security code is: {0}"
            });
            //manager.EmailService = new EmailService();
            //manager.SmsService = new SmsService();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <User, int>(
                        dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }
コード例 #3
0
ファイル: AuthRepository.cs プロジェクト: topoulos/Dp
 public AuthRepository()
 {
     _ctx         = new DpContext();
     _userManager = new DpUserManager(new DpUserStore(_ctx));
 }