コード例 #1
0
        public UsersController()
        {
            var dbContext    = new WealthEconomyContext();
            var appUserStore = new AppUserStore(dbContext);
            var appRoleStore = new AppRoleStore(dbContext);

            _userManager = new AppUserManager(appUserStore, appRoleStore);
        }
コード例 #2
0
        public RolesController()
        {
            var dbContext    = new BackboneContext();
            var appUserStore = new AppUserStore(dbContext);
            var appRoleStore = new AppRoleStore(dbContext);

            _userManager = new AppUserManager(appUserStore, appRoleStore);
        }
コード例 #3
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();

            var webApiUri = ConfigurationManager.AppSettings["webApiUri"].ToString();

            container.RegisterInstance <IApiProvider>(new ApiProvider(webApiUri));

            var userStore   = new AppUserStore <AppUser>();
            var userManager = new AppUserManager(userStore);

            container.RegisterInstance <AppUserManager>(userManager);

            var appRoleStore   = new AppRoleStore();
            var appRoleManager = new AppRoleManager(appRoleStore);

            container.RegisterInstance <AppRoleManager>(appRoleManager);

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));


            /*
             *  Getting started with Unity.Mvc5
             *  ------------------------------ -
             *
             *  Unity.Mvc5 is an update of the popular Unity.Mvc3 package, updated to target .NET 4.5, MVC5 and Unity 3.0
             *
             *  To get started, just add a call to UnityConfig.RegisterComponents() in the Application_Start method of Global.asax.cs
             *  and the MVC framework will then use the Unity.Mvc5 DependencyResolver to resolve your components.
             *
             *  e.g.
             *
             *  public class MvcApplication : System.Web.HttpApplication
             *          {
             *              protected void Application_Start()
             *              {
             *                  AreaRegistration.RegisterAllAreas();
             *                  UnityConfig.RegisterComponents();                           // <----- Add this line
             *                  FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
             *                  RouteConfig.RegisterRoutes(RouteTable.Routes);
             *                  BundleConfig.RegisterBundles(BundleTable.Bundles);
             *              }
             *          }
             *
             *          Add your Unity registrations in the RegisterComponents method of the UnityConfig class. All components that implement IDisposable should be
             *          registered with the HierarchicalLifetimeManager to ensure that they are properly disposed at the end of the request.
             *
             *          It is not necessary to register your controllers with Unity.
             */
        }
コード例 #4
0
        public static AppUserManager CreateUserManager(IdentityFactoryOptions <AppUserManager> options, IOwinContext context)
        {
            var dbContext    = context.Get <WealthEconomyContext>();
            var appUserStore = new AppUserStore(dbContext);
            var appRoleStore = new AppRoleStore(dbContext);

            var manager = new AppUserManager(appUserStore, appRoleStore);

            // Configure validation logic for userNames
            manager.UserValidator = new UserValidator <User, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            // Configure validation logic for passwords
            // TODO Review this!
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6,
                //RequireNonLetterOrDigit = true,
                RequireDigit     = true,
                RequireLowercase = true,
                //RequireUppercase = true,
            };

            manager.EmailService = new EmailService();

            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <User, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }

            return(manager);
        }
コード例 #5
0
 public AppRoleManager(AppRoleStore store)
     : base(store)
 {
 }
コード例 #6
0
 public AppUserManager(AppUserStore store, AppRoleStore appRoleStore) : base(store)
 {
     _roleStore = appRoleStore;
 }