public static MvcHtmlString GetUserName(this HtmlHelper html, string id)
        {
            AppUserManager userManager = HttpContext.Current.GetOwinContext().GetUserManager <AppUserManager>();

            return(new MvcHtmlString(userManager.FindByIdAsync(id).Result.UserName));
        }
コード例 #2
0
        public void PerformInitialSetup(AppIdentityDbContext context)
        {
            //setup users and roles
            AppUserManager userMgr  = new AppUserManager(new UserStore <AppUser>(context));
            AppRoleManager roleMgr  = new AppRoleManager(new RoleStore <AppRole>(context));
            string         roleName = "Administrators";
            string         userName = "******";
            string         password = "******";
            string         email    = "*****@*****.**";

            if (!roleMgr.RoleExists(roleName))
            {
                roleMgr.Create(new AppRole(roleName));
            }
            AppUser user = userMgr.FindByName(userName);

            if (user == null)
            {
                userMgr.Create(new AppUser {
                    UserName = userName, Email = email
                },
                               password);
                user = userMgr.FindByName(userName);
            }

            if (!userMgr.IsInRole(user.Id, roleName))
            {
                userMgr.AddToRole(user.Id, roleName);
            }



            // initial configuration will go here

            Content mycontent = new Content()
            {
                Body         = "Hello",
                Byline       = "By line hehe",
                CreationDate = DateTime.Now,
                Seo          = "Helllo seo",
                TagLine      = "Tag line",
                Teaser       = "Hi Teaser",
                Title        = "Det me title",
                UpdatedDate  = DateTime.Now,
                ViewCount    = 0,

                UserId = userMgr.FindByName("Admin").Id
            };
            Setting seedsetting1 = new Setting();

            seedsetting1.Name  = "AdminEmail";
            seedsetting1.Type  = "GeneralSettings";
            seedsetting1.Value = "*****@*****.**";
            Setting seedsetting2 = new Setting();

            seedsetting2.Name  = "SiteName";
            seedsetting2.Type  = "GeneralSettings";
            seedsetting2.Value = "Alumc";

            Setting seedsetting3 = new Setting();

            seedsetting3.Name  = "HomeMetaDescription";
            seedsetting3.Type  = "SeoSettings";
            seedsetting3.Value = "Alumc Seosettings";
            Setting seedsetting4 = new Setting();

            seedsetting4.Name  = "HomeMetaTitle";
            seedsetting4.Type  = "SeoSettings";
            seedsetting4.Value = "Alumc Title settings";

            context.Settings.Add(seedsetting1);
            context.Settings.Add(seedsetting2);
            context.Settings.Add(seedsetting3);
            context.Settings.Add(seedsetting4);

            context.Contents.Add(mycontent);
            context.SaveChanges();
        }
コード例 #3
0
 public CustomUserValidator(AppUserManager mgr)
     : base(mgr)
 {
 }
コード例 #4
0
 public CustomUserValidator(AppUserManager manager)
 {
     _manager = manager;
 }