Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

user utilities

Quote Reply
user utilities
i'm currently making some user utilities.. so that users can modify their profiles and change their passwords..

but i'm sort of unsure about one thing right now..

to modify a user record.. would this work?

(this is just a simple example)

Code:
my ($original);

my $db = new Links: BSQL "$LINKS{admin_root_path}/defs/Users.def";
my $USER = &load_user ($in);

foreach my $key (keys %$USER) {
$original->{$key} = $USER->{$key};
$USER->{$key} = $in->param($key) if ($in->param($key));
}
$USER->{Username} = $original->{Username};
$USER->{Status} = $original->{Status};

my $id = $db->modify_record ($USER);
if (!$id) {
# error: <ul>$Links: BSQL::error</ul>
}
# success

is that right.. the part i'm unsure of is..

Code:
my $id = $db->modify_record ($USER);

jerry
Quote Reply
Re: user utilities In reply to
i'm not sure what you meant.. i'm looking at load_user in HTML_Templates.pm and this is what i see..

my ($dynamic, $hash, $category_id) = @_;

i'm guessing what you're telling me has to do something with $hash

right now.. i'm doing this.. and it works..

Code:
$USER = &load_user ($in);
if (! defined $USER) {
print $in->redirect("$LINKS{db_cgi_url}/user.cgi?to=$ENV{'SCRIPT_NAME'}") and return;
}

$USER is inside of the use vars so i can use it in the other subroutines in the script..

jerry
Quote Reply
Re: user utilities In reply to
Hi Jerry,

You need to pass a hash ref to load_user if you are going to use it. It's not the best calling convention I know, but you'll probably get a error trying to derefernce a non existing hash.

As for modify_record, you simply pass in the hash_ref of the info you want. What get's returned is either a 1 if successfull or an undefined if there was a failure. So what you have works, it's just not an id.

Cheers,

Alex

Quote Reply
Re: user utilities In reply to
It works? Hmm.. If you look at load_user you'll see:

foreach (keys %$user) { $hash->{$_} = $user->{$_} unless (exists $hash->{$_}); }

What this does is copy the user fields into a hash ref that was passed in. I would have thought since $hash is undefined it would throw an error when you try and dereference it.

The whole reason for this is so that if you have an existing hash of things you want to display, you can add in the user information easily as in:

&load_user ($in, \%display);

Then %display has all the original info, plus the user information as well. Without the second args, I'm not sure how it's working. Wink

Cheers,

Alex
Quote Reply
Re: user utilities In reply to
when i do

$USER = &load_user ($in);

it gets the session and then figures out the user.. then it adds the user's info to $hash..

since i put

my $USER = &load_user ($in);

$USER->{Username} is now equal to the user's username..

i'm still having a problem with the modify record thing though..

i keep getting

"The requested record was not found in the database."

you can see the example here:

http://www.pdamania.com/account/edit.cgi

login as

u: pdamania
p: test

thanks alex!

jerry
Quote Reply
Re: user utilities In reply to
sorry.. the last post made it seem like i didn't even look at the problem before i asked for help.. Smile

anyways.. i've been looking in modify_record in DBSQL.pm

and this line

Code:
my $where = "$key = $key_q";

$key is equal to 'Username' and
$key_q is equal to 'PDAmania'

pretty much is what searches for the record..

anyways.. i'm pretty sure $USER is defined or else it would make you login all the time and the email field wouldn't have the correct email..

this is my sub edit

Code:
sub edit {
# --------------------------------------------------------
my ($in, $dynamic) = @_;
my ($original);

foreach my $key (keys %$USER) {
$original->{$key} = $USER->{$key};
$USER->{$key} = $in->param($key) if ($in->param($key));
}
$USER->{Username} = $original->{Username};
$USER->{Status} = $original->{Status};

my $db = new Links: BSQL "$LINKS{admin_root_path}/defs/Users.def";
my $id = $db->modify_record ($USER);
if (!$id) {
print $in->header();
print qq~<ul>$Links: BSQL::error</ul>~;
}
else {
print $in->header();
print qq~Successful!~;
}
}

$USER is defined in sub main.. but it is global.. $db is correct..

so i'm really unsure what the problem is here..

jerry
Quote Reply
Re: user utilities In reply to
ok.. i'm confused..

it only returns

"The requested record was not found in the database."

if you didn't modify any of the fields..

i changed the email address and it said

successful! (which is my temp success message)

and yes.. it did modify it..

so modify_record returns not found if the record is not changed?

is it possible to change that so that you can return NO change or something..

i'm guessing you can simply do a

select * from Users where Username = 'PDAmania'

first.. and then if it returns 0 hits return with not found.. then the regular one can be changed to no change..

------------------
Jerry Su
Links SQL Licensed
------------------
Quote Reply
Re: user utilities In reply to
Hi,

This is mysql actually. If you do a modify and don't change anything, it returns false. That should be trapped though, as it should return '0E0' which evaluates to false, but is not equal to 0. In sub modify_record, you'll see that's why I do the comparision to 0.

I'll have to take another look..

Cheers,

Alex
Quote Reply
Re: user utilities In reply to
Jerry,

How is this project coming along?
Could you share it with us? I know that you probably don't have time now, because of school, but how about this summer?



------------------
Robert Blackstone
Webmaster of Scato Search
www.scato.com
Quote Reply
Re: user utilities In reply to
i think i did finish this.. not sure.. i didn't even know i had it until i read this.. but i remember i got far on it.. to a point that i was satisfied

i have to figure out how to get my dedicated server to work.. anyone know a good place with tutorials and help on configurating apache? my cgi doesn't work where i want it to.. plus i want wildcards

thanks..

jerry
Quote Reply
Re: user utilities In reply to
Jerry....

Give me access and I'll configure your server, if you release some of the code in development you've been holding on to. Smile Mainly the review2 stuff for the graphics routines and such. A lot of people really want that, and 10 weeks is a long time.

For apache you should check out apache.org.

Also, you should install WebMin until you get comfortable with the server. Even then, it makes simple tasks really simple.

As I said... I'll do it for you and set up webmin etc so you can do your own reconfig if you'll release the code you've got so we can continue it.

Once the server is configured, it's easier to see how to add in additional features.

Fair trade Smile