Beispiel #1
0
        public static UsuarioAdmManager Create(IdentityFactoryOptions <UsuarioAdmManager> options,
                                               IOwinContext context)
        {
            var manager = new UsuarioAdmManager(new UserStore <UsuarioAdm>(context.Get <IdentityContext>()));

            // Configurando validator para nome de usuario
            manager.UserValidator = new UserValidator <UsuarioAdm>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            // Logica de validação e complexidade de senha
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = true,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true,
            };
            // Configuração de Lockout
            manager.UserLockoutEnabledByDefault          = true;
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // Registrando os providers para Two Factor.
            manager.RegisterTwoFactorProvider("Código via SMS", new PhoneNumberTokenProvider <UsuarioAdm>
            {
                MessageFormat = "Seu código de segurança é: {0}"
            });

            manager.RegisterTwoFactorProvider("Código via E-mail", new EmailTokenProvider <UsuarioAdm>
            {
                Subject    = "Código de Segurança",
                BodyFormat = "Seu código de segurança é: {0}"
            });

            // Definindo a classe de serviço de e-mail
            manager.EmailService = new EmailService();

            // Definindo a classe de serviço de SMS
            manager.SmsService = new SmsService();

            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <UsuarioAdm>(dataProtectionProvider.Create("ASP.NET Identity"));
            }

            return(manager);
        }
        private static Task <bool> VerifyClientIdAsync(UsuarioAdmManager manager, UsuarioAdm user, CookieValidateIdentityContext context)
        {
            string clientId = context.Identity.FindFirstValue("AspNet.Identity.ClientId");

            if (!string.IsNullOrEmpty(clientId) && user.Clients.Any(c => c.Id.ToString() == clientId))
            {
                user.CurrentClientId = clientId;
                return(Task.FromResult(true));
            }

            return(Task.FromResult(false));
        }
        private static async Task <bool> VerifySecurityStampAsync(UsuarioAdmManager manager, UsuarioAdm user, CookieValidateIdentityContext context)
        {
            string stamp = context.Identity.FindFirstValue("AspNet.Identity.SecurityStamp");

            return(stamp == await manager.GetSecurityStampAsync(context.Identity.GetUserId()));
        }
 public ApplicationSignInManager(UsuarioAdmManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }