hack to check for existing emails

Makes it possible for admin to create users from admin panel
Forum rules
The content in this forum is dated Dec. 21 2005 and can be used as Archive only. This Forum is LOCKED and READ ONLY !

hack to check for existing emails

Postby packetrouter on Sat 15. May, 2004 18:45

I have added a hack to check the database for existing emails.. the same way a check is being done for existing usernames.

Replace:
Code: Select all
// Start add - Admin add user MOD
$new_user = (isset($HTTP_POST_VARS['new_user'])) ? (($HTTP_POST_VARS['new_user']==TRUE) ? TRUE : 0 ) : 0 ;
if ($new_user)
{
   //see if user already exist
   if (get_userdata($HTTP_POST_VARS['username']))
   {
      message_die(GENERAL_MESSAGE, $lang['Username_taken'] );
   }
   //see if default user exist
   if ( !($default_user = get_userdata(DEFAULT_USER_ID) ) )
   {
      message_die(CRITICAL_MESSAGE, 'The DEFAULT_USER_ID are not set correctly, please correct this in admin/admin_users.php');
   }
   if ($mode == 'save' && isset( $HTTP_POST_VARS['submit'] ) )
   {
      //we need to create the user
      $sql = "SELECT MAX(user_id) AS total
         FROM " . USERS_TABLE;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
      }
      if ( !($row = $db->sql_fetchrow($result)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
      }
      $user_id = $row['total'] + 1;
      $sql = "INSERT INTO " . USERS_TABLE . "   (user_id, username, user_regdate, user_active)
         VALUES ($user_id, 'new_user', " . time() . ",'0')";
      if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into users table', '', __LINE__, __FILE__, $sql);
      }
      $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user, group_moderator)
         VALUES ('', 'Personal User', 1, 0)";
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into groups table', '', __LINE__, __FILE__, $sql);
      }
      $group_id = $db->sql_nextid();
      //go get the usergroups, the default user are member of
      $sql = "SELECT g.group_id
         FROM " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
         WHERE NOT g.group_single_user AND ug.group_id=g.group_id AND ug.user_id='".DEFAULT_USER_ID."'";
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain default user group information', '', __LINE__, __FILE__, $sql);
      }
      while ($group_data = $db->sql_fetchrow($result))
      {
         //user join default groups
         $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
            VALUES (".$group_data['group_id'].", $user_id, '0')";
         if ( !($db->sql_query($sql)) )
         {
            message_die(GENERAL_ERROR, 'Error insert default groupst', '', __LINE__, __FILE__, $sql);
         }
      }

      $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
         VALUES ($user_id, $group_id, 0)";
      if( !($result = $db->sql_query($sql, END_TRANSACTION)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into user_group table', '', __LINE__, __FILE__, $sql);
      }
      $HTTP_POST_VARS[POST_USERS_URL] = $user_id;
   } else
   {
      //make script use default user as a starting point
      $HTTP_POST_VARS[POST_USERS_URL] = DEFAULT_USER_ID;
   }
}
// End add - Admin add user MOD

with
Code: Select all
// Start add - Admin add user MOD
$new_user = (isset($HTTP_POST_VARS['new_user'])) ? (($HTTP_POST_VARS['new_user']==TRUE) ? TRUE : 0 ) : 0 ;
if ($new_user)
{
   //see if user already exist
   if (get_userdata($HTTP_POST_VARS['username']))
   {
      message_die(GENERAL_MESSAGE, $lang['Username_taken'] );
   }

   //see if default user exist
   if ( !($default_user = get_userdata(DEFAULT_USER_ID) ) )
   {
      message_die(CRITICAL_MESSAGE, 'The DEFAULT_USER_ID are not set correctly, please correct this in admin/admin_users.php');
   }
   if ($mode == 'save' && isset( $HTTP_POST_VARS['submit'] ) )
   {
      //see if the email address exists
      $result = validate_email($HTTP_POST_VARS['email']);
      if ( $result['error'] )
      {
         message_die(GENERAL_MESSAGE, $lang['Email_taken'] );
      }      
      //we need to create the user
      $sql = "SELECT MAX(user_id) AS total
         FROM " . USERS_TABLE;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
      }
      if ( !($row = $db->sql_fetchrow($result)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain next user_id information', '', __LINE__, __FILE__, $sql);
      }
      $user_id = $row['total'] + 1;
      $sql = "INSERT INTO " . USERS_TABLE . "   (user_id, username, user_regdate, user_active)
         VALUES ($user_id, 'new_user', " . time() . ",'0')";
      if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into users table', '', __LINE__, __FILE__, $sql);
      }
      $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user, group_moderator)
         VALUES ('', 'Personal User', 1, 0)";
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into groups table', '', __LINE__, __FILE__, $sql);
      }
      $group_id = $db->sql_nextid();
      //go get the usergroups, the default user are member of
      $sql = "SELECT g.group_id
         FROM " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
         WHERE NOT g.group_single_user AND ug.group_id=g.group_id AND ug.user_id='".DEFAULT_USER_ID."'";
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain default user group information', '', __LINE__, __FILE__, $sql);
      }
      while ($group_data = $db->sql_fetchrow($result))
      {
         //user join default groups
         $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
            VALUES (".$group_data['group_id'].", $user_id, '0')";
         if ( !($db->sql_query($sql)) )
         {
            message_die(GENERAL_ERROR, 'Error insert default groupst', '', __LINE__, __FILE__, $sql);
         }
      }

      $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
         VALUES ($user_id, $group_id, 0)";
      if( !($result = $db->sql_query($sql, END_TRANSACTION)) )
      {
         message_die(GENERAL_ERROR, 'Could not insert data into user_group table', '', __LINE__, __FILE__, $sql);
      }
      $HTTP_POST_VARS[POST_USERS_URL] = $user_id;
   } else
   {
      //make script use default user as a starting point
      $HTTP_POST_VARS[POST_USERS_URL] = DEFAULT_USER_ID;
   }
}
// End add - Admin add user MOD


Hope this helps. :)
Visit my Code Resource Forum at http://www.techsatcomputers.com and be part of a growing Community.
packetrouter
Poster
Poster
 
Posts: 8
Joined: Mon 06. Jan, 2003 15:31

Return to Admin add users [2.0.8/EM]

Who is online

Users browsing this forum: No registered users and 1 guest

cron