Exemple #1
0
 public RolesAndUsersHelper(ApplicationDbContext db)
 {
     context     = db;
     userManager = OwinContextExtensions.GetUserManager <ApplicationUserManager>(HttpContext.Current.GetOwinContext());
     roleManager = new RoleManager <IdentityRole>(
         new RoleStore <IdentityRole>(context));
 }
        private async Task <ClaimsIdentity> CreateIdentity()
        {
            ClaimsIdentity identity = null;

            //用户
            var user = new IotUser();

            user.Id       = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.NickName = "农业气象物联网";

            //Context
            var owinContext = HttpContext.GetOwinContext();
            var userManager = OwinContextExtensions.GetUserManager <UserManager <IotUser, string> >(owinContext);

            identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            return(identity);
        }
Exemple #3
0
 public UserRoleRepository(ApplicationDbContext dbContext)
 {
     DbContext = dbContext;
     UserManager = OwinContextExtensions.GetUserManager<ApplicationUserManager>(HttpContext.Current.GetOwinContext());
     UserRepository = new UserRepository(dbContext);
 }
Exemple #4
0
 public static ApplicationSignInManager Create(
     IdentityFactoryOptions <ApplicationSignInManager> options,
     IOwinContext context)
 {
     return(new ApplicationSignInManager((ApplicationUserManager)OwinContextExtensions.GetUserManager <ApplicationUserManager>(context), context.get_Authentication()));
 }