当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.FindByEmail方法代码示例

本文整理汇总了C#中UserManager.FindByEmail方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.FindByEmail方法的具体用法?C# UserManager.FindByEmail怎么用?C# UserManager.FindByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.FindByEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddUserAndRole

        internal void AddUserAndRole()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            RoleStore<IdentityRole> roleStore = new RoleStore<IdentityRole>(context);
            RoleManager<IdentityRole> roleMgr = new RoleManager<IdentityRole>(roleStore);

            //create admin role
            if(!roleMgr.RoleExists("admin")) {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "admin" });
            }

            //create master user
            UserManager<ApplicationUser> userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            ApplicationUser appUser = new ApplicationUser {
                UserName = "Adam",
                Email = "[email protected]"
            };
            IdUserResult = userMgr.Create(appUser, "Baseball1!");

            //add to admin role
            if(!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "admin")) {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "admin");
            }
        }
开发者ID:adam-currie,项目名称:SET-SQ1-EMS,代码行数:27,代码来源:RoleActions.cs

示例2: InitializeRoles

    /// <summary>
    /// Checks for the three roles - Admin, Employee and Complainant and 
    /// creates them if not present
    /// </summary>
    public static void InitializeRoles()
    {  // Access the application context and create result variables.
        ApplicationDbContext context = new ApplicationDbContext();
        IdentityResult IdUserResult;

        // Create a RoleStore object by using the ApplicationDbContext object. 
        // The RoleStore is only allowed to contain IdentityRole objects.
        var roleStore = new RoleStore<IdentityRole>(context);

        RoleManager roleMgr = new RoleManager();
        if (!roleMgr.RoleExists("Administrator"))
        {
            roleMgr.Create(new ApplicationRole { Name = "Administrator" });
        }
        if (!roleMgr.RoleExists("Employee"))
        {
            roleMgr.Create(new ApplicationRole { Name = "Employee" });
        }
        if (!roleMgr.RoleExists("Complainant"))
        {
            roleMgr.Create(new ApplicationRole { Name = "Complainant" });
        }
        if (!roleMgr.RoleExists("Auditor"))
        {
            roleMgr.Create(new ApplicationRole { Name = "Auditor" });
        }
      

        // Create a UserManager object based on the UserStore object and the ApplicationDbContext  
        // object. Note that you can create new objects and use them as parameters in
        // a single line of code, rather than using multiple lines of code, as you did
        // for the RoleManager object.
        var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
        var appUser = new ApplicationUser
        {
            UserName = "Administrator",
            Email = "[email protected]"
        };
        IdUserResult = userMgr.Create(appUser, "Admin123");

        // If the new "canEdit" user was successfully created, 
        // add the "canEdit" user to the "canEdit" role. 
        if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "Administrator"))
        {
            IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "Administrator");
        }
         appUser = new ApplicationUser
        {
            UserName = "Auditor",
            Email = "[email protected]"
        };
        IdUserResult = userMgr.Create(appUser, "Auditor123");

        // If the new "canEdit" user was successfully created, 
        // add the "canEdit" user to the "canEdit" role. 
        if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "Auditor"))
        {
            IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "Auditor");
        }
    }
开发者ID:chandankpgreen,项目名称:PGRAMS,代码行数:64,代码来源:UserRoleInitialization.cs

示例3: AddUserAndRole

        internal void AddUserAndRole()
        {
            Models.ApplicationDbContext db = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            var roleStore = new RoleStore<IdentityRole>(db);

            var roleMgr = new RoleManager<IdentityRole>(roleStore);

            if (!roleMgr.RoleExists("canEdit"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "canEdit" });
            }

            var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            var appUser = new ApplicationUser
            {
                UserName = "[email protected]",
                Email = "[email protected]"
            };
            IdUserResult = userMgr.Create(appUser, "NhatSinh123*");

            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "canEdit"))
            {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "canEdit");
            }
        }
开发者ID:VoNhatSinh,项目名称:TestAppHarbor,代码行数:28,代码来源:RoleActions.cs

示例4: AddUserAndRole

        internal void AddUserAndRole()
        {
            // Access the application context and create result variable.
            Models.ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // Create a RoleStore object by using the ApplicationDbContext object.
            // The RoleStore is only allowed to contain IdentityRole Objects.
            var roleStore = new RoleStore<IdentityRole>(context);

            // Create a RoleManager object that is only allowed to contain IdentityRole objects.
            // When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object.
            var roleMgr = new RoleManager<IdentityRole>(roleStore);

            // Then, you create the "canEdit" role if it doesn't already exist.
            if (!roleMgr.RoleExists("canEdit"))
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "canEdit" });

            // Create a UserManager object based on the UserStore objcet and the ApplicationDbContext objcet.
            // Note that you can create new objects and use them as parameters in a single line of code, rather than using multiple lines of code, as you did for the RoleManager object.
            var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            var appUser = new ApplicationUser
            {
                UserName = "[email protected]",
                Email = "[email protected]"
            };
            IdUserResult = userMgr.Create(appUser, "Pa$$word1");

            // If the new "canEdit" user was successfully created, add the "canEdit" user to the "canEdit" role.
            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "canEdit"))
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "canEdit");
        }
开发者ID:yanhua2002,项目名称:WingtipToys,代码行数:33,代码来源:RoleActions.cs

示例5: AddUserAndRole

        internal void AddUserAndRole()
        {
            // access the application context and create result variables.
            Models.ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // create roleStore object that can only contain IdentityRole objects by using the ApplicationDbContext object.
            var roleStore = new RoleStore<IdentityRole>(context);
            var roleMgr = new RoleManager<IdentityRole>(roleStore);

            // create admin role if it doesn't already exist
            if (!roleMgr.RoleExists("admin"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "admin" });
            }

            // create a UserManager object based on the UserStore object and the ApplicationDbContext object.
            // defines admin email account
            var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            var appUser = new ApplicationUser
            {
                UserName = "[email protected]",
                Email = "[email protected]"
            };
            IdUserResult = userMgr.Create(appUser, "Pa$$word1");

            // If the new admin user was successfully created, add the new user to the "admin" role.
            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "admin"))
            {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "admin");
            }
        }
开发者ID:SCCapstone,项目名称:ZVerse,代码行数:33,代码来源:RoleActions.cs

示例6: AddUserAndRole

        internal void AddUserAndRole()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;
            var roleStore = new RoleStore<IdentityRole>(context);
            var roleMgr = new RoleManager<IdentityRole>(roleStore);
            if (!roleMgr.RoleExists("Admin"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "Admin" });
            }

            var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            var appUser = new ApplicationUser
            {

                Email = "[email protected]"
            };
            IdUserResult = userMgr.Create(appUser, "adminA123...");

            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "Admin"))
            {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "canEdit");
            }
        }
开发者ID:anitha1993,项目名称:dept-EmpMgmt,代码行数:25,代码来源:RoleActions.cs

示例7: AddToNormalUserRole

 internal void AddToNormalUserRole(ApplicationUser user)
 {
     Models.ApplicationDbContext context = new ApplicationDbContext();
     var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     if (!userMgr.IsInRole(userMgr.FindByEmail(user.Email).Id, "Normal"))
     {
         userMgr.AddToRole(userMgr.FindByEmail(user.Email).Id, "Normal");
     }
 }
开发者ID:MhdNZ,项目名称:MenStore,代码行数:9,代码来源:UserRoleActions.cs

示例8: Seed

        protected override void Seed(Context context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
            var userStore = new UserStore<ApplicationUser>(context);
            var mngr = new UserManager<ApplicationUser>(userStore);
            context.Roles.AddOrUpdate(r => r.Name, new IdentityRole { Name = "Administrators" });
            ApplicationUser adm = new ApplicationUser();
            
            

            adm.Email = "[email protected]";
            adm.UserName = "admin";

            mngr.Create(adm, "Adm!n0");
           
            context.SaveChanges();
            IdentityRole adrol = context.Roles.First(x => x.Name == "Administrators");
            adm = mngr.FindByEmail("[email protected]");
            mngr.AddToRole(adm.Id, adrol.Name);
            context.SaveChanges();

        }
开发者ID:angaratosurion,项目名称:MultiPlex,代码行数:33,代码来源:Configuration.cs

示例9: Validate

 public override void Validate(string userNameOrEmail, string password)
 {
     try
     {
         using (var context = new IdentityDbContext())
         {
             using (var userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(context)))
             {
                 string userName = userNameOrEmail;
                 if (userNameOrEmail.Contains('@'))
                 {
                     var userForEmail = userManager.FindByEmail(userNameOrEmail);
                     if (userForEmail != null)
                     {
                         userName = userForEmail.UserName;
                     }
                 }
                 var user = userManager.Find(userName, password);
                 if (user == null)
                 {
                     var msg = String.Format("Unknown Username {0} or incorrect password {1}", userNameOrEmail, password);
                     Trace.TraceWarning(msg);
                     throw new FaultException(msg);
                 }
             }
         }
     }
     catch (Exception e)
     {
         var msg = e.Message;
         Trace.TraceWarning(msg);
         throw new FaultException(msg);
     }
 }
开发者ID:minrogi,项目名称:PLMPack,代码行数:34,代码来源:IdentityValidator.cs

示例10: getUserId

 public string getUserId(string user_name)
 {
     Models.ApplicationDbContext context = new ApplicationDbContext();
     var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     var Id = userMgr.FindByEmail(user_name).Id;
     return Id;
 }
开发者ID:MSTCAlex,项目名称:Employee-Tracker,代码行数:7,代码来源:RolesManager.cs

示例11: GenerateCompany

        /// <summary>
        /// This will generate a new company from a view company
        /// </summary>
        /// <param name="comp">the company to be generated</param>
        /// <returns>the company that should be added to the database</returns>
        public Company GenerateCompany(ViewCompany comp, int _lenghtOfPassword, int _numberOfAlphabeticCharacters)
        {

            var result = new Company() {Active = true, Name = comp.Name, PhoneNr = comp.PhoneNr};

            //Generates a random password, and makes a new user with the correct email
            var password = System.Web.Security.Membership.GeneratePassword(_lenghtOfPassword, _numberOfAlphabeticCharacters);
            var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new DAL.Context.Context()));
            var user = new ApplicationUser()
            {
                UserName = comp.Email,
                Email = comp.Email
            };

            um.Create(user, password);
            //Generates the access string by encoding the email and the password into an array of bytes.
            var bytes = System.Text.Encoding.UTF8.GetBytes(comp.Email + ":" + password);
            result.AccessString = System.Convert.ToBase64String(bytes);
            result.Active = true;

            //This will be so that the database will make the relation between the two.
            var item = um.FindByEmail(comp.Email);
            result.IdentityId = item.Id;

            return result;
        }
开发者ID:Xorthos,项目名称:3.SemesterProject-Saatsea,代码行数:31,代码来源:CompanyGenerator.cs

示例12: Create

        /*This should be removed after the first admin gets made */
        // GET: MakeMeAdmin/Create
        public ActionResult Create(string email)
        {
            using (var context = new ApplicationDbContext())
            {
                var fadmin = context.KeyValueSettings.FirstOrDefault(s => s.Key == "FirstAdminSet");
                if (fadmin == null || fadmin.Value == "false")
                {
                    var roleStore = new RoleStore<IdentityRole>(context);
                    var roleManager = new RoleManager<IdentityRole>(roleStore);

                    roleManager.Create(new IdentityRole("Admin"));

                    var userStore = new UserStore<ApplicationUser>(context);
                    var userManager = new UserManager<ApplicationUser>(userStore);

                    var user = userManager.FindByEmail(email);
                    userManager.AddToRole(user.Id, "Admin");
                    if (fadmin == null)
                    {
                        context.KeyValueSettings.Add(new KeyValueSettings() { Key = "FirstAdminSet", Value = "true" });
                    }
                    else
                    {
                        fadmin.Value = "true";
                    }
                    context.SaveChanges();
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
            }
            return Json(false, JsonRequestBehavior.AllowGet);
        }
开发者ID:emartinez-dat,项目名称:DebesAlgo,代码行数:33,代码来源:MakeMeAdminController.cs

示例13: AddUserAndRole

        internal void AddUserAndRole()
        {
            // Access the application context and create result variables.
            Models.ApplicationDbContext context = new ApplicationDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // Create a RoleStore object by using the ApplicationDbContext object.
            // The RoleStore is only allowed to contain IdentityRole objects.
            var roleStore = new RoleStore<IdentityRole>(context);

            // Create a RoleManager object that is only allowed to contain IdentityRole objects.
            // When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object.
            var roleMgr = new RoleManager<IdentityRole>(roleStore);

            // Then, you create the "canEdit" role if it doesn't already exist.
            if (!roleMgr.RoleExists("SuperAdmin"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "SuperAdmin" });
            }

            if (!roleMgr.RoleExists("RegUser"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "RegUser" });
            }

            // Create a UserManager object based on the UserStore object and the ApplicationDbContext
            // object. Note that you can create new objects and use them as parameters in
            // a single line of code, rather than using multiple lines of code, as you did
            // for the RoleManager object.
            var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            if (userMgr.FindByEmail("[email protected]") == null)
            {
                var appUser = new ApplicationUser
                {
                    UserName = "AdminSw",
                    Email = "[email protected]"
                };
                IdUserResult = userMgr.Create(appUser, "Pantelic93.");
            }
            // If the new "canEdit" user was successfully created,
            // add the "canEdit" user to the "canEdit" role.
            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "SuperAdmin"))
            {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "SuperAdmin");
            }
        }
开发者ID:StefanP93,项目名称:ASP-Iep_Sw_shop,代码行数:47,代码来源:ActionRoles.cs

示例14: AddUserAndRole

        internal void AddUserAndRole()
        {
            // Access the application context and create result variables.
            GolddiggerDbContext context = new GolddiggerDbContext();
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // Create a RoleStore object by using the ApplicationDbContext object. 
            // The RoleStore is only allowed to contain IdentityRole objects.
            var roleStore = new RoleStore<IdentityRole>(context);

            // Create a RoleManager object that is only allowed to contain IdentityRole objects.
            // When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object. 
            var roleMgr = new RoleManager<IdentityRole>(roleStore);

            // Then, you create the "admin" role if it doesn't already exist.
            if (!roleMgr.RoleExists("admin"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole { Name = "admin" });
            }

            // Create a UserManager object based on the UserStore object and the ApplicationDbContext  
            // object. Note that you can create new objects and use them as parameters in
            // a single line of code, rather than using multiple lines of code, as you did
            // for the RoleManager object.
            var userMgr = new UserManager<User>(new UserStore<User>(context));
            var appUser = new User
            {
                UserName = "admin",
                Email = "[email protected]",
                IsFemale = true,
                ProfilePhoto = new byte[8]
            };
            
            IdUserResult = userMgr.Create(appUser, "Pa$$word1");

            // If the new "admin" user was successfully created, 
            // add the "admin" user to the "admin" role. 
            if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "admin"))
            {
                IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "admin");
            }
        }
开发者ID:How-Deep-Is-Your-Code,项目名称:Golddigger,代码行数:43,代码来源:RoleActions.cs

示例15: Adminator

        public ActionResult Adminator(string email)
        {
            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
            roleManager.Create(new IdentityRole("Administrator"));

            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            var user = userManager.FindByEmail(email);
            userManager.AddToRole(user.Id, "Administrator");

            return View();
        }
开发者ID:wstephenson,项目名称:streamq,代码行数:11,代码来源:AdminController.cs


注:本文中的UserManager.FindByEmail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。