Gossamer Forum
Home : Products : DBMan : Customization :

limit each user can only reg. 1 data only

Quote Reply
limit each user can only reg. 1 data only
How to limit each user can only reg. 1 data only. And also how to limit the UserID as number only. Thank you
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Do you mean, how can you prevent users from adding more than one record each?

Include a field for the userid in the %db_def section of default.cfg.
Set $db_key = 'the name of the userid field';
Set $db_key_track = 0;
Set $auth_user_field = the number of the userid field;

To only allow numbers as the userid, in db.cgi, sub signup, change

Code:
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.";
}

to

Code:
unless ((length($in{'userid'}) >= 3) and (length($in{'userid'}) <= 12) and ($in{'userid'} =~ /^[0-9]+$/)) {
$message = "Invalid userid: $in{'userid'}. Must only contain only numbers and be less then 12 and greater then 3 characters.";
}


------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
I wish to keep the ID. Any other method?
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Not that I know of.

Why do you wish to keep the ID?


------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Oh... that's not important.
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Carol,

This is exactly the question that I would like to ask... But I've got another side to it...

1. User names are kinda hard to remember when they're numbers instead of words or names.

2. The Add button is still on the menu... and a Duplicate Key Error doesn't explain very much.

A really simple solution for me would be that after a person entered a record, that the ability to press the add button would disappear. I thought about adding a hidden field into the database that I could read when checking for permissions in the html_footer but I'm not sure if that would work or not... In my instance, a user can only add a record after they've registered.

Do you have any ideas? This is actually a side project of my own for an Alumni section. It doesn't quite make sense for a user to submit more than one entry for themselves...

Thanks Carol!
-Dave
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
You might try looking at the thread at http://www.gossamer-threads.com/...m12/HTML/001128.html .

This mod will check to see if the user has a record in the database. If not, the user is taken directly to the add form. If you use this, you can just take the "add" link out of sub html_footer, or make it an admin link.


------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Carol,

Thanks for looking this over. However, everyone is still being sent to add a record - even if a record for the registered user is already in the database and for default users as well. (Default users don't have permission to add records to the database. Adding an item gets an error message if you're a default user).

This is what I added to the html_home

Code:
%rec = &get_record($db_userid);
unless ($rec{'UserID'}) {&html_add_form; return;}

In my case, I don't even need the script to automatically send them to the add record script. Just a check to see if a record exists that they submitted (UserID).

Is there a way to scan the database each time to see if they have a record attached to their UserID, and if so - not show the Add Record link? Default users can only view from a prebuilt form (built from the database on each screen).

Thanks again for all of your help.

Dave
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
The line

Code:
%rec = &get_record($db_userid);

should pick up whether a user has a record or not.

Code:
if ($rec{$db_key}) {
}

should be the code you need to decide whether the user has a record or not, if your userid field is your $db_key.

The trouble is that the footer prints out on every page, so that you would have to do the search every time the user did anything in the script. That's why it's better (IMHO) to force the user to add when they first sign up and then not give them the add option in the footer at all.


------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Hmmm... I wished that this would work easier for me... But my userid field is not my $db_key. And the example show at the top of this thread doesn't take into account a default user that doesn't have rights to add a record.

I saw an earlier post somewhere that allowed each user 5 records... how did that work?

In anycase - you're correct in saying that forcing somebody to add a record and removing the Add record link would be another, less script intensive way to go... But it didn't work either in that it sent everybody to the add a record each time they logged in. Of course, how is somebody to edit their information without logging in... Which of course sends them to add another record.

Am I thinking about this wrong?

If you want a place to visit, ths-alumni.musicshoppe.com/alumni.cgi or for a default user ths-alumni.musicshoppe.com/alumni.cgi?uid=default

(Date stamp on the database doesn't work either... But that's for another post)

Thanks Carol for all of your help.

-Dave


[This message has been edited by shoppe (edited October 03, 1999).]
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
If you only want one record per user, you really should make the $db_key field the same as the userid field. I can't think of any reason not to and a whole lot of reasons why you should.

As for a default user, that's easy to take care of.

Code:
if ($per_add) {
%rec = &get_record($db_userid);
unless ($rec{$db_key}) {
&html_add_form;
return;
}
}

Quote:
I saw an earlier post somewhere that allowed each user 5 records... how did that work?

If you can find it again, let me know. I don't know where that post is. I recall that it was a pain to do, though. This is so much simpler, especially if you're going to use one record per user.

Quote:
But it didn't work either in that it sent everybody to the add a record each time they logged in. Of course, how is somebody to edit their information without logging in... Which of course sends them to add another record.

This is because your userid field is not your key field. Change it and it will work the way it's supposed to.



------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
Carol,

You're right... This quick setup works for what I need to happen. In my quick reading, I didn't notice that part of the first question was that chyung needed the UserID to be a number... It can also be letters as in my case.

Now if I can only get your modified date working correctly...

Thanks!
Dave
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
What problem are you having with the date?


------------------
JPD





Quote Reply
Re: limit each user can only reg. 1 data only In reply to
I'm using:

Code:
$last_modified = time() - (-M "f:/alumni/ths.db") * 86400;
$date_and_time = &get_date($last_modified) . " " . &get_time($last_modified);
print $date_and_time;

And it returns the correct modified date, but the time is the current server time.
Quote Reply
Re: limit each user can only reg. 1 data only In reply to
That's because sub get_time is not set up to use input. (That is a terrible sentence, but I don't know how to make it better.)

Try replacing sub get_time with the following:

Code:
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#

my ($time2) = @_;
($time2) or ($time2 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time2);
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

That should work for you.


------------------
JPD