Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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));
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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;
        }