Gossamer Forum
Home : Products : Links 2.0 : Customization :

Password Modify for Templates

Quote Reply
Password Modify for Templates
This cry for help is in relation to Password Modify for Templates @ http://www.asan.com/users/phoenix/modify/

I have installed the script as stated at the page but nothing ever works. I have tried many differnet ways.

This is the modify page i have:

<FORM ACTION="<Û_cgi_url%>/modify.cgi" METHOD="POST">
<P>Title:
<BR><INPUT NAME="Title" VALUE="<%Title%>" SIZE="47">
<BR>URL:
<BR><INPUT NAME="URL" VALUE="<%URL%>" SIZE="47">
<BR>Category:
<BR>
<Êtegory%>
<BR>Description:
<BR><TEXTAREA WRAP="virtual" NAME="Description" ROWS="3" COLS="42"><Þscription%></TEXTAREA>
<BR>Contact Name:
<BR><INPUT NAME="Contact Name" VALUE="<%Contact Name%>" SIZE="47">
<BR>Contact Email
<BR><INPUT NAME="Contact Email" VALUE="<%Contact Email%>" SIZE="47">
<BR>Password:
<BR><INPUT NAME="Password" VALUE="<%Password%>" SIZE="47">
<BR><INPUT TYPE="Hidden" NAME="ID" VALUE="<%ID%>">
<B><input type="SUBMIT" Name="Submit" value="Modify Resource"></B>
</P>
</FORM>

This is my modify.cgi script

sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

# We are processing the form.
if ($in{'Submit'}) {
&process_form;
}
# Otherwise we are displaying the form (in site_html.pl), displaying
# the entrance (Asks for Link ID and Password)
else {
if ($in{'ID'} =~ /^\d+$/) {
my (%rec) = &get_record ($in{'ID'});

if ($rec{$db_key} eq $in{'ID'}) {
if ($rec{'Password'} eq $in{'password'}) {
&site_html_modify_form (%rec);
}
else {
&site_html_modify_failure ("Password Invalid: $in{'password'}");
}
}
else {
&site_html_modify_failure ("Unkown Link ID: $in{'ID'}");
}
}
else {
&site_html_modify_first;
}
}
}


sub process_form {
# --------------------------------------------------------
my ($key, $status, @values, $found);
local (%original);

# Make sure we have a link to modify.
#!$in{'Current URL'} and &site_html_modify_failure ("did not specify link to modify") and return;

# Let's check to make sure the link we want to update is actually
# in the database.
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name. Reason: $!");
$found = 0;
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[$db_key] eq $in{'ID'}) {
$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
!$found and &site_html_modify_failure ("link was not found in the database") and return;

# Since we have a valid link, let's make sure the system fields are set to their
# proper values. We will simply copy over the original field values. This is to stop
# people from trying to modify system fields like number of hits, etc.
foreach $key (keys ­d_system_fields) {
$in{$key} = $original{$key};
}

# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;

# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {
# First make sure the link isn't already in there.
open (MOD, "<$db_modified_name") or &cgierr ("error opening modified database: $db_modified_name. Reason: $!");
while (<MOD>) {
chomp;
@values = split /\|/;
if ($values[0] eq $in{$db_key}) {
close MOD;
&site_html_modify_failure("A request to modify this record has already been received. Please try again later.");
return;
}
}
close MOD;

# Print out the modified record to a "modified database" where it is stored until
# the admin decides to add it into the real database.
open (MOD, ">>$db_modified_name") or &cgierr("error in modify.cgi. unable to open modification database: $db_modified_name. Reason: $!");
flock(MOD, $LOCK_EX) unless (!$db_use_flock);
print MOD &join_encode(%in);
close MOD; # automatically removes file lock

# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_modify_success;
}
else {
# Let's change that error message from a comma delimted list to an html
# bulleted list.
&site_html_modify_failure($status);
}
}

sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated.

# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");
my $to = $db_admin_email;
my $from = $in{$db_cols[$db_contact_email]};
my $subject = "Modification to Database: $in{'Title'}";
my $msg = qq|
The following link was modified and is awaiting validation:

