Gossamer Forum
Home : Products : DBMan : Customization :

Email Admin if Email is changed in "change Password mod"

Quote Reply
Email Admin if Email is changed in "change Password mod"
I successful installed the Secure Password mod, change password mod & the change email mod.

I have looked in both the FAQ and this forum, yet I have not found the answer to this.

After reading all the posts I was able to have a email sent to me (admin) when a user changes their password. But, what I cannot find is how to have an email sent to me if a user changes their email with the "change email mod."

Now, I did find many references to different types of things to this effect and I got this far from reading those posts:

In my html.pl file I added:

----------------------------------

$page_title = "Email address changed";
%rec = &get_record($in{$auth_pw_file});
$date = &get_date();
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");


print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Rathe Email Changed\n\n";
print MAIL "Date added: $date\n";
print MAIL "Userid: $in{'userid'}\n";
close MAIL;
&html_page_top;


------------------------

And in doing this, when the user changed their password I did get the email, but the email does not include their name or email address.

All I get in my email is this:



Sent: Monday, January 21, 2002 11:51 PM Subject: New Record Added


Date added: 01/21/2002
Userid:
----------------------------------------------------

That's really a problem 'cause I don't know who it is from or what their new email address is! Unimpressed

I realize I am missing a lot of code somewhere. I am not sure what code to use, or where to put it, to add the User ID's name & Email in the letter to me. Unsure

If someone could point me in the right direction I would appreciate the help.

Thanks.



Diana Rae
Quote Reply
Re: [dianarae] Email Admin if Email is changed in "change Password mod" In reply to
You would need to add the fields you want included in the email within a new print Mail line.

Something like this:

print MAIL "Name: $rec{'Name'}\n";
print MAIL "Email: $rec{'Email'}\n";

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Email Admin if Email is changed in "change Password mod" In reply to
Thank you for responding, Lois. I did as you suggested:

$page_title = "Email address changed";
%rec = &get_record($in{$auth_pw_file});
$date = &get_date();
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");

print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Rathe Email Changed\n\n";
print MAIL "Date added: $date\n";
print MAIL "Name: $rec{'Name'}\n";
print MAIL "Email: $rec{'Email'}\n";

close MAIL;
&html_page_top;

However, when I tested it this is what I got:

Subject: Email Changed

Date added: 01/21/2002
Name:
Email:


-------------

I'm guessing I am missing in the coding at the top to call the userid & email.

Any ideas? Thanks again for your help.



Diana Rae
Quote Reply
Re: [dianarae] Email Admin if Email is changed in "change Password mod" In reply to
Well, since you are drawing this information from the password file, you will only be able to retrieve what is actually within the password file.

What you are trying to do is get field info from both the password and database file.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Email Admin if Email is changed in "change Password mod" In reply to
Could you please help me as to how to add that code so I might get that info? I'm not exactly sure what to add to get that info or what to add.
Diana Rae
Quote Reply
Re: [dianarae] Email Admin if Email is changed in "change Password mod" In reply to
Hi Diana, make a back-up of your file then try changing the following line.

From:

%rec = &get_record($in{$auth_pw_file});


To:

%rec = $rec{$db_key};

Since you had been working from a mod that looked in the password file for data, your new mod is trying to look there (in password) for the data which is actually stored in the db itself (Name, Email, etc.). Hopefully, this change will work for you or get you somewhat closer to making the changes you're wanting.

~ Karen
Quote Reply
Re: [Karen] Email Admin if Email is changed in "change Password mod" In reply to
Quote:
From:

%rec = &get_record($in{$auth_pw_file});


To:

%rec = $rec{$db_key};


That should probably be:

my %rec = &get_record($rec{$db_key});

Last edited by:

RedRum: Jan 22, 2002, 12:37 PM
Quote Reply
Re: [RedRum] Email Admin if Email is changed in "change Password mod" In reply to
Neither worked. Frown I still get:

Subject: Members Password Changed

Date added: 01/22/2002
Name:
Email:


html.pl

##########################################################
## Email ##
##########################################################

sub html_change_email_form {
# --------------------------------------------------------
# This form is displayed when users want to change their password.
#
my $error = shift;

$page_title = "Change Email";
&html_page_top;

$submit_button = "Change Email";
$reset_button = "Reset";

# < -- Start page text -- >
print qq|
<br>
<br><$font>To change your email address, simply enter your new email address in the field below.<br>
<br>You then <b><i>must</i></b> log in again, using the <b>new password</b> you will receive at your new address.
<p>|;
# < -- End page text -->

if ($error) { print "<font color=red>$error</font></p>"; }

print qq|
<form action="$db_script_url" method="post" name="form1">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table border=0>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#003399"><b>Email address:</b></FONT></td>
<td><input type="TEXT" name="email" value=""></td></tr>
</table>
<center>
<input type="SUBMIT" name="change_email" value="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button"></center></form></p></font>|;

&html_footer;
&html_page_bottom;
}

sub html_change_email_success {
# --------------------------------------------------------

$page_title = "Email address changed";
my %rec = &get_record($rec{$db_key});
$date = &get_date();
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");

print MAIL "To: $admin_email\n";
print MAIL "From: Rathe Duchy Email Change\n";
print MAIL "Subject: Members Password Changed\n\n";
print MAIL "Date added: $date\n";
print MAIL "Name: $rec{'Name'}\n";
print MAIL "Email: $rec{'Email'}\n";
close MAIL;
&html_page_top;

$submit_button = "Logon";
$reset_button = "Cancel";

# < -- Start page text -- >
print qq|
<br><$font>Your email address has been changed!<br>
<br>You <b><i>must</i></b> log in again, using the <b>new password</b> you will received at your new address.<br>
You may change this password after you log in, but you <b>must</b> log in first using the password sent at the <b>new</b> email address.
<p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="post" name="form1">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table border=0>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#003399"><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid"></td></tr>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#003399"><b>New Password (from email sent):</b></FONT></td>
<td><input type="PASSWORD" name="pw"></td></tr>
</table>
<center>
<input type="SUBMIT" name="login" value="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button"></center></form></p></font>|;

&html_footer;
&html_page_bottom;
}

.cgi file---

sub change_email {
# --------------------------------------------------------
#### Following subroutine added for secure_password_lookup mod

my ($message, $userid, $pw, $view, $add, $del, $mod, $admin, $email, $password, $found, $output, $pass);

# Check to make sure email is ok
unless ($in{'email'} =~ /.+\@.+\..+/) {
$message = "Invalid email address format.";
}

open (PASSWD, "<$auth_pw_file") || &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
close PASSWD;

foreach $pass (@passwds) { # Go through each pass and see if we match..
chomp ($pass);
($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $pass);
if (($in{'email'} eq $email) && ($db_userid ne $userid)) {
$message = "Email address already exists.";
}
elsif (($in{'email'} eq $email) && ($db_userid eq $userid)) {
$message = "You entered the same email address which is already on file";
}
}
if ($message) {
&html_change_email_form($message);
return;
}

open (PASSWD, "<$auth_pw_file") || &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
close PASSWD;
$found = '';
PASS: foreach $pass (@passwds) { # Go through each pass and see if we match..
next PASS if ($pass =~ /^$/); # Skip blank lines.
chomp ($pass);
if ($pass =~ /^$db_userid:/) {
$found = $pass;
}
else {
$output .= $pass . "\n";
}
}
if (!$found) {
&html_change_email_form ("Your userid was not found in the password file.");
return;
}
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: $!");
}
print PASS $output;
close PASS;

($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $found);

$password = &generate_password;
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($password, $salt);

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: $!");
}
print PASS "$userid:$encrypted:$view:$add:$del:$mod:$admin:$in{'email'}\n";
close PASS;

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $in{'email'}\n";
print MAIL "From: dianarae\@bellsouth.net,dabard\@3g.quik.com\n";
print MAIL "Subject: $html_title New Password\n\n";

print MAIL "-" x 75 . "\n\n";

print MAIL "Here is your new $html_title password.\n\n";
print MAIL "Your $html_title User ID is: $userid\n";
print MAIL "Your $html_title password is: $password\n\n";

print MAIL "Please keep this email for future reference.\n\n";

print MAIL "To log on, go to\n\n";
print MAIL "http://www.newoutriders.org/eq/rathe\n";
print MAIL "and enter your User ID and the above password at the Members Area of the Rathe Duchy page.\n\n";

print MAIL "Please contact Bard or Raeana for $html_title support at: $admin_email\n";
print MAIL "if you have any questions.\n\n";

close (MAIL);
&html_change_email_success;
}

The email I am trying to get is the email is the email they put in when they sign up. These people only have "view" access. They do not enter anything into the database other then their user name and password to view.

Can you see what I am missing? Unsure
Diana Rae
Quote Reply
Re: [dianarae] Email Admin if Email is changed in "change Password mod" In reply to
Hi DianaRae, okay, it looks like the way you were trying to get the info was being thwarted by using the wrong field names.

Quote:


<input type=hidden name="uid" value="db_uid">
<table border=0>
<tr><td><Font face="Verdana, Arial, Helvetica" Size=2 Color="#003399"><b>Email address:</b></FONT></td>
<td><input type="TEXT" name="email" value=""></td></tr>

Quote Reply
Email to admin (when user changes email in change email mod) In reply to
Nothing I tried would work. I changed the names & still the email userid (uid) and email (email addy) were blank.

So, I tried something different. Since the "sub signup" in the .cgi file already has a little mail mod to notify the admin that the user has signed up - I tried to use that in the email one...

I actually got it to print the email in the admin letter. But, it still will not print the user ID. I cannot figure out why it wont.

The userid and the email address are both is in the letter to the User, but when I add the same little sub at the bottom calling the very same information...it DOES give the email now, but the UserID still is blank.

Here is the sub sign-up in the .cgi (which DOES work):

$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;

###mail to user

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $in{'email'}\n";
print MAIL "From: dianarae\@bellsouth.net,dianaraes\@hotmail.com\n";
print MAIL "Subject: $html_title Account Created\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "Your account at $html_title has been created.\n\n";
print MAIL "Your $html_title User ID is: $in{'userid'}\n";
print MAIL "Your $html_title password is: $in{'pw'}\n\n";
print MAIL "Please keep this email for future reference.\n\n";
print MAIL "To log on, go to\n\n";
print MAIL "http://www.newoutriders.org/eq/rathe\n";
print MAIL "and enter your User ID and the above password at the Members Area of the Rathe Duchy page.\n\n";
print MAIL "Please contact Bard or Raeana for $html_title support at: $admin_email\n";
print MAIL "if you have any questions.\n\n";
close (MAIL);
&html_signup_success;

###mail to admin

open (MAIL, "$mailprog") or &cgierr("Can't open sendmail: $!");
print MAIL "To: dianaraes\@hotmail.com,dianarae\@bellsouth.net\n";
print MAIL "From: RatheDuchyMembersSignUp\n";
print MAIL "Subject: New user signup!\n\n";
print MAIL "A new user signed up on ", scalar localtime(), ".\n";
print MAIL "Userid: $in{'userid'}\n";
print MAIL "Pass: $in{'pw'}\n";
close (MAIL);
}


And here is the sub change email in the .cgi (which only shows the email not the userid):

$password = &generate_password;
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($password, $salt);

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: $!");
}
print PASS "$in{'userid'}:$encrypted:$view:$add:$del:$mod:$admin:$in{'email'}\n";
close PASS;

###mail to user

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $in{'email'}\n";
print MAIL "From: dianarae\@bellsouth.net,dianaraes\@hotmail.com\n";
print MAIL "Subject: $html_title Email Changed\n\n";

print MAIL "-" x 75 . "\n\n";

print MAIL "Your Email has been changed.\n\n";

print MAIL "Here is your new $html_title password.\n\n";
print MAIL "Your $html_title User ID is: $userid\n";
print MAIL "Your $html_title password is: $password\n\n";

print MAIL "Please keep this email for future reference.\n\n";

print MAIL "To log on, go to\n\n";
print MAIL "http://www.newoutriders.org/eq/rathe\n";
print MAIL "and enter your User ID and the above password at the Members Area of the Rathe Duchy page.\n\n";

print MAIL "Please contact Bard or Raeana for $html_title support at: $admin_email\n";
print MAIL "if you have any questions.\n\n";

close (MAIL);


### mail to admin


open (MAIL, "$mailprog") or &cgierr("Can't open sendmail: $!");
print MAIL "To: dianaraes\@hotmail.com,dianarae\@bellsouth.net\n";
print MAIL "From: RatheDuchyEmailChange\n";
print MAIL "Subject: User has changed their email\n\n";
print MAIL "User changed their email on ", scalar localtime(), ".\n";
print MAIL "Userid: $in{'userid'}\n";
print MAIL "Email: $in{'email'}\n";
close (MAIL);
&html_change_email_success;
}

-----------

The mails in the 'sub sign up' to both the user & admin work properly. But, in the 'sub change email' only the email name shows in the body. I cannot seem to get the Userid to show.

Can anyone see what I am missing? It has to be something...I'm going braindead after trying to fix this for 3 days. Tongue
Diana Rae
Quote Reply
Re: [dianarae] Email to admin (when user changes email in change email mod) In reply to
Well, I did find one error I made. It should be:

print PASS "$userid:$encrypted:$permissions:$in{'email'}\n";
close PASS;


Instead of:

print PASS "$in{'userid'}:$encrypted:$permissions:$in{'email'}\n";
close PASS;



But, alas..I still only get the email address printed in the mail to the admin.

I'm missing something & I can't figure it out. Unsure



Diana Rae