I found this code in the FAQ under email user after signup:
# Check to make sure userid is ok, pw ok, and userid is unique.
unless ((length($in{'userid'}) >= 3) and (length($in{'userid'}) <= 12) and ($in{'userid'} =~ /^[a-zA-Z0-9]+$/)) {
$message = ''Invalid userid: $in{'userid'}. Must only contain only letters and be less then 12 and greater then 3 characters.'';
}
unless ($in{'email'} =~ /.+\@.+\..+/) {
$message = ''Invalid email address format: '$in{'email'}'.'';
}
open (PASSWD, ''<$auth_pw_file'') || &cgierr(''unable to open password file. Reason: $!\n'');
@passwds = ;
close PASSWD;
foreach $pass (@passwds) { # Go through each pass and see if we match..
next if ($pass =~ /^$/); # Skip blank lines.
next if ($pass =~ /^#/); # Skip Comment lines.
chomp ($pass);
($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $pass);
if (lc($in{'userid'}) eq lc($userid)) {
$message = ''userid already exists. Please try another.
'';
}
if (lc($in{'email'}) eq lc($email)) {
$message .= ''email address already exists.'';
}
}
if ($message) {
&html_signup_form ($message);
return;
}
$in{'pw'} = &generate_password;
$in{'email'} = lc($in{'email'});
# Add the userid into the file with signup permissions.
open (PASS, ''>>$auth_pw_file'') or &cgierr (''unable to open: $auth_pw_file.\nReason: $!'');
if ($db_use_flock) {
flock(PASS, 2) or &cgierr(''unable to get exclusive lock on $auth_pw_file.\nReason: $!'');
}
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'pw'}, $salt);
my $permissions = join ('':'', @auth_signup_permissions);
print PASS ''$in{'userid'}:$encrypted:$permissions:$in{'email'}\n'';
close PASS;
But the only thing I need out of this is the part that opens the pass file to get the password to include in the email. I have no idea what half of this stuff means. I assume that it starts with the OPEN PASS line, but i'm not sure what after that because it looks like alot of checking going on in there also. I am in need of this code to email the user after they fill out the signup form AND add their user record via the users.db add form where they supply their email address.
Can someone tell me what needs to come out this bit of code to do what I need? BTW, this code to print the email is in my add_success sub and not the signup_success. Thanks!
Code:
my ($message,$userid, $pw, $view, $add, $del, $mod, $mem, $admin, $email, $password); # Check to make sure userid is ok, pw ok, and userid is unique.
unless ((length($in{'userid'}) >= 3) and (length($in{'userid'}) <= 12) and ($in{'userid'} =~ /^[a-zA-Z0-9]+$/)) {
$message = ''Invalid userid: $in{'userid'}. Must only contain only letters and be less then 12 and greater then 3 characters.'';
}
unless ($in{'email'} =~ /.+\@.+\..+/) {
$message = ''Invalid email address format: '$in{'email'}'.'';
}
open (PASSWD, ''<$auth_pw_file'') || &cgierr(''unable to open password file. Reason: $!\n'');
@passwds = ;
close PASSWD;
foreach $pass (@passwds) { # Go through each pass and see if we match..
next if ($pass =~ /^$/); # Skip blank lines.
next if ($pass =~ /^#/); # Skip Comment lines.
chomp ($pass);
($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $pass);
if (lc($in{'userid'}) eq lc($userid)) {
$message = ''userid already exists. Please try another.
'';
}
if (lc($in{'email'}) eq lc($email)) {
$message .= ''email address already exists.'';
}
}
if ($message) {
&html_signup_form ($message);
return;
}
$in{'pw'} = &generate_password;
$in{'email'} = lc($in{'email'});
# Add the userid into the file with signup permissions.
open (PASS, ''>>$auth_pw_file'') or &cgierr (''unable to open: $auth_pw_file.\nReason: $!'');
if ($db_use_flock) {
flock(PASS, 2) or &cgierr(''unable to get exclusive lock on $auth_pw_file.\nReason: $!'');
}
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'pw'}, $salt);
my $permissions = join ('':'', @auth_signup_permissions);
print PASS ''$in{'userid'}:$encrypted:$permissions:$in{'email'}\n'';
close PASS;
But the only thing I need out of this is the part that opens the pass file to get the password to include in the email. I have no idea what half of this stuff means. I assume that it starts with the OPEN PASS line, but i'm not sure what after that because it looks like alot of checking going on in there also. I am in need of this code to email the user after they fill out the signup form AND add their user record via the users.db add form where they supply their email address.
Can someone tell me what needs to come out this bit of code to do what I need? BTW, this code to print the email is in my add_success sub and not the signup_success. Thanks!