示例#1
0
        public async Task Test_add_user_modify_lockout_end_date_delete()
        {
            var dao = Global.TenantDao;
            await dao.EstablishConnectionAsync();

            var guidId    = Guid.NewGuid();
            var userStore = new CassandraUserStore();

            string userName = Guid.NewGuid().ToString();
            var    user     = new CassandraUser()
            {
                Email                = userName,
                UserName             = userName,
                EmailConfirmed       = false,
                PhoneNumberConfirmed = false,
                PhoneNumber          = "310.383.1111",
                LockoutEnabled       = false,
                PasswordHash         = "1234",
                SecurityStamp        = "1234",
                LockoutEndDate       = DateTimeOffset.UtcNow
            };
            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            var lockOutDate = await userStore.GetLockoutEndDateAsync(foundUser);

            Assert.AreEqual(lockOutDate.Day, user.LockoutEndDate.Day);
            Assert.AreEqual(lockOutDate.Hour, user.LockoutEndDate.Hour);
            Assert.AreEqual(lockOutDate.Minute, user.LockoutEndDate.Minute);
            Assert.AreEqual(lockOutDate.Year, user.LockoutEndDate.Year);

            var future = user.LockoutEndDate.AddDays(5);
            await userStore.SetLockoutEndDateAsync(foundUser, future);

            await userStore.UpdateAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            lockOutDate = await userStore.GetLockoutEndDateAsync(foundUser);

            Assert.AreEqual(lockOutDate.Day, future.Day);
            Assert.AreEqual(lockOutDate.Hour, future.Hour);
            Assert.AreEqual(lockOutDate.Minute, future.Minute);
            Assert.AreEqual(lockOutDate.Year, future.Year);

            await userStore.DeleteAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNull(foundUser);
        }
示例#2
0
        public async Task Test_add_user_modify_twofactor_enabled_delete()
        {
            var dao = Global.TenantDao;
            await dao.EstablishConnectionAsync();

            var guidId    = Guid.NewGuid();
            var userStore = new CassandraUserStore();

            string userName = Guid.NewGuid().ToString();
            var    user     = new CassandraUser()
            {
                Email                = userName,
                UserName             = userName,
                EmailConfirmed       = false,
                PhoneNumberConfirmed = false,
                PhoneNumber          = "310.383.1111",
                LockoutEnabled       = false,
                PasswordHash         = "1234",
                SecurityStamp        = "1234",
                TwoFactorEnabled     = false
            };
            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.IsFalse(await userStore.GetTwoFactorEnabledAsync(foundUser));

            await userStore.SetTwoFactorEnabledAsync(foundUser, true);

            await userStore.UpdateAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.IsTrue(await userStore.GetTwoFactorEnabledAsync(foundUser));

            await userStore.DeleteAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNull(foundUser);
        }
示例#3
0
        public async Task Test_add_user_modify_password_hash_delete()
        {
            var dao = Global.TenantDao;
            await dao.EstablishConnectionAsync();

            var guidId    = Guid.NewGuid();
            var userStore = new CassandraUserStore();

            string userName = Guid.NewGuid().ToString();
            var    user     = new CassandraUser()
            {
                Email                = userName,
                UserName             = userName,
                EmailConfirmed       = false,
                PhoneNumberConfirmed = false,
                PhoneNumber          = "310.383.1111",
                LockoutEnabled       = false,
                PasswordHash         = "1234"
            };
            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.AreEqual(await userStore.GetPasswordHashAsync(foundUser), "1234");

            await userStore.SetPasswordHashAsync(foundUser, "abcd");

            await userStore.UpdateAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.AreEqual(await userStore.GetPasswordHashAsync(foundUser), "abcd");

            await userStore.DeleteAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNull(foundUser);
        }
示例#4
0
        public async Task Test_add_user_modify_phone_confirmed_delete()
        {
            var dao = Global.TenantDao;
            await dao.EstablishConnectionAsync();

            var guidId    = Guid.NewGuid();
            var userStore = new CassandraUserStore();

            string userName = Guid.NewGuid().ToString();
            var    user     = new CassandraUser()
            {
                Email                = userName,
                UserName             = userName,
                EmailConfirmed       = false,
                PhoneNumberConfirmed = false
            };
            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.IsFalse(await userStore.GetPhoneNumberConfirmedAsync(foundUser));

            await userStore.SetPhoneNumberConfirmedAsync(foundUser, true);

            await userStore.UpdateAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNotNull(foundUser);
            Assert.IsTrue(await userStore.GetPhoneNumberConfirmedAsync(foundUser));

            await userStore.DeleteAsync(foundUser);

            foundUser = await userStore.FindByEmailAsync(userName);

            Assert.IsNull(foundUser);
        }
        public override async Task AuthenticateLocalAsync(LocalAuthenticationContext context)
        {
            var user = await _userStore.FindByEmailAsync(context.UserName);

            if (user != null)
            {
                IPasswordHasher passwordHasher = new PasswordHasher();
                var             hash           = passwordHasher.HashPassword(password: context.Password);
                var             result         = passwordHasher.VerifyHashedPassword(user.PasswordHash, context.Password);
                if (result == PasswordVerificationResult.Success)
                {
                    context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), context.UserName);
                }
            }
        }