Пример #1
0
        public static VesiPortalUserManager Create(IdentityFactoryOptions <VesiPortalUserManager> options, IOwinContext context)
        {
            var manager = new VesiPortalUserManager(new UserStore <ApplicationUser, VesiPortalRole, Guid, VesiPortalUserLogin, VesiPortalUserRole, VesiPortalUserClaim>(context.Get <VesiPortalDbContext>()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <ApplicationUser, Guid>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = false,
                RequireDigit            = false,
                RequireLowercase        = false,
                RequireUppercase        = false,
            };

            // Configure user lockout defaults
            manager.UserLockoutEnabledByDefault          = true;
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
            // You can write your own provider and plug it in here.
            manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider <ApplicationUser, Guid>
            {
                MessageFormat = "Your security code is {0}"
            });
            manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider <ApplicationUser, Guid>
            {
                Subject    = "Security Code",
                BodyFormat = "Your security code is {0}"
            });
            manager.EmailService = new EmailService();
            manager.SmsService   = new SmsService();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <ApplicationUser, Guid>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }
Пример #2
0
 public ApplicationSignInManager(VesiPortalUserManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }
Пример #3
0
        // In this method we will create default User roles and Admin user for login
        private void CreateRolesandUsers()
        {
            VesiPortalDbContext context = new VesiPortalDbContext();

            var roleManager = new VesiPortalRoleManager(new VesiPortalRoleStore(context));
            var UserManager = new VesiPortalUserManager(new VesiPortalUserStore(context));

            //var UserManager = HttpContext.Current.GetOwinContext().Get<VesiPortalUserManager>(null);

            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new VesiPortalRole
                {
                    Id   = Guid.NewGuid(),
                    Name = "Admin"
                };
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website

                var user = new AdminUser
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "Toni",
                    LastName  = "Kuosmanen",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };



                string userPWD = "_bWx5krnd";

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            // creating Creating customer role
            if (!roleManager.RoleExists("Customer"))
            {
                var role = new VesiPortalRole();
                role.Id   = Guid.NewGuid();
                role.Name = "Customer";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("WaterworkUser"))
            {
                var role = new VesiPortalRole();
                role.Id   = Guid.NewGuid();
                role.Name = "WaterworkUser";
                roleManager.Create(role);
            }
        }