Exemplo n.º 1
0
        public static MyApplicationUserManager Create(IdentityFactoryOptions <MyApplicationUserManager> options, IOwinContext context)
        {
            var manager = new MyApplicationUserManager(new MyUserStore(CurrentUser.GetCurrentUserInfo()))
            {
                PasswordHasher = new MyPasswordHasher()
            };

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <MyUser, string>(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 = false;
            //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 <MyUser, string>
            {
                MessageFormat = "Your security code is {0}"
            });

            manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider <MyUser, string>
            {
                Subject    = "Welcome to Identity ststem",
                BodyFormat = "Your security code is {0}"
            });

            manager.EmailService = new MyEmailService();
            manager.SmsService   = new MySmsService();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (manager.UserTokenProvider == null)
            {
                manager.UserTokenProvider = new DataProtectorTokenProvider <MyUser, string>(dataProtectionProvider.Create("Stone ASP.NET Identity"));
            }
            return(manager);
        }
Exemplo n.º 2
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(MyApplicationUserManager manager)
        {
            //AuthenticationType must be the same as the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            //Add custom user claims here
            userIdentity.AddClaim(new Claim(CustomClaims.Firstname, Firstname, ClaimValueTypes.String));
            userIdentity.AddClaim(new Claim(CustomClaims.Lastname, Lastname, ClaimValueTypes.String));
            userIdentity.AddClaim(new Claim(CustomClaims.Fullname, Fullname, ClaimValueTypes.String));
            userIdentity.AddClaim(new Claim(CustomClaims.Active, Active.ToString(), ClaimValueTypes.Boolean));
            userIdentity.AddClaim(new Claim(CustomClaims.ProfilePic, ProfilePic, ClaimValueTypes.String));

            foreach (var role in Roles)
            {
                userIdentity.AddClaim(new Claim(ClaimTypes.Role, role, ClaimValueTypes.String));
            }

            return(userIdentity);
        }
Exemplo n.º 3
0
 public MyApplicationSignInManager(MyApplicationUserManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }