Exemple #1
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(BusLocatorUserManager manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            userIdentity.AddClaim(new Claim("UserId", Id));
            userIdentity.AddClaim(new Claim("UserFullname", FullName ?? ""));
            return(userIdentity);
        }
Exemple #2
0
        protected override void Seed(BusLocatorContext context)
        {
            BusLocatorUserManager userManager = new BusLocatorUserManager(new BusLocatorUserStore(context));
            BusLocatorRoleManager roleManager = new BusLocatorRoleManager(new BusLocatorRoleStore(context));

            //System.Web.HttpContext.Current.GetOwinContext().

            const string name     = "*****@*****.**";
            string       password = "******";

            string[] roles = { "Admin", "User", "Driver" };

            foreach (string rolename in roles)
            {
                var role = roleManager.FindByName(rolename);
                if (role == null)
                {
                    role = new RoleBO(rolename);
                    var roleresult = roleManager.Create(role);
                }
            }

            RoleBO role1 = roleManager.FindByName(roles[0]);
            RoleBO role2 = roleManager.FindByName(roles[1]);

            var user = userManager.FindByName(name);

            if (user == null)
            {
                user = new UserBO
                {
                    UserName         = name,
                    Email            = name,
                    FullName         = "Global Admin",
                    EmailConfirmed   = true,
                    LockoutEnabled   = false,
                    Audit            = new Domain.Entity.Audit(),
                    HasAcceptedTerms = true,
                };
                var result = userManager.Create(user, password);
                result = userManager.SetLockoutEnabled(user.Id, false);
            }

            var rolesForUser = userManager.GetRoles(user.Id);

            if (!rolesForUser.Contains("Admin"))
            {
                userManager.AddToRole(user.Id, "Admin");
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_userManager != null)
                {
                    _userManager.Dispose();
                    _userManager = null;
                }

                if (_signInManager != null)
                {
                    _signInManager.Dispose();
                    _signInManager = null;
                }

                if (_roleManager != null)
                {
                    _roleManager.Dispose();
                    _roleManager = null;
                }
            }
            base.Dispose(disposing);
        }
 public BaseController(BusLocatorUserManager userManager, BusLocatorSignInManager signInManager, BusLocatorRoleManager roleManager)
 {
     UserManager   = userManager;
     SignInManager = signInManager;
     RoleManager   = roleManager;
 }