We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18436
    • 135 Posts
    Hey guys, after a few months of informal monitoring of my site I recently did a major upgrade. Much to my horror I discovered over 200 hundred bogus registered users (mainly with .ru addresses, and I thought CAPTCHA was secure). Now I know that user mamagement and community building isn’t the strong point of MODX at the moment but is there anyway to implement a checkbox or something into the manager interface that allows you to process more than one account at a time?

    200 users x 3 clicks + 200 page refeshes = a huge waste of time...

    Please guys, even if you know some SQL syntax to do this I’d be stoked, since I find myself using SQLYog more and more to manage online/offline syncs, sadly my host os still runnning MySQL 4...
      • 18436
      • 135 Posts
      Blocking might not be a bad idea, I was wondering how you would do a cascade delete on the modx_web_users_attributes table as well...
        • 33337
        • 3,975 Posts
        Zaigham (aka zi) Reply #3, 19 years ago
        I would check the code behind the "delete" button wink...
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 18436
          • 135 Posts
          Thought about doing that from the start and managed to find the sql used in delete_web_user.processor.php
          Any SQL guru’s know if you can combine the two seperate DELETE queries into one?
            • 2328
            • 39 Posts
            If it’s any help, I wrote a "web user approval" snippet for my front-end.

            At present, it only approves users using a list of checkboxes (I use a probationary member type for new sign-ups since my user base is _very_ small), but I need to modify it to delete unapproved users (a minor oversight there!). I could post the code if you’re interested.

            At the very least it could form the basis of preventing it getting to this stage again!
              • 18436
              • 135 Posts
              I’d appreciate that, any code examples would be great!
                • 2328
                • 39 Posts
                Ok, I’ll try and get the existing code up over the weekend (I ought to check it for thoroughness first!) - and maybe a modified version later in the week to include deleting.
                  • 2328
                  • 39 Posts
                  Here you are:

                  $wua_str_snip_path = $modx->config['base_path'] . "assets/snippets/";
                  include_once $wua_str_snip_path."weblogin/weblogin.common.inc.php";
                  
                  $wua_str_output = '';
                  
                  // Access control
                  if ( !$modx->isMemberOfWebGroup( array( 'Administrator' ) ) ) {
                    return $wua_str_output;
                  }
                  
                  // Do we have any probationary users?
                  $wua_arr_probationary_users = $modx->getIntTableRows( 'webuser', 'web_groups', 'webgroup=4' );
                  if ( count( $wua_arr_probationary_users ) == 0 ) {
                    unset( $wua_arr_probationary_users );
                  
                    return $wua_str_output;
                  }
                  
                  // Do we have entries to approve?
                  if ( count( $_POST ) > 1 ) {
                    $wua_arr_approved_users = array();
                    foreach( $wua_arr_probationary_users as $wua_arr_user ) {
                      if ( $_POST[$wua_arr_user['webuser'].'/approved'] ) {
                        $wua_arr_this_user = $modx->getWebUserInfo( $wua_arr_user['webuser'] );
                        
                        // Update user membership
                        $modx->updIntTableRow( array( 'webgroup' => 1 ), 'web_groups', 'webuser='.$wua_arr_this_user['id'] );
                  
                        // Generate password
                        $wua_str_password = webLoginGeneratePassword();
                        
                        // Update user password
                        $wua_sql = "UPDATE ".$modx->getFullTableName( "web_users" )."
                                  SET password=md5('".$wua_str_password."')
                                  WHERE id=".$wua_arr_this_user['id'].";";
                        $wua_rs = $modx->db->query( $wua_sql );
                        if( !$wua_rs ) {
                            $wua_str_output .= webLoginAlert( "An error occured while attempting to update the password." );
                  
                            unset( $wua_str_password );
                            unset( $wua_arr_approved_users );
                            unset( $wua_arr_this_user );
                            unset( $wua_arr_user );
                  
                            return $wua_str_output;
                        }
                  
                        // send email notification
                        $wua_rt = webUserApprovalSendNewPassword( $wua_arr_this_user['email'],
                                                              $wua_arr_this_user['username'],
                                                              $wua_str_password,
                                                              $wua_arr_this_user['fullname'] );
                        if ( $wua_rt !== true ) { // an error occured
                          $wua_str_output .= $wua_rt;
                  
                          unset( $wua_str_password );
                          unset( $wua_arr_approved_users );
                          unset( $wua_arr_this_user );
                          unset( $wua_arr_user );
                  
                          return $wua_str_output;
                        }       $wua_arr_approved_users[] = $wua_arr_this_user['username'];
                      }
                    }
                    if ( count( $wua_arr_approved_users ) > 0 ) {
                      $wua_str_output .= '
                      <p>The following users have been approved as members: '.implode( ', ', $wua_arr_approved_users ).'</p>';
                    }
                    unset( $wua_str_password );
                    unset( $wua_arr_approved_users );
                    unset( $wua_arr_this_user );
                    unset( $wua_arr_user );
                    
                    // Reload list
                    unset( $wua_arr_probationary_users );
                    $wua_arr_probationary_users = $modx->getIntTableRows( 'webuser', 'web_groups', 'webgroup=4' );
                    if ( count( $wua_arr_probationary_users ) == 0 ) {
                      unset( $wua_arr_probationary_users );
                  
                      return $wua_str_output;
                    }
                  }
                  
                  // Form with list of probationary users
                  $wua_str_output = '
                      <form id="WebRegisterForm" method="post" action="'.$modx->makeURL( $modx->documentIdentifier ).'">
                        <fieldset>
                          <legend>The following probationary users are awaiting approval:</legend>
                          <table>
                            <tr>
                              <th scope="col">Username</th>
                              <th scope="col">Real name</th>
                              <th scope="col">Email address</th>
                            </tr>';
                  foreach( $wua_arr_probationary_users as $wua_arr_user ) {
                    $wua_arr_this_user = $modx->getWebUserInfo( $wua_arr_user['webuser'] );
                    $wua_str_output .= '
                            <tr>
                              <th scope="row">'.$wua_arr_this_user['username'].'</th>
                              <td>'.$wua_arr_this_user['fullname'].'</td>
                              <td>'.$wua_arr_this_user['email'].'</td>
                              <td><input class="checkbox" type="checkbox" name="'.$wua_arr_this_user['id'].'/approved" /></td>
                            </tr>';
                  }
                  $wua_str_output .= '
                          </table>
                        </fieldset>
                        <p class="right">
                          <input class="button" type="submit" value="Submit" name="cmdwebapproval" />
                          <input class="button" type="reset" value="Reset" name="cmdreset" />
                        </p>
                      </form>';
                  
                  unset( $wua_arr_this_user );
                  unset( $wua_arr_user );
                  unset( $wua_arr_probationary_users );
                  
                  return $wua_str_output;


                  It’s based around the idea that newly-registered users are assigned to a "probationary" group (who aren’t allowed to post). This code allows you to view the probationary users and approve them by changing their user groups.

                  What it doesn’t do is delete the unapproved - yet!

                  Let me know if you have any queries.