Gossamer Forum
Home : Products : DBMan : Customization :

Add record without login

Quote Reply
Add record without login
I'm trying to allow a default user to add a record to a database.

Everything seems fine -- calling with /db.cgi?db=db&uid=default gets to the main menu & it links thru to the add page just fine. But when I submit the form, I get the login screen appearing. The .cfg file is set for default user and no authentication.

Have I missed something? Is it OK to allow a default user to add a record?

I want to be sure each user can modify only their own record. Can I avoid the sign up process, allowing a user to modify but still be sure that they get access to only their own record?

If this isn't possible, they'll have to login to modify. Presumably, with no login need for adding a record, their user details are not added to the authorised users file. Can I include a "hidden" sign up facility as part of the add form section -- to be sure that the User ID asked for in the add form is unique in my authorised users file? Or can I just use the e-mail address as the User ID so that it will be unique when they come to sign up prior to modifying?

Thanks!

------------------
WYSIWYG

Regn # 1718-00-DB

[This message has been edited by WYSIWYG (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
I really don't think this is possible. It is not a problem for default users to add records. In order to modify records, users would have to be assigned to the records, thus...they have to login to add and modify their records with a unique ID (like userid).

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Add record without login In reply to
Thanks, Eliot.

OK, so let's get them to sign up before they add. Now, at the outset, I'm trying to get visitors to become registered users. So, to encourage them, I want one clean step to add a record -- instead of sign up, receive password by e-mail, login and then add. Can I get them to sign up (so their User ID & e-mail address get added to my authorised users file) and then get them straight through to add a record -- with no log in. Perhaps this would involve them adding a record as a "default" user, but with the User ID and e-mail address being pulled across from the sign up form and included as fixed elements of the add form?

Do you think this would work? And do you see how I could achieve the "short-cut" from the sign up form to the add record form?

As ever, I appreciate your guidance.

[This message has been edited by WYSIWYG (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
 
Quote:
Can I get them to sign up (so their User ID & e-mail address get added to my authorised users file) and then get them straight through to add a record -- with no log in.

I really don't see a method of doing this. How do you think users will get their password to access your database?? The password is mailed to them, right? (Through the Secure Password Lookup Mod.) You would also have to change the session login process that attachs the UNIX time to the uid argument.

So, it would be a lot more work than its worth to do this...

Sorry...

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Add record without login In reply to
Surely if I get the user to sign up, we determine a valid User ID & email address. Then, we can let the user add a record (forcing them to use the same User ID and email) without bothering to send the password to them or troubling them to login. After all, they can ask for the UserID & password to be emialed to them when needed for odifying their record.

I've now managed to sort out the code for jumpong the user from signup to add_form (in place of html_signup_success). I've brought in the email and userid with $in (and displaying the values and using hidden input). But again, when I try to submit the add form, it forces me thru to the login screen. Eek!

Any ideas how to get the record added?

[This message has been edited by WYSIWYG (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
 
Quote:
You would also have to change the session login process that attachs the UNIX time to the uid argument.

This is the problem that needs to be addressed to attach the session to the uid argument.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Add record without login In reply to
Ah! I understand the problem of trying to continue the same session.

Instead of this, can we start up a new session, with the user set to "default" but still grabbing the userid/email values just entered by using $in?
Quote Reply
Re: Add record without login In reply to
 
Quote:
user set to "default"

No...Again, you cannot associate the default user with the uid of the record being added. I would recommend staying away from the "default" user since you do want people to be able to modify their records, right?

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


[This message has been edited by AnthroRules (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
I've got you. Sorry to take a while to pick up on this fully.

Given this, what I'd like to do is take the user through the subsequent login, but in a "hidden" fashion. Instead of troubling her/him to enter the userid/password, can I bring these into html_signup_success with $in and use hidden input? I've tried and am getting pushed through to the login screen. Could you please look over the code extract I'm using in html_signup_success:

E-mail: $in{'email'}
<input type="hidden" name="email" value=$in{'email'}>
UserID: $in{'userid'}
<input type="hidden" name="userid" value=$in{'userid'}>
<input type="hidden" name="pw" value=$in{'pw'}>

Thanks!

[This message has been edited by WYSIWYG (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
Again...the problem is that if you are using the Secure Password Mod, the password is NOT passed through the sign_up form...It is sent to the user. So, the codes are using won't work.

See you still have the following codes:

Code:
<input type="hidden" name="pw" value=$in{'pw'}>

You are still using the password field. And again, to by-pass what you want, you would have to dramatically edit the login process and codes in the auth.pl file since the login process needs a uid and password. And if you are using the Secure Password Lookup Mod, the password is NOT passed through the signup_form as I mentioned above.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Add record without login In reply to
So can I go back to the basic db.cgi without secure password lookup for this purpose?
Quote Reply
Re: Add record without login In reply to
It would be possible to adapt sub add_record in db.cgi to include the signup procedure. (Possible, but not real easy, as I think about it right now.)

The add form would have to include fields for the userid, email and password, as well as the other fields you want in your database. You could use some of the secure password lookup mod -- just not the signup procedure.



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






Quote Reply
Re: Add record without login In reply to
I think I have this worked out. It's really just a matter of doing things in different order.

Set up the authorization in your .cfg file as follows:

$db_key = 'the name of your userid field';
$db_key_track = 0;
$auth_no_authentication = 0;
$auth_allow_default = 1;
@auth_default_permissions = (1,1,0,0,0);
$auth_signup = 0;
@auth_signup_permissions = (1,0,1,1,0);
$auth_modify_own = 1;
$auth_user_field = the number of your userid field;

Be sure to have a field for the user's email address. Set the "valid expr" portion of the field definition to

'.+\@.+\..+'

Add the following line to your .cfg file:

$db_email_field = 'name of your email address field';

Make sure you have a field on your "add" form named pw for the entry of a password.

You will probably want to have one form for adding and another one for searching and modifying, with the latter one not having the password field.

[After I posted this, I realized that I had more in here than was necessary.]

Replace sub validate_record with the following:

Code:
sub validate_record {
# --------------------------------------------------------
# Verifies that the information passed through the form and stored
# in %in matches a valid record. It checks first to see that if
# we are adding, that a duplicate ID key does not exist. It then
# checks to see that fields specified as not null are indeed not null,
# finally it checks against the reg expression given in the database
# definition.

my ($col, @input_err, $errstr, $err, $line, @lines, @data);
my ($userid, $pw, $view, $add, $del, $mod, $admin, $email);


if ($in{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
push(@input_err, "userid already in use -- try another");
}
}
close DB;
unless ((length($in{$db_key}) >= 3) and (length($in{$db_key}) <= 12) and ($in{$db_key} =~ /^[a-zA-Z0-9]+$/)) {
push(@input_err, "Invalid userid: $in{'userid'}. Must only contain only letters and be less then 12 and greater then 3 characters.");
}
unless ((length($in{'pw'}) >= 3) and (length($in{'pw'}) <= 12)) {
push(@input_err, "Invalid pw: '$in{'pw'}'. Must be less then 12 and greater then 3 characters.");
}
open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>;
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{$db_email_field}) eq lc($email)) {
push(@input_err, "email address already exists.");
}
}
}
foreach $col (@db_cols) {
if ($in{$col} =~ /^\s*$/) { # entry is null or only whitespace
($db_not_null{$col}) and # entry is not allowed to be null.
push(@input_err, "$col (Can not be left blank)"); # so let's add it as an error
}
else { # else entry is not null.
($db_valid_types{$col} && !($in{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
(length($in{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($in{$col});
}
}
}

if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "<li>$err"; # and return it.
}
return "<ul>$errstr</ul>";
}
else {
if ($in{'add_record'}) {
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{$db_cols[$auth_user_field]}:$encrypted:$permissions:$in{$db_email_field}\n";
close PASS;
}
return "ok"; # no errors, return ok.
}
}


Note that you will not be able to use this db.cgi file or any other databases that you might want to add to your site.


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








[This message has been edited by JPDeni (edited April 15, 2000).]
Quote Reply
Re: Add record without login In reply to
Tx, Carol.

Eliot's challenging approach led me to get this working crudely (switching to a db.cgi without the secure password lookup mod) at 2am this morning local time!

I really appreciate your more sophisticated response which I'll build in.
Quote Reply
Re: Add record without login In reply to
It's looking good. The code allows a default user in to the add form. On submitting the form, we get the add_fail page with "email address already exists" repeated about 60 times. It bugs me that I can't see what tweak I need to make. But I'm well chuffed to be this far down the track.

If it helps, the debug shows the following:

Email : correctly stated and, yes, not one that's been registered previously
User ID : default
Session ID : default
pw : temp
uid : default
Quote Reply
Re: Add record without login In reply to
For the time being, just to check out the rest of it, why don't you comment out

Code:
if (lc($in{$db_email_field}) eq lc($email)) {
push(@input_err, "email address already exists.");
}

(Make sure you comment out all three lines or you'll get a syntax error.)

Then you can at least test the rest of it.

Are you sure that all of your entries in the .pass file have an email address?



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






Quote Reply
Re: Add record without login In reply to
I've tried a few approaches -- most centering around the PRINT PASS line of sub validate_record. Am I in the right area? Having tried all the variants I can think of, does anyone have any better ideas?!

Thanks,
Quote Reply
Re: Add record without login In reply to
Quote:
Are you sure that all of your entries in the .pass file have an email address?

Thanks, nail hit squarely on head. A couple of entries were created before I added the email mod.

My desired "default add with no login" now works. Except that the new user in the .pass file (as viewed using Admin's User Management screen) is given a userid of "default" and no email address is stored. I'll try to see how to achieve this -- but some guidance would be appreciated.

Thanks ever so much.

[This message has been edited by WYSIWYG (edited April 17, 2000).]
Quote Reply
Re: Add record without login In reply to
I think the problem is the following line in sub add_record

Code:
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

Comment out that line, and you should be okay.


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






Quote Reply
Re: Add record without login In reply to
Thanks -- it all works a treat now, with one tweak made, as follows, to capture e-mail address in the .pass file:

In Print PASS:
$in{$db_email_field}
amended to:
$in{$db_cols[$auth_email_field]}

I really appreciate all your help.


[This message has been edited by WYSIWYG (edited April 18, 2000).]
Quote Reply
Re: Add record without login In reply to
It occurred to me that, even after adding the record, the user will still have to log in.

I'm not sure if this will work, but you may be able to automatically log the user in after the record is added.

In sub add_record, after

&auth_logging("added record: $in{$db_key}") if ($auth_logging);

add

Code:
$in{'login'} = 1;
$db_uid = "";
$in{'userid'} = $in{$db_cols[$auth_user_field]};

($status, $uid, $per_view, $per_add, $per_del, $per_mod, $per_admin) = &auth_check_password;

if ($status eq "ok") {
$db_script_link_url = "$db_script_url?db=$db_setup&uid=$db_uid";
($db_userid) = $db_uid =~ /([A-Za-z0-9]+)\.\d+/;
}

Like I say, I'm not sure if this will work or not, but it might. Smile

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






Quote Reply
Re: Add record without login In reply to
Thanks, Carol.

In this case, I've allowed the default user to have add and modify own permissions. It's for registering as a user, with just 1 record per user. In the process of registering, the user completes one screen (add) and then another (modify, with the form based on what's input in add). Then (s)he is sent back to the home page.

So, on this occasion, no need to have a hidden login -- but probably very useful for the future!

Thanks.
Quote Reply
Re: Add record without login In reply to
On reflection, I'll be adding this once I'm back from vacation -- it'll be great to allow newly-registered users access to my other DBMan databases.