예제 #1
0
        public async Task <string> GetEmailAsync(IdentityUser user)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                return((await db.Users.GetAsync(user.Id)).Email);
            }
        }
예제 #2
0
        public async Task <bool> GetTwoFactorEnabledAsync(IdentityUser user)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                return((await db.Users.GetAsync(user.Id)).TwoFactorEnabled);
            }
        }
예제 #3
0
        public async Task <bool> GetPhoneNumberConfirmedAsync(IdentityUser user)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                return((await db.Users.GetAsync(user.Id)).PhoneNumberConfirmed);
            }
        }
예제 #4
0
        public async Task DeleteAsync(IdentityRole role)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                var db = IdentityDatabase.Init(conn, 2);

                await db.Roles.DeleteAsync(role.Id);
            }
        }
예제 #5
0
        public async Task <bool> HasPasswordAsync(IdentityUser user)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                return(!string.IsNullOrEmpty(u.PasswordHash));
            }
        }
예제 #6
0
        public async Task CreateAsync(IdentityUser user)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                var result = await FindByEmailAsync(user.Email);

                if (result == null)
                {
                    await db.Users.InsertAsync(user);
                }
            }
        }
예제 #7
0
        public async Task SetTwoFactorEnabledAsync(IdentityUser user, bool enabled)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u != null)
                {
                    u.TwoFactorEnabled = enabled;

                    await db.Users.UpdateAsync(u.Id, u);
                }
            }
        }
예제 #8
0
        public async Task SetPhoneNumberConfirmedAsync(IdentityUser user, bool confirmed)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u != null)
                {
                    u.PhoneNumberConfirmed = confirmed;

                    await db.Users.UpdateAsync(u.Id, u);
                }
            }
        }
예제 #9
0
        public async Task SetEmailAsync(IdentityUser user, string email)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u != null)
                {
                    u.Email = email;

                    await db.Users.UpdateAsync(u.Id, u);
                }
            }
        }
예제 #10
0
        public async Task SetPasswordHashAsync(IdentityUser user, string passwordHash)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u != null)
                {
                    u.PasswordHash = passwordHash;

                    await db.Users.UpdateAsync(u.Id, u);
                }
            }
        }
예제 #11
0
        public async Task AddClaimAsync(IdentityUser user, Claim claim)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                var instance = new IdentityUserClaim
                {
                    UserId     = user.Id,
                    ClaimType  = claim.Type,
                    ClaimValue = claim.Value,
                };

                await db.UserClaims.InsertAsync(instance);
            }
        }
예제 #12
0
        public async Task SetSecurityStampAsync(IdentityUser user, string stamp)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u == null)
                {
                    throw new InvalidOperationException("Cannot find a user to set the security stamp.");
                }

                u.SecurityStamp = stamp;

                await db.Users.UpdateAsync(u.Id, u);
            }
        }
예제 #13
0
        public async Task AddToRoleAsync(IdentityUser user, string roleName)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityRole role = (await conn.QueryAsync <IdentityRole>(@"select * from Roles where Name=@RoleName", new { RoleName = roleName })).SingleOrDefault();
                if (role == null)
                {
                    throw new InvalidOperationException(string.Format("Role {0} not found.", roleName));
                }

                var instance = new IdentityUserRole
                {
                    RoleId = role.Id,
                    UserId = user.Id,
                };

                await db.UserRoles.InsertAsync(instance);
            }
        }
예제 #14
0
        public async Task <int> IncrementAccessFailedCountAsync(IdentityUser user)
        {
            //int result;

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                var db = IdentityDatabase.Init(conn, 2);

                IdentityUser u = await db.Users.GetAsync(user.Id);

                if (u == null)
                {
                    throw new ArgumentException("Cannot find user.");
                }

                int result = u.AccessFailedCount++;

                await db.Users.UpdateAsync(u.Id, u);

                return(result);
            }

            //return result;
        }