Example #1
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName");
            try
            {
                using (var session = new MongoSession(_connectionString))
                {
                    var role = (from r in session.Roles
                                where r.RoleName == roleName
                                select r).SingleOrDefault();


                    var users = session.Users
                                .Where(u => u.Roles != null)
                                .Where(u => u.Roles.Any(r => r.RoleName == roleName));


                    if (users.Any() && throwOnPopulatedRole)
                    {
                        throw new ProviderException(StringResources.GetString(StringResources.Role_is_not_empty));
                    }

                    session.DeleteById <MembershipRole>(role.RoleId);

                    return(true);
                }
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Deletes the OAuth token from the backing store from the database.
        /// </summary>
        /// <param name="token">The token to be deleted.</param>
        public override void DeleteOAuthToken(string token)
        {
            VerifyInitialized();

            using (var session = new MongoSession(_connectionString))
            {
                // Note that token is case-sensitive
                session.DeleteById <OAuthToken>(token);
            }
        }
Example #3
0
        // Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method
        public override bool DeleteAccount(string userName)
        {
            VerifyInitialized();

            int userId = GetUserId(_session, userName);

            if (userId == -1)
            {
                return(false); // User not found
            }


            try
            {
                _session.DeleteById <MembershipAccount>(userId);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// Replaces the request token with access token and secret.
        /// </summary>
        /// <param name="requestToken">The request token.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="accessTokenSecret">The access token secret.</param>
        public override void ReplaceOAuthRequestTokenWithAccessToken(string requestToken, string accessToken, string accessTokenSecret)
        {
            VerifyInitialized();

            using (var session = new MongoSession(_connectionString))
            {
                // insert new record
                session.DeleteById <OAuthToken>(requestToken);

                // Although there are two different types of tokens, request token and access token,
                // we treat them the same in database records.
                StoreOAuthRequestToken(accessToken, accessTokenSecret);
            }
        }
Example #5
0
        public static bool DeletePermission(string name, bool throwException = true)
        {
            MembershipPermission permission = _session.Permissions.FirstOrDefault(x => x.Name == name);
            var rolesWithPermissionCount    = _session.Roles.Where(x => x.Permissions.Any(y => y == permission.Name)).Count();
            var usersWithPermissionCount    = _session.Users.Where(x => x.Permissions.Any(y => y == permission.Name)).Count();

            if (permission != null && rolesWithPermissionCount == 0 && usersWithPermissionCount == 0)
            {
                _session.DeleteById <MembershipPermission>(permission.Name);

                return(true);
            }

            if (throwException)
            {
                throw new ProviderException("Permission is not empty");
            }

            return(false);
        }
        // Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method
        public override bool DeleteAccount(string userName)
        {
            VerifyInitialized();

            using (var session = new MongoSession(_connectionString))
            {
                int userId = GetUserId(session, userName);
                if (userId == -1)
                {
                    return(false); // User not found
                }


                try
                {
                    session.DeleteById <MembershipAccount>(userId);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }