コード例 #1
0
        public void CreateAdminUser(AdminSetupModel adminSetupModel)
        {
            if (_connectionString == null)
            {
                _connectionString = ConfigurationManager.ConnectionStrings["eFormMainConnection"].ConnectionString;
            }
            // Seed admin and demo users
            var manager   = new EformUserManager(new EformUserStore(new BaseDbContext(_connectionString)));
            var adminUser = new EformUser()
            {
                UserName                     = adminSetupModel.UserName,
                Email                        = adminSetupModel.Email,
                FirstName                    = adminSetupModel.FirstName,
                LastName                     = adminSetupModel.LastName,
                EmailConfirmed               = true,
                TwoFactorEnabled             = false,
                IsGoogleAuthenticatorEnabled = false
            };

            if (!manager.Users.Any(x => x.Email.Equals(adminUser.Email)))
            {
                IdentityResult ir = manager.Create(adminUser, adminSetupModel.Password);
                if (ir != null)
                {
                    manager.AddToRole(adminUser.Id, "admin");
                }
                else
                {
                    throw new Exception("Could not create the user");
                }
            }
        }
コード例 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && _userManager != null)
            {
                _userManager.Dispose();
                _userManager = null;
            }

            base.Dispose(disposing);
        }
コード例 #3
0
        public void CreateAdminUser(AdminSetupModel adminSetupModel)
        {
            if (_connectionString == null)
            {
                _connectionString = ConfigurationManager.ConnectionStrings["eFormMainConnection"].ConnectionString;
            }
            // Seed admin and demo users
            var manager   = new EformUserManager(new EformUserStore(new BaseDbContext(_connectionString)));
            var adminUser = new EformUser()
            {
                UserName       = adminSetupModel.UserName,
                Email          = adminSetupModel.Email,
                FirstName      = adminSetupModel.FirstName,
                LastName       = adminSetupModel.LastName,
                EmailConfirmed = true,
            };

            if (!manager.Users.Any(x => x.Email.Equals(adminUser.Email)))
            {
                manager.Create(adminUser, adminSetupModel.Password);
                manager.AddToRole(adminUser.Id, "admin");
            }
        }
コード例 #4
0
 public AccountController(EformUserManager userManager,
                          ISecureDataFormat <AuthenticationTicket> accessTokenFormat)
 {
     UserManager       = userManager;
     AccessTokenFormat = accessTokenFormat;
 }