示例#1
0
        public static CustomUserManager Create(IdentityFactoryOptions <CustomUserManager> options, IOwinContext context)
        {
            var manager =
                new CustomUserManager(new UserStoreInt(context.Get <AppUserIdentityDbContext>()));

            return(manager);
        }
示例#2
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(CustomUserManager manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            return(userIdentity);
        }
示例#3
0
        private async Task <SignInStatus> SignInOrTwoFactor(CustUserIdentity user, bool isPersistent)
        {
            if (await CustomUserManager.GetTwoFactorEnabledAsync(user.Id) &&
                !await AuthenticationManager.TwoFactorBrowserRememberedAsync(user.Id.ToString()))
            {
                var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()));
                identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
                AuthenticationManager.SignIn(identity);
                return(SignInStatus.RequiresTwoFactorAuthentication);
            }
            await SignInAsync(user, isPersistent, false);

            return(SignInStatus.Success);
        }
示例#4
0
        public async Task <SignInStatus> PasswordSignIn(string userName, string password, bool isPersistent)
        {
            var user = await CustomUserManager.FindByNameAsync(userName);

            if (user == null)
            {
                return(SignInStatus.Failure);
            }
            if (await CustomUserManager.CheckPasswordAsync(user, password))
            {
                return(await SignInOrTwoFactor(user, isPersistent));
            }
            if (await CustomUserManager.IsLockedOutAsync(user.Id))
            {
                return(SignInStatus.LockedOut);
            }

            return(SignInStatus.Failure);
        }
示例#5
0
 public SignIn(CustomUserManager customManager, IAuthenticationManager authManager)
 {
     CustomUserManager     = customManager;
     AuthenticationManager = authManager;
 }