I need to be able to use this module to send out codes in sms messages and then have people register using their assigned code but allow only one registration per code and, if possible, store the used code in the user's profile.

I really need this and i need it quickly so am prepared to pay for the development.

I also think it would be a worthy addition to a great module (-:

Comments

colan’s picture

I agree. This would indeed be an excellent feature; other folks have requested it too. Unfortunately, I don't have time to take on any new paid work until September. I've got some projects that are keeping me busy full-time.

If someone else steps up, or you can find someone to do the work required in coming up with a patch, I'll gladly merge the feature into a future release (as long as it's tested and the code is in line with the Drupal coding standards).

bakwas_internet’s picture

Status: Active » Needs review

Did some hacking and finally came up with following code. This is working fine on my system. Can other people test it and give me their feedback.


     if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }
          // code to remove the reg code which has been used once
          else
          {
          	$removekey= array_search(trim($edit['regcode_code']), $regcodes);
          	unset ($regcodes[$removekey]);
          	$regcodestring= join("\n",$regcodes);
          	variable_set('regcode_codes',$regcodestring);
          }
        }
        break;
bakwas_internet’s picture

There is one problem with above code. It removes a regcode even if user registration form is not accepted due to some error in some other field(such as email or password etc.). is there any way to check whether form has been filled correctly.

colan’s picture

Priority: Critical » Normal

I'm moving this down from "critical", which usually means the module is very broken. This is just a feature request, albeit a good one. ;)

colan’s picture

Status: Needs review » Needs work

bakwas_internet: Thanks for working on this. One other thing to be aware of is that this module was originally meant provide a small number of passwords for the site. (This was mentioned by jvermillion.)

In that sense, it was fine to keep these passwords as one or many Drupal variables because there were a small number of them. If the registration codes are to be individually generated, that means that there could be a lot of data. We don't want to keep this much information in a variable or variables because this would take up a lot of memory when there are many users.

The way to properly deal with this, then, would be for this module to have its own database table that will store the information for many users.

Bassel’s picture

Version: 5.x-1.x-dev » 5.x-2.0

The new update of the registration code module has been a great improvement, but may be if we can have a two-columns table, a column for the registration code itself and a column for the user id. By doing this we assure that only registration codes with no user id are available for the registration process, and in the same time we keep track of the used registration codes and by which user has been used.

I am suggesting this because this is a scenario that I have been asked to do.

I wish I have the experience to do this and to contribute myself, but I am still in the learning stage right now.

Thanx,

Bassel’s picture

This might be a bad work around but it works 100%.

After digging around I found out that Drupal stores the registration codes which have been used previously by each user upon registration in a column named “data” in the “users” table.

So it would be enough to compare the newly entered registration code with the already available registration codes. My problem is I don’t know how to extract the registration code out of the “data” column and I have no experience developing in PHP and I needed this quickly. So I came up with the following solution which worked 100% with me.

Create a table:

create table regcodes (uid int(10) unsigned primary key,code varchar(64) unique not null);

and then change the "regcode.module" to be like this:

      case 'validate':
        if (($category == 'account') && (!$account->uid)) {   
          // Make sure that the entered code is in the list.
          $regcodes = explode("\n", $regcodes);
          array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
          if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }

// new code
          $nofusers=db_result(db_query("select count(*) from regcodes where code='%s'",trim($edit['regcode_code'])));
          if ($nofusers) {
          form_set_error('regcode_code', t('The registration code you provided has been used before'));
            }
// end of new code

        }
        break;

// new code
      case 'insert':
        db_query("insert into regcodes(uid,code)  values(%d,'%s')",$account->uid,trim($edit['regcode_code']));
// end of new code

    } // switch
  }
}

My solution made the registration codes to be stored twice in the “regcodes” and “variable” tables, which is off course a stupid thing to do.

off course the perfect scenario would be to rewrite the module, so that we have the codes stored in a separate table “regcodes” with a similar structure that I used and to have an option in the registration codes setup page whether we need the registration codes to be uniquely used by users or not.

lelizondo’s picture

Great patch, it works for me..

The regcode.install would be something like this:

<?php
// $Id: regcode.install,v 1.1.2.1 2007/04/18 20:58:09 colan Exp $

/**
 * Create a table to store the used valid codes
*/

function regcode_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {regcodes} (
        uid int(10) unsigned primary key,code varchar(64) unique not null
        )"
      );
  }
}

/**
 * Implementation of hook_uninstall().
 */

function regcode_uninstall() {
  variable_del('regcode_codes');
}

?>
-enzo-’s picture

Hello People

I reuse the code posted on this thread to create a new path to support Registration codes by account type with expiration more information at http://drupal.org/node/361527.

Thanks a lot to all people for his contribution.

Best regards

enzo

danielnolde’s picture

Hey regcode-users,

i just posted a ready-for-review proposal of a completely reworked new regcode.module (still D5, but soon to be upgraded to D6 & D7). This new to-become-release is solving a lot of feature-requests and issues (this one too!) on a completely new and flexible basis.

Check it out, test it and give feedback whether you think it solves your issues, and whether it's ready to be committed:

http://drupal.org/node/466630

cheers,

daniel

aidanlis’s picture

Status: Needs work » Closed (fixed)

Implemented in the D6 and D5 versions now.