ORIGINAL LINK:
===============================================
Title: $original{'Title'}
URL: $original{'URL'}
Description: $original{'Description'}
Country: $original{'Country'}
Type: $original{'Type'}
Contact Name: $original{'Contact Name'}
Contact Email: $original{'Contact Email'}
Category: $original{'Category'}

NEW LINK:
===============================================
Title: $in{'Title'}
URL: $in{'URL'}
Description: $in{'Description'}
Country: $in{'Country'}
Type: $in{'Type'}
Contact Name: $in{'Contact Name'}
Contact Email: $in{'Contact Email'}
Category: $in{'Category'}

Remote Host: $ENV{'REMOTE_HOST'}
Referer: $ENV{'HTTP_REFERER'}

To update, please go to:
$db_script_url

Sincerely,

Links Manager.
|;

# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or return undef;
$mailer->send or return undef;
}



This is the updated site_html_template.cgi

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.

my %rec = @_;
my $category = &build_select_field ("Category", "$rec{'Category'}");

&html_print_headers;
print &load_template ('modify.html', {
category => $category,
%rec,
%globals
});
}




sub site_html_modify_first {
#---------------------------------------------------------
# displays the form for users to enter the ID number and
# Password for the Link they wish to modify

&html_print_headers;
print &load_template ('modify_first.html', {
%globals
});
}


And i have added the password var to the links.def file.
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
Password => [14, 'alpha', 10, 10, 1, '', '']
);

# Database file to use -- defined in links.cfg.
$db_file_name = $db_links_name;
# Counter file to use -- defined in links.cfg.
$db_id_file_name = $db_links_id_file_name;
# The column name for the database key.
$db_key = 'ID';
# Database delimeter.
$db_delim = '|';
# Title used in admin output.
$html_title = 'Links Database';
$html_object = 'Link';

# Field Number of some important fields. The number is from Û_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 8; $db_isnew = 9; $db_ispop = 10;
$db_contact_name = 6; $db_contact_email = 7; $db_title = 1;
$db_votes = 12; $db_rating = 11; $db_mail = 13;
$db_password = 14;


But i still get directed to the error page when i try to modify a site. Can anyone help.

Quote Reply
Re: Password Modify for Templates In reply to
Does the error page you get directed to contain an error message? If so, what is it? That might point us to where the problem is.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: Password Modify for Templates In reply to
This MOD is actually bug filled and I had to do some modification to it to fix a few things including the fact that the email was case dependent... I'll post the updates code with a URL sometime in the next few days... Sorry I can't put it straight on here but I've got a deadline and presentation to do in a couple of days that has priority...


Quote Reply
Re: Password Modify for Templates In reply to
Thanks for your help, i hope you meet you deadline. :0)

Quote Reply
Re: Password Modify for Templates In reply to
Do you use the MOD on your website.

Quote Reply
Re: Password Modify for Templates In reply to
Hi Andy,

yeah I use the MOD on a site I've been working on for a charity group.

The site is at http://www.citizenz.org/

It's in a period of transfer at the moment because I originally used the MOD that required ID, email and URL to modify things... It's frustrating for people who are non techies so I changed it to the Password 1.0 version..

Like I said though, I'll sort out the updated MOD for you soon and post it to Links 2 MOD list...

Best of luck
:)

Quote Reply
Re: Password Modify for Templates In reply to
I would recommend contacting the original Mod Author and also crediting the original Mod Author....

Wink

Regards,

Eliot Lee
Quote Reply
Re: Password Modify for Templates In reply to
Okay I took the corrections you suggested but when it gets to the modify.html page it doesn't pass on the rec fields. They are all blank! What do you need to see? Is it this?

Code:
# the entrance (Asks for Link ID and Password)
else {
if ($in{'ID'} =~ /^\d+$/) {
my (%rec) = &get_record ($in{'ID'});

if ($rec{$db_key} eq $in{'ID'}) {
if ($rec{'Password'} eq $in{'password'}) {
&site_html_modify_form (%rec);
}
else {
&site_html_modify_failure ("Password Invalid: $in{'password'}");
}
}
else {
&site_html_modify_failure ("Unkown Link ID: $in{'ID'}");
}
}
else {
&site_html_modify_first;
}
}
}
Quote Reply
Re: Password Modify for Templates In reply to
I've been working with this script the past three days making heavy modifications allowing you to login with a username and password and change your information without it being validated (I'll post the results when I finish.), but there is something I noticed at the top... you put site_html_templates.cgi when in fact it is site_html_templates.pl...

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Ok, not sure if this is the definitive answer but I noticed that in the code (top) that you've got this sort of problem:

($rec{'Password'} eq $in{'password'})

Note: the capitalised 'P' in the $rec variable and the lowercase 'p' in the $in variable. You can't do that!

Check what how you have Password/password in your links.def file and then make sure that you reference it in the same way throughout... so if your links.def file has the line:

Password => [27, 'alpha', 10, 10, 1, '', '']

then you need to make sure that any calls are the same.. ie:

<%Password%>
$rec{'Password'}
$in{'Password'}


Note that Password is the same throughout.. capitalised as per the links.def.

That will probably solve part of the problem...

Oh and as for that updated Password MOD. it's available at:

http://www.websnail.org/scripts/password.html

I hope that helps solve your problem somewhat...
Smile
Martin


The impossible we can handle now
Miracles take a little longer
Quote Reply
Re: Password Modify for Templates In reply to
I thought that too, but it really doesn't matther how you call whats comming in ie: $in{'password'} its what that represents... So in{'password'} should work the same as in{'Password'}.... I reccomend you capitalize both of them also to avoid confusion...

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Uhm.. I'd disagree with your evaluation.. you MUST have the same capitalisation or it will treat your field as a different one.

so in{'Password'} does not equal rec{'password'} or in{'password'}. etc....

Like you noted (as did I in my post), you need to be consistent with how you label it.

Regards,

Martin



The impossible we can handle now
Miracles take a little longer
Quote Reply
Re: Password Modify for Templates In reply to
Here is an even simple version of password.cgi using templates...

http://www.magicdirectory.com/links-mods/password.txt

The only thing it requires is these routines in site_html_templates.pl:
Code:
sub site_html_password_failure {
# --------------------------------------------------------
# This routine determines how the forgot your password error
# page will look like.

my ($errormsg) = shift;

&html_print_headers;
print &load_template ('password_failure.html', {
error => $errormsg,
%globals
});

}

sub site_html_password_success {
# --------------------------------------------------------
# This routine determines how the forgot your password
# success page will look like.

&html_print_headers;

print &load_template ('password_success.html', {
%in,
%globals
});
}
and I suggest that you edit your new templates password_failure.html and password_success.html based on email_error.html and add_success.html.

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
All I was saying is that if you have a field in your template called password and you read-it as $in{'password'}, it would be the same thing as if you had a field Password and you read-it as $in{'Password'}.

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Hmm...

Ok, without wishing to get into a flame war.. I should note that my original post was not specifying that you should only use "Password" but in fact that whatever you used, it should be used consistently... be it "PASSword", "PaSswOrD" or whatever...

So, can I respectfully suggest that you read a post before you offer comment on it. Then we don't confuse the issue.

Cheers
Smile
Martin

The impossible we can handle now
Miracles take a little longer
Quote Reply
Re: Password Modify for Templates In reply to
Ok, at the risk of sounding peevish couple of things:

1. Why reinvent the wheel?
A MOD (Password 1.0) already exists that only required some tweaking before it was bug fixed and workable

2. Your MODs use of only the email field means that someone with multiple records will end up receiving EVERY record password they own instead of just the one they want.

3. The password.txt copyright/title headers still read as the old Modify.cgi info so they're misleading and potentially confuse/mislead people who are new to Links 2.0 / Perl

4. Matching email
On your script this does the same thing as the Password 1.0 MOD which is that it doesn't allow for differences in the email (uppercase/lowercase) between the input email and the email on record.

Ok, that said it's a simple script and I can appreciate why you've attempted to simplify it.

However, I created a bug fixed version which deals with all the issues above and takes into account the work of the original author.

What I figure has happened is that you missed the other postings on the topic of "Password" and went off to write your own. Easily done I know, but I'd recommend you take a peek at the original and updated versions and see what's already been done.

The original MOD and the updated one are at:

http://hostglobal.com/scripts/password.shtml

http://www.websnail.org/scripts/password.html

I'll be posting the MOD update to the MODs list for Links 2.0 now so people don't have to rely on the forum to find it..

Criticism is not intended to be anything other than constructive so please don't take it personally.

Regards,

Martin

The impossible we can handle now
Miracles take a little longer
Quote Reply
Re: Password Modify for Templates In reply to
Ok, first nothing anyone can say in this forum can really make me made, If it does I ignore it.

Second... keeping in mind this isn't a watermelon fest... I was replying to your original post you said:

Note: the capitalised 'P' in the $rec variable and the lowercase 'p' in the $in variable. You can't do that!

But it doesn't matther anyway, I just don't want to look like an idiot... Wink we both agree it needs to be consistent keep it there...

But now for your real questions...

1.Why reinvent the wheel?

I'm not trying to reinvent the wheel I was just offering a template version that I made for my own purposes...

2. Your MODs use of only the email field means that someone with multiple records will end up receiving EVERY record password they own instead of just the one they want.

Maybe I'm not familiar with your mod, but if you do have more than one record why wouldn't you want all of them emailed to you? Also how do you know which one the user wants when the only information they give is their email address?

3. The password.txt copyright/title headers still read as the old Modify.cgi info so they're misleading and potentially confuse/mislead people who are new to Links 2.0 / Perl

I can change that in 5 seconds... If you want me to copy your header I will be happy to...

4. Matching email
On your script this does the same thing as the Password 1.0 MOD which is that it doesn't allow for differences in the email (uppercase/lowercase) between the input email and the email on record.


I did use the original password 1.0. Where do u see anything concerning the case of the email? The email in $in{'email'} never changes case... at least not that I know of...

Ok, that said it's a simple script and I can appreciate why you've attempted to simplify it.

attempted lol Laugh just trying to help

I will be more than happy to modify your script so that you can use templates and to also using the built in send mail function with links... I created it because its easier for me... I need to update my site with it anyway so I going to start as soon as I finish this...

Thanks for the comments and help,

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Heya,

Ok, glad we're not getting into WW3 Smile

Just to clarify one point... The case thing re: email was that the script used to only match:

"myemail@here.com"
to
"myemail@here.com"
NOT
"MYemail@here.com"

even though they are the same.. I just did some pattern translation to reduce the record and input 'email' to lowercase before attempting a match...

Hope that helps

Martin


The impossible we can handle now
Miracles take a little longer
Quote Reply
Re: Password Modify for Templates In reply to
Thanks, uhh, I found out what you were talking about when I looked in the script...

Ok, what do you think now?
http://www.magicdirectory.com/links-mods/password.txt

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
We're talking about modify password for templates not emailing lost passwords. hehe Smile I still can't get it to display the contents of that ID so the user doesn't get a blank form. I want the old info to be displayed there and let them edit that info.

Quote Reply
Re: Password Modify for Templates In reply to
umm, this is the message sent to them u can simply edit that:


my $msg = qq|----------------------------------------------------
Resource ID: $data[0]
URL: $data[$db_url]
Password: $data[$db_password]

----------------------------------------------------
Remote Host: $ENV{'REMOTE_HOST'}
Remote Address: $ENV{'REMOTE_ADDR'}
Referer: $ENV{'HTTP_REFERER'}
|;


- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
I'm sorry, but I don't think I understand what you are talking about...

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Okay what file am I editing to put that in there?

Quote Reply
Re: Password Modify for Templates In reply to
password.cgi same file...

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Password Modify for Templates In reply to
Hi Drophit...

Ok, If I'm reading this right the problem you're having is in getting the information from the record you want to modify to appear in the modify.html form AFTER you've confirmed your ID and password... Correct?

If so then all you need to do really is make sure that the %rec field is being passed on in the relevant subroutine in html_templates.pl (or whatever that files called Smile )

Then put all the <%mytag%> tags into the relevant value="" sections....

The only difference is that the description (or any other <textarea>tags will require you to put the <%description%> tag in between the area opening and closing tags...

If you need more info on that one let me know... I'll be writing a FAQ / MOD for this update sometime after the exams so people can get it direct... (don't hold your breath).

Regards,

Martin

The impossible we can handle now
Miracles take a little longer