public IIdentityManagerService Create()
        {
            var db = new IdentityDbContext<IdentityUser>(_connString);
            var userstore = new UserStore<IdentityUser>(db);
            var usermgr = new Microsoft.AspNet.Identity.UserManager<IdentityUser>(userstore);
            usermgr.PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator
            {
                RequiredLength = 3
            };
            var rolestore = new RoleStore<IdentityRole>(db);
            var rolemgr = new Microsoft.AspNet.Identity.RoleManager<IdentityRole>(rolestore);

            var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<IdentityUser, string, IdentityRole, string>(usermgr, rolemgr);

            var dispose = new DisposableIdentityManagerService(svc, db);
            return dispose;

            //var db = new CustomDbContext(_connString);
            //var userstore = new CustomUserStore(db);
            //var usermgr = new CustomUserManager(userstore);
            //var rolestore = new CustomRoleStore(db);
            //var rolemgr = new CustomRoleManager(rolestore);

            //var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<CustomUser, int, CustomRole, int>(usermgr, rolemgr);
            //var dispose = new DisposableIdentityManagerService(svc, db);
            //return dispose;
        }
        public static IUserService Factory(string connString)
        {
            var db = new IdentityDbContext<IdentityUser>(connString);
            var store = new UserStore<IdentityUser>(db);
            var mgr = new UserManager<IdentityUser>(store);
            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService<IdentityUser, string>(mgr, db);
            return userSvc;

            //var db = new CustomDbContext(connString);
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new AspNetIdentityUserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
 public EmployeeAdminRepository()
 {
     AspContext = new IdentityDbContext();
     _db = new GtrackDbContext();
     UserManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>());
     RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>());
 }
        public ActionResult ViewAllUsers(string returnUrl)
        {
            //List<string> users;
            //using (var context = new ApplicationDbContext())
            //{
            //    var userStore = new UserStore<ApplicationUser>(context);
            //    var userManager = new UserManager<ApplicationUser>(userStore);

            //    users = (from u in userManager.Users select u.UserName).ToList();
            //}
            //return View(users);
            var context = new IdentityDbContext();

            var allUsers = context.Users.ToList();
            var cUsers = new List<MetroUsers>();
            foreach (var user in allUsers)
            {
                var m = new MetroUsers();
                m.id = user.Id;
                m.Username = user.UserName;
                cUsers.Add(m);

            }
            return View(cUsers);
        }
Exemple #5
0
 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);
     }
 }
Exemple #6
0
 private static void InitializeDatabase()
 {
     using (var ctxt = new IdentityDbContext())
     {
         System.Data.Entity.Database.SetInitializer<IdentityDbContext>(new IdentityDbInitializer());
         ctxt.Database.Initialize(false);
     }
 }
 public AccountController(
     UserManager<IdentityUser> userManager,
     SignInManager<IdentityUser> signInManager,
     IdentityDbContext dbContext)
 {
     _userManager = userManager;
     _signInManager = signInManager;
     _identityContext = dbContext;
 }
Exemple #8
0
 public ProductController(UserManager <IdentityUser> userManager,
                          SignInManager <IdentityUser> signInManager,
                          IdentityDbContext identityDbContext, WebShopDBContext webShopDBContext)
 {
     this.userManager       = userManager;
     this.signInManager     = signInManager;
     this.identityDbContext = identityDbContext;
     this.webShopDBContext  = webShopDBContext;
 }
 public HttpUnitOfWork(
     IdentityDbContext IdentityContext,
     IHttpContextAccessor httpAccessor) : base(IdentityContext)
 {
     IdentityContext.CurrentUserId =
         httpAccessor.HttpContext.User
         .FindFirst(OpenIdConnectConstants.Claims.Subject)
         ?.Value?.Trim();
 }
Exemple #10
0
 public UserManager(
     IdentityDbContext <TUser> db,
     IHasher hasher,
     ILogger <UserManager <TUser> > logger)
 {
     this.db     = db;
     this.hasher = hasher;
     this.logger = logger;
 }
Exemple #11
0
 public LocalUserService(
     IdentityDbContext context,
     IPasswordHasher <User> passwordHasher)
 {
     _context = context
                ?? throw new ArgumentNullException(nameof(context));
     _passwordHasher = passwordHasher
                       ?? throw new ArgumentNullException(nameof(passwordHasher));
 }
Exemple #12
0
        public UserService(IdentityDbContext <ApplicationUser> context)
        {
            if (context == null)
            {
                throw new ArgumentException("Context cannot be null or empty");
            }

            this.context = context;
        }
Exemple #13
0
 public IList <IdentityUser> GetAllUser(ShuaDanPingTai.Models.Pager pager)
 {
     using (var db = new IdentityDbContext())
     {
         pager.Count = (from a in db.Users select a).Count();
         var query = (from a in db.Users orderby a.UserName select a).Skip((pager.PageIndex - 1) * pager.PageSize).Take(pager.PageSize).ToList();
         return(query);
     }
 }
 public IdentityInitializer(
     IdentityDbContext context,
     UserManager <ApplicationUser> userManager,
     RoleManager <IdentityRole> roleManager)
 {
     _context     = context;
     _userManager = userManager;
     _roleManager = roleManager;
 }
Exemple #15
0
 public ManagementUnitOfWork(
     DbContext context,
     IdentityDbContext <ApplicationUser> appContext,
     ILinkRepository linkRepository,
     IPageRepository pageRepository,
     ITenantRepository tenantRepository,
     IEronFileRepository fileRepository,
     IBannerSliderRepository bannerSliderRepository,
     IOfferRepository offerRepository,
     IInvoiceRepository invoiceRepository,
     IInvoiceItemRepository invoiceItemRepository,
     IInvoiceLogRepository invoiceLogRepository,
     IWishListRepository wishListRepository,
     ICartRepository cartRepository,
     IOrderRepository orderRepository,
     ITariffRepository tariffRepository,
     ITariffPriceRepository tariffPriceRepository,
     ITariffItemRepository tariffItemRepository,
     IProductRepository productRepository,
     IProductPriceRepository productPriceRepository,
     IProductPropertyRepository productPropertyRepository,
     IProductPropertyNameRepository productPropertyNameRepository,
     IProductCategoryRepository productCategoryRepository,
     IServiceReviewRepository serviceReviewRepository,
     ITariffCategoryRepository tariffCategoryRepository, IFinanceTransactionRepository financeTransactionRepository, IBlogRepository blogRepository, IBlogArchiveRepository blogArchiveRepository, ICommentRepository commentRepository, ILikeRepository likeRepository, IHashTagRepository hashTagRepository) : base(context)
 {
     AppContext                    = appContext;
     LinkRepository                = linkRepository;
     PageRepository                = pageRepository;
     TenantRepository              = tenantRepository;
     FileRepository                = fileRepository;
     BannerSliderRepository        = bannerSliderRepository;
     OfferRepository               = offerRepository;
     InvoiceRepository             = invoiceRepository;
     InvoiceItemRepository         = invoiceItemRepository;
     InvoiceLogRepository          = invoiceLogRepository;
     WishListRepository            = wishListRepository;
     CartRepository                = cartRepository;
     OrderRepository               = orderRepository;
     TariffRepository              = tariffRepository;
     TariffPriceRepository         = tariffPriceRepository;
     TariffItemRepository          = tariffItemRepository;
     ProductRepository             = productRepository;
     ProductPriceRepository        = productPriceRepository;
     ProductPropertyRepository     = productPropertyRepository;
     ProductPropertyNameRepository = productPropertyNameRepository;
     ProductCategoryRepository     = productCategoryRepository;
     ServiceReviewRepository       = serviceReviewRepository;
     TariffCategoryRepository      = tariffCategoryRepository;
     FinanceTransactionRepository  = financeTransactionRepository;
     BlogRepository                = blogRepository;
     BlogArchiveRepository         = blogArchiveRepository;
     CommentRepository             = commentRepository;
     LikeRepository                = likeRepository;
     HashTagRepository             = hashTagRepository;
 }
Exemple #16
0
        public SecurityUserManagerTests(IdentityDbContextFixture fixture)
        {
            var storeMock = new Mock <IUserStore <SecurityUser> >();

            _userManager  = new Mock <UserManager <SecurityUser> >(storeMock.Object, null, null, null, null, null, null, null, null);
            _tokenFactory = new Mock <ITokenFactory>(MockBehavior.Strict);
            _context      = fixture.Context;

            _sut = new SecurityUserManager(_userManager.Object, _context, _tokenFactory.Object);
        }
        public static UserManager <IdentityUser> CreateManager(IdentityDbContext db)
        {
            var options = new IdentityFactoryOptions <UserManager <IdentityUser> >
            {
                Provider = new TestProvider(db),
                DataProtectionProvider = new DpapiDataProtectionProvider()
            };

            return(options.Provider.Create(options, new OwinContext()));
        }
 public IdentityTokenIssuer(UserManager <IdentityUser> userManager,
                            SignInManager <IdentityUser> signInManager,
                            IdentityDbContext db,
                            ITokenBuilder tokenBuilder)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _tokenBuilder  = tokenBuilder;
     _db            = db;
 }
Exemple #19
0
        public UnitOfWork(CodingSoldierDbContext dbContext, IdentityDbContext <ApplicationUser> identityDbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }
            _dbContext = dbContext as CodingSoldierDbContext;

            _identityDbContext = identityDbContext ?? throw new ArgumentNullException(nameof(identityDbContext));
        }
        public static IdentityDbContext CreateDefaultDb()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways <IdentityDbContext>());
            var db = new IdentityDbContext();

            db.Database.Initialize(true);
            var foo = typeof(SqlProviderServices);

            return(db);
        }
    public static void Main()
    {
        IdentityDbContext f = new IdentityDbContext(new DbContextOptions("test"));         //it's ok

        Console.WriteLine(f.Options.Config);

        IdentityDbContext f2 = new IdentityDbContext("testWithImplicit");

        Console.WriteLine(f2.Options.Config);
    }
 public IdentityDbContextCleaner(IdentityDbContext context, IWebHostEnvironment environment, ILogger <IdentityDbContextCleaner> logger) : base(
         context,
         environment,
         logger)
 {
     Users     = context.Set <User>();
     Doxatags  = context.Set <Doxatag>();
     Addresses = context.Set <Address>();
     Roles     = context.Set <Role>();
 }
Exemple #23
0
 public AccountRepository(IdentityDbContext identityContext,
                          OrcaQuizContext orcaQuizContext,
                          UserManager <IdentityUser> userManager,
                          SignInManager <IdentityUser> signInManager)
 {
     this.identityContext = identityContext;
     this.orcaQuizContext = orcaQuizContext;
     this.userManager     = userManager;
     this.signInManager   = signInManager;
 }
Exemple #24
0
 public AuthenticationService(UserManager <User> userManager, SignInManager <User> signInManager, IJwtUser user, IOptions <JwtSettings> jwtSettings, IOptions <FacebookAuthSettings> facebookAuthSettings, IOptions <RefreshTokenSettings> refreshTokenSettings, IdentityDbContext context, IMapper mapper)
 {
     this.UserManager          = userManager;
     this.SignInManager        = signInManager;
     this.JwtSettings          = jwtSettings.Value;
     this.FacebookAuthSettings = facebookAuthSettings.Value;
     this.RefreshTokenSettings = refreshTokenSettings.Value;
     this.Context = context;
     this.Mapper  = mapper;
 }
        public AccountController(ApplicationUserManager userManager,
            ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
        {
            var context = new DispatcherContext();
            db = context;
            idContext = context;

            UserManager = userManager;
            AccessTokenFormat = accessTokenFormat;
        }
        public MembersController(

            UserManager <IdentityUser> userManager,
            SignInManager <IdentityUser> signInManager,
            IdentityDbContext dbContext)
        {
            _userManager     = userManager;
            _signInManager   = signInManager;
            _identityContext = dbContext;
        }
Exemple #27
0
        public async Task DeleteResourceAsync(string id)
        {
            var identityResourceToDelete =
                await IdentityDbContext.IdentityResources.FirstOrDefaultAsync(a =>
                                                                              a.Name.Equals(id, StringComparison.OrdinalIgnoreCase));

            identityResourceToDelete.IsDeleted = true;

            await IdentityDbContext.SaveChangesAsync();
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //create a dbcontext that specified the connection string
            var identityDBContext = new IdentityDbContext("IdentityConnectionString");
            //create user store and user manager
            var userStore   = new UserStore <IdentityUser>(identityDBContext);
            var userManager = new UserManager <IdentityUser>(userStore);
            var user        = userManager.Find(txtLoginEmail.Text, txtLoginPassword.Text);

            var roleStore   = new RoleStore <IdentityRole>(identityDBContext);
            var roleManager = new RoleManager <IdentityRole>(roleStore);

            if (user != null)
            {
                if (userManager.IsInRole(user.Id, "administrator"))
                {
                    LogUserIn(userManager, user);
                    Server.Transfer("manageproduct.aspx", true);
                }
                else if (userManager.IsInRole(user.Id, "registeredcustomer"))
                {
                    LogUserIn(userManager, user);
                    Server.Transfer("default.aspx", true);
                }
                else
                {
                    Server.Transfer("default.aspx", true);
                }
            }
            else
            {
                litLoginError.Text    = "Invalid username or password";
                txtLoginEmail.Text    = "";
                txtLoginPassword.Text = "";
            }

            //var identityDbContext = new IdentityDbContext("IdentityConnectionString");
            //var userStore = new UserStore<IdentityUser>(identityDbContext);
            //var userManager = new UserManager<IdentityUser>(userStore);
            //var user = userManager.Find(txtLoginEmail.Text, txtLoginPassword.Text);


            ////if (user != null)
            ////{
            ////    LogUserIn(userManager, user);
            ////    Server.Transfer("manageProduct_update.aspx", true);
            ////}
            ////else
            ////{
            ////    litLoginError.Text = "Invalid username or password";
            ////    txtLoginEmail.Text = "";
            ////    txtLoginPassword.Text = "";
            ////}
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this._context != null)
         {
             this._context.Dispose();
             this._context = null;
         }
     }
 }
Exemple #30
0
 public JwtAuthManager(
     IdentityDbContext <TUser> jwtIdentityDb,
     IUserManager <TUser> userManager,
     IHttpContextAccessor contextAccessor,
     JwtIdentityOptions identityOptions)
 {
     _jwtIdentityDb   = jwtIdentityDb;
     _userManager     = userManager;
     _context         = contextAccessor.HttpContext;
     _identityOptions = identityOptions;
 }
Exemple #31
0
        /// <summary>
        /// Executed migration SQL script located in Migrations/Scripts folder.
        /// </summary>
        /// <param name="context"></param>
        protected virtual void ExecuteMigrationSql(IdentityDbContext context)
        {
            string sql = GetScript();

#if NET_CORE2
            context.Database.ExecuteSqlCommand(sql);
#endif
#if NET_CORE3
            context.Database.ExecuteSqlRaw(sql);
#endif
        }
Exemple #32
0
 public IndexModel(
     UserManager <AspNetUsers> userManager,
     SignInManager <AspNetUsers> signInManager,
     IEmailSender emailSender,
     IdentityDbContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _context       = context;
 }
Exemple #33
0
 public ClientController(
     ConfigurationDbContext _idsDB,
     IdentityDbContext _userDB,
     IStringLocalizer <ClientController> localizer,
     IdentityServerTools tools)
 {
     userDB = _userDB;
     idsDB  = _idsDB;
     l      = localizer;
     _tools = tools;
 }
Exemple #34
0
        public UserAdmin()
        {
            // Constructor to initialize user service objects.
            myConStr      = "UserStoreConnection";
            myDbContext   = new IdentityDbContext(myConStr);
            myUserStore   = new UserStore <IdentityUser>(myDbContext);
            myUserManager = new UserManager <IdentityUser>(myUserStore);
            IAuthenticationManager authManager = HttpContext.Current.GetOwinContext().Authentication;

            mySignInManager = new SignInManager <IdentityUser, string>(myUserManager, authManager);
        }
Exemple #35
0
 public AuthController(
     UserManager <AppUser> userManager,
     IJwtFactory jwtFactory,
     IOptions <JwtOptions> jwtOptions,
     IdentityDbContext context)
 {
     this.userManager = userManager;
     this.jwtFactory  = jwtFactory;
     this.context     = context;
     this.jwtOptions  = jwtOptions.Value;
 }
Exemple #36
0
 public MembersController(
     UserManager <IdentityUser> userManager,
     SignInManager <IdentityUser> signInManager,
     IdentityDbContext identityContext,
     QuizDbContext context)
 {
     this.userManager     = userManager;
     this.signInManager   = signInManager;
     this.identityContext = identityContext;
     this.context         = context;
 }
        public static IUserManager Create()
        {
            var db = new IdentityDbContext<IdentityUser>("DefaultConnection");
            var store = new UserStore<IdentityUser>(db);
            var mgr = new Microsoft.AspNet.Identity.UserManager<IdentityUser>(store);
            return new Thinktecture.IdentityManager.AspNetIdentity.UserManager<IdentityUser>(mgr, db);

            //var db = new CustomDbContext("CustomAspId");
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //return new Thinktecture.IdentityManager.AspNetIdentity.UserManager<CustomUser, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(mgr, db);
        }
Exemple #38
0
 public UserController(
     StockholmForNewcomersContext context,
     UserManager <IdentityUser> userManager,
     SignInManager <IdentityUser> signInManager,
     IdentityDbContext dbContext)
 {
     dataManager      = new DataManager(context, userManager);
     _userManager     = userManager;
     _signInManager   = signInManager;
     _identityContext = dbContext;
     //_context = context;
 }
Exemple #39
0
 public IdentityController(
     ITokenService tokenService,
     IdentityDbContext dbContext,
     IMapper mapper,
     ILogger <IdentityController> logger
     )
 {
     _tokenService = tokenService;
     _dbContext    = dbContext;
     _mapper       = mapper;
     _logger       = logger;
 }
 public UserManager<AbitInfoIdentityUser> GetUserManager(IdentityDbContext<AbitInfoIdentityUser> context)
 {
     UserStore<AbitInfoIdentityUser> userStore = new UserStore<AbitInfoIdentityUser>(context);
     AbitInfoUserManager userManager = new AbitInfoUserManager(userStore);
     userManager.EmailService = _service;
     userManager.UserTokenProvider = new DataProtectorTokenProvider<AbitInfoIdentityUser>(
         _dataProtectionProvider.Create("ASP.NET Identity"))
         {
             //Code for email confirmation and reset password life time
             TokenLifespan = TimeSpan.FromHours(6)
         };
     return userManager;
 }
        public static IUserService Factory()
        {
            var db = new IdentityDbContext<IdentityUser>("DefaultConnection");
            var store = new UserStore<IdentityUser>(db);
            var mgr = new UserManager<IdentityUser>(store);
            var userSvc = new UserService<IdentityUser, string>(mgr, db);
            return userSvc;

            //var db = new CustomDbContext("CustomAspId");
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new UserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
Exemple #42
0
        public static IdentityDbContext CreateContext(bool delete = false)
        {
            var services = new ServiceCollection();
            services.AddEntityFramework().AddSqlServer();
            var serviceProvider = services.BuildServiceProvider();

            var db = new IdentityDbContext(serviceProvider, ConnectionString);
            if (delete)
            {
                db.Database.EnsureDeleted();
            }
            db.Database.EnsureCreated();
            return db;
        }
        public IQueryable<KeyValuePair<string, int>> GetRankingList()
        {
            using (var db = new IdentityDbContext())
            {

                var sortedUser = AchievementDb.GetAllUser().OrderByDescending(x => x.RankingPoints);
                var returnList = new Dictionary<string, int>();
                foreach (var user in sortedUser)
                {
                    var userName = db.Users.First(u => u.Id.Equals(user.ReleatedApplicationUserId)).UserName;
                    returnList.Add(userName, user.RankingPoints);
                }
                return returnList.AsQueryable();
            }
        }
Exemple #44
0
        public bool removeRole(RoleViewModel model)
        {
            if (model.CurrentName == null || model.CurrentName == "" || model.CurrentName == "Admin" || model.CurrentName == "Staff")
            {
                return false;
            }

            using (var identityContext = new IdentityDbContext())
            {
                try
                {
                    identityContext.Roles.Remove(identityContext.Roles.Where(r => r.Name == model.CurrentName).FirstOrDefault());
                    return identityContext.SaveChanges() == 1;
                }
                catch
                {
                    return false;
                }

            }
        }
Exemple #45
0
        public bool SaveRole(RoleViewModel model)
        {
            if (model.NewName == null || model.NewName == "")
            {
                return false;
            }

            using (var identityContext = new IdentityDbContext())
            {
                try
                {
                    identityContext.Roles.AddOrUpdate(r => r.Name, new IdentityRole() { Name = model.NewName });
                    return identityContext.SaveChanges() == 1;
                }
                catch
                {
                    return false;
                }

            }
        }
        public ActionResult Users()
        {
            Administration.UsersViewModel mdl = new Administration.UsersViewModel();

            List<IdentityUser> userLogins;
            List<Repository.TeamMember> memberships;
            using(var usrContext = new IdentityDbContext())
            {
                userLogins = usrContext.Users.Include("Roles.Role").ToList();
                
            }

            using(var context = new Repository.BetaDepotContext())
            {
                memberships = context.TeamMembers.Include("UserMemberships").Where(w => w.IsSystemUser == false).ToList();
            }


            var rm = new RoleManager<IdentityRole>(
               new RoleStore<IdentityRole>(new ApplicationDbContext()));
            foreach (var u in userLogins)
            {
                Repository.TeamMember member = memberships.Where(w => w.UserName == u.UserName).FirstOrDefault();
                if(member != null)
                {
                    mdl.AppUsers.Add(new Administration.UsersViewModel.Users()
                    {
                        AppMemberCount = member.UserMemberships.Count(),
                        EmailAddress = member.EmailAddress,
                        UserName = member.UserName,
                        SystemRole = u.Roles.Select(s => s.Role.Name).Contains(Common.Constants.SYSTEM_ROLE_ADMINISTRATOR) ? Common.Constants.SYSTEM_ROLE_ADMINISTRATOR : Common.Constants.SYSTEM_ROLE_USER,
                        Name = string.Format("{0} {1}", member.FirstName, member.LastName),
                        GravitarUrl = string.Format("http://www.gravatar.com/avatar/{0}?s=36", Common.Functions.GenerateMD5Hash(member.EmailAddress.ToLower()))
                    }); 
                }
            }

            return View(mdl);
        }
        // GET: Home
        public async Task<ActionResult> Index()
        {
            var context = new IdentityDbContext<IdentityUser>(); // DefaultConnection
            var store = new UserStore<IdentityUser>(context);
            var manager = new UserManager<IdentityUser>(store);

            var email = "*****@*****.**";
            var password = "******";
            var user = await manager.FindByEmailAsync(email);

            if (user == null)
            {
                user = new IdentityUser
                {
                    UserName = email,
                    Email = email
                };

                await manager.CreateAsync(user, password);
            }


            return Content("Hello, Index");
        }
 public AccountController()
 {
     var context = new DispatcherContext();
     db = context;
     idContext =context;
 }
Exemple #49
0
 public AdminController()
 {
     IdentityDbContext<IdentityUser> db = new IdentityDbContext<IdentityUser>();
     UserManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(db));
 }
 public void Setup()
 {
     context = new IdentityDbContext();
     userStore = new UserStore(context);
     roleStore = new RoleStore(context);
 }
Exemple #51
0
 public UserAccountController(ApplicationUserManager userManager, IdentityDbContext context)
 {
     this.userManager = userManager;
     this.identityContext = context;
 }
 private IdentityDbContext CreateDb()
 {
     Database.SetInitializer(new DropCreateDatabaseAlways<IdentityDbContext>());
     var db = new IdentityDbContext();
     db.Database.Initialize(true);
     return db;
 }
Exemple #53
0
 public GroupManager(IdentityDbContext context) : base(context)
 {
 }
 public PermissionManager(IdentityDbContext context) : base(context)
 {
 }
Exemple #55
0
 public TestController(IdentityDbContext<User, Role, int, UserLogin, UserRole, UserClaim> context)
 {
 }
 public AuthenticationService(IdentityDbContext<User> context)
 {
     if (context == null)
         throw new ArgumentNullException("AuthenticationService: context can not be null.");
     UserManager = new UserManager<User>(new UserStore<User>(context));
 }
 public AuthRepository()
 {
     _ctx = new IdentityDbContext();
     _userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(_ctx));
     _roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>());
 }
        private void CreateUserAndRoles(IdentityDbContext context)
        {
            //Admin role for tenancy owner

            var adminRoleForTenancyOwner = context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == "Admin");
            if (adminRoleForTenancyOwner == null)
            {
                adminRoleForTenancyOwner = context.Roles.Add(new Role(null, "Admin", "Admin"));
                context.SaveChanges();

                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanCreateUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanEditUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanDeleteUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanDeleteRoles", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanCreateMenues", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanEditMenues", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForTenancyOwner.Id, Name = "CanDeleteMenues", IsGranted = true });
                context.SaveChanges();
            }

            //Admin user for tenancy owner

            var adminUserForTenancyOwner = context.Users.FirstOrDefault(u => u.TenantId == null && u.UserName == "admin");
            if (adminUserForTenancyOwner == null)
            {
                adminUserForTenancyOwner = context.Users.Add(
                    new User
                    {
                        TenantId = null,
                        UserName = "******",
                        Name = "System",
                        Surname = "Administrator",
                        EmailAddress = "*****@*****.**",
                        IsEmailConfirmed = true,
                        Password = "******" //123qwe
                    });

                context.SaveChanges();

                context.UserRoles.Add(new UserRole(adminUserForTenancyOwner.Id, adminRoleForTenancyOwner.Id));

                context.SaveChanges();
            }

            //Default tenant

            var defaultTenant = context.Tenants.FirstOrDefault(t => t.TenancyName == "Default");
            if (defaultTenant == null)
            {
                defaultTenant = context.Tenants.Add(new Tenant("Default", "Default"));
                context.SaveChanges();
            }

            //Admin role for 'Default' tenant

            var adminRoleForDefaultTenant = context.Roles.FirstOrDefault(r => r.TenantId == defaultTenant.Id && r.Name == "Admin");
            if (adminRoleForDefaultTenant == null)
            {
                adminRoleForDefaultTenant = context.Roles.Add(new Role(defaultTenant.Id, "Admin", "Admin"));
                context.SaveChanges();

                //Permission definitions for Admin of 'Default' tenant
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanCreateUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanEditUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanDeleteUsers", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanDeleteRoles", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanCreateMenues", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanEditMenues", IsGranted = true });
                context.Permissions.Add(new RolePermissionSetting { RoleId = adminRoleForDefaultTenant.Id, Name = "CanDeleteMenues", IsGranted = true });
                context.SaveChanges();
            }

            //User role for 'Default' tenant

            var userRoleForDefaultTenant = context.Roles.FirstOrDefault(r => r.TenantId == defaultTenant.Id && r.Name == "User");
            if (userRoleForDefaultTenant == null)
            {
                userRoleForDefaultTenant = context.Roles.Add(new Role(defaultTenant.Id, "User", "User"));
                context.SaveChanges();

                //Permission definitions for User of 'Default' tenant
                //context.Permissions.Add(new RolePermissionSetting { RoleId = userRoleForDefaultTenant.Id, Name = "CanCreateMenues", IsGranted = true });
                //context.SaveChanges();
            }

            //Admin for 'Default' tenant

            var adminUserForDefaultTenant = context.Users.FirstOrDefault(u => u.TenantId == defaultTenant.Id && u.UserName == "admin");
            if (adminUserForDefaultTenant == null)
            {
                adminUserForDefaultTenant = context.Users.Add(
                    new User
                    {
                        TenantId = defaultTenant.Id,
                        UserName = "******",
                        Name = "System",
                        Surname = "Administrator",
                        EmailAddress = "*****@*****.**",
                        IsEmailConfirmed = true,
                        Password = "******" //123qwe
                    });
                context.SaveChanges();

                context.UserRoles.Add(new UserRole(adminUserForDefaultTenant.Id, adminRoleForDefaultTenant.Id));
                context.UserRoles.Add(new UserRole(adminUserForDefaultTenant.Id, userRoleForDefaultTenant.Id));
                context.SaveChanges();

            }

            //User 'Emre' for 'Default' tenant

            var emreUserForDefaultTenant = context.Users.FirstOrDefault(u => u.TenantId == defaultTenant.Id && u.UserName == "emre");
            if (emreUserForDefaultTenant == null)
            {
                emreUserForDefaultTenant = context.Users.Add(
                    new User
                    {
                        TenantId = defaultTenant.Id,
                        UserName = "******",
                        Name = "Yunus Emre",
                        Surname = "Kalkan",
                        EmailAddress = "*****@*****.**",
                        IsEmailConfirmed = true,
                        Password = "******" //123qwe
                    });
                context.SaveChanges();

                context.UserRoles.Add(new UserRole(emreUserForDefaultTenant.Id, userRoleForDefaultTenant.Id));
                context.SaveChanges();
            }

            //Menu
            context.Menues.Add(new Menu(
                        "Menues",
                        "Menues",
                        defaultTenant.Id,
                        url: "#/menues",
                        icon: "fa fa-file",
                        requiredPermissionName: "Menues"
                        )
                        );
            context.Menues.Add(new Menu(
                "Users",
                "Users",
                defaultTenant.Id,
                url: "#/users",
                icon: "fa fa-user",
                requiredPermissionName: "Users"
                )
                );
            context.Menues.Add(new Menu(
                "Roles",
                "Roles",
                defaultTenant.Id,
                url: "#/roles",
                icon: "fa fa-group",
                requiredPermissionName: "Roles"
                )
                );
            context.Menues.Add(new Menu(
                    "UserRoles",
                    "UserRoles",
                    defaultTenant.Id,
                    url: "#/userroles",
                    icon: "fa fa-userplus",
                    requiredPermissionName: "UserRoles"
                    )
                );
            context.Menues.Add(new Menu(
                    "MenuRoles",
                    "MenuRoles",
                    defaultTenant.Id,
                    url: "#/menuroles",
                    icon: "fa fa-gears",
                    requiredPermissionName: "MenuRoles"
                    ));
            context.SaveChanges();
        }
Exemple #59
0
 public IoTClientManager(IdentityDbContext context) : base(context)
 {
 }
        static Startup()
        {
            PublicClientId = "self";

            UserManagerFactory = () =>
            {
                var context = new IdentityDbContext();
                System.Data.Entity.Database.SetInitializer<IdentityDbContext>(new IdentityDbInitializer());

                var userStore = new UserStore<IdentityUser>(context);
                userStore.DisposeContext = true;

                return new UserManager<IdentityUser>(userStore);
            };

            RoleManagerFactory = () =>
            {
                var context = new IdentityDbContext();
                System.Data.Entity.Database.SetInitializer<IdentityDbContext>(new IdentityDbInitializer());

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

                return new RoleManager<IdentityRole>(roleStore);
            };

            OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/Token"),
                Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
                AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                AllowInsecureHttp = true
            };
        }