public void PerformInitialSetup(UserIdentityDbContext context)
        {
            UserIdentityManager userManager = new UserIdentityManager(new UserStore <User>(context));
            AppRoleManager      roleManager = new AppRoleManager(new RoleStore <AppRole>(context));

            userManager.Create(
                new User()
            {
                UserName = userName, FirstName = firstName, LastName = lastName, Email = email
            }, password);

            var user = userManager.FindByName(userName);

            foreach (string roles in Enum.GetNames(typeof(TypicalRoles)))
            {
                roleManager.Create(new AppRole(roles));
                userManager.AddToRole(user.Id, roles);
            }
            context.SaveChanges();
        }
        public static UserIdentityManager Create(IdentityFactoryOptions <UserIdentityManager> options, IOwinContext context)
        {
            UserIdentityDbContext dbContext       = context.Get <UserIdentityDbContext>();
            UserIdentityManager   identityManager = new UserIdentityManager(new UserStore <User>(dbContext));

            identityManager.PasswordValidator = new PasswordValidator()
            {
                RequireDigit            = false,
                RequireLowercase        = true,
                RequireUppercase        = true,
                RequiredLength          = 6,
                RequireNonLetterOrDigit = false
            };

            identityManager.UserValidator = new UserValidator <User>(identityManager)
            {
                AllowOnlyAlphanumericUserNames = true,
                RequireUniqueEmail             = true
            };

            return(identityManager);
        }
Ejemplo n.º 3
0
        public static MvcHtmlString GetUserName(this HtmlHelper html, string id)
        {
            UserIdentityManager manager = HttpContext.Current.GetOwinContext().GetUserManager <UserIdentityManager>();

            return(new MvcHtmlString(manager.FindByIdAsync(id).Result.UserName));
        }