Gossamer Forum
Home : General : Perl Programming :

Can't modify constant item in scalar assignment

Quote Reply
Can't modify constant item in scalar assignment
i want to allow users to login with EITHER userid or email address. i've added Email field to login form. here's original code for authenticating valid user:
Code:
sub auth_valid_user {
# -------------------------------------------------------------------
# This function returns 1 if the user/pass combo is valid, 0/undef
# otherwise.
#
my $args = shift;
my $table = $args->{Table};

return $DB->table($table)->select ( { Username => $args->{Username}, Password => $args->{Password} }, ['Username'] )->rows;
here's what i've done so far and gotten error: Can't modify constant item in scalar assignment

Code:
sub auth_valid_user {
# -------------------------------------------------------------------
# This function returns 1 if the user/pass combo is valid, 0/undef
# otherwise.
#
my $args = shift;
my $table = $args->{Table};
my $password = $args->{Password};
my $email = $args->{Email};
# 8/06/2010
if ($email) {
SELECT Username FROM $table WHERE Email = '$email' and Password = '$password';
return $DB->table($table)->select ( { Username => $args->{Username}, Password => $args->{Password} }, ['Username'] )->rows;
}
###
return $DB->table($table)->select ( { Username => $args->{Username}, Password => $args->{Password} },

['Username'] )->rows;
}
user won't even get to this sub if they leave both email & username blank. what i need to do is lookup the username if they entered email instead. then use the username for everything subsequent. remember i'm a trial and error person, so i'm sure this is a simple problem!
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
What line do you get this error on?

Quote:
Can't modify constant item in scalar assignment

Will help to track down where the problem is ;)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Can't modify constant item in scalar assignment In reply to
line 56, near "'$password';"

SELECT Username FROM $table WHERE Email = '$email' and Password = '$password';

when i comment out that line, i don't get the error

Last edited by:

delicia: Aug 7, 2010, 5:31 AM
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
Hi,

Ah duh - the reason you are getting that error is simple :P

Code:
if ($email) {
SELECT Username FROM $table WHERE Email = '$email' and Password = '$password';
return $DB->table($table)->select ( { Username => $args->{Username}, Password => $args->{Password} }, ['Username'] )->rows;

You can't just do:

Code:
SELECT Username FROM $table WHERE Email = '$email' and Password = '$password';

You need something like:

Code:
return $DB->table($table)->select ( { Email => $email, Password => $password }, ['Username'] )->rows;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Can't modify constant item in scalar assignment In reply to
got it working now!

Code:
sub auth_valid_user {
# -------------------------------------------------------------------
# This function returns 1 if the user/pass combo is valid, 0/undef
# otherwise.
#
my $args = shift;
my $table = $args->{Table};
my $email = $args->{Email};
# 8/06/2010
if ($email) {
my $duser = $DB->table($table)->select ( { Email => $args->{Email}, Password => $args->{Password} },

['Username'] )->rows;
return $DB->table($table)->select ( { Username => $duser, Password => $args->{Password} }, ['Username']

)->rows;
}
###
return $DB->table($table)->select ( { Username => $args->{Username}, Password => $args->{Password} },

['Username'] )->rows;
}
after i fixed the syntax problem, it wasn't working because i forgot to comment out the section that looked for username before it called this sub.

i got my original bad SELECT statement from w3schools basic sql info. :(
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
Hi,

You sure you don't need something like this? (I'm not sure the code you have is actually doing what you want)

Code:
sub auth_valid_user {
# -------------------------------------------------------------------
# This function returns 1 if the user/pass combo is valid, 0/undef
# otherwise.
#
my $args = shift;
my $table = $args->{Table};
my $email = $args->{Email};
# 8/06/2010
if ($email) {
if ($DB->table($table)->count ( { Email => $args->{Email}, Password => $args->{Password} } ) > 0) {
return $DB->table($table)->select ( ['Username'], { Email => $args->{Email}, Password => $args->{Password} } )->fetchrow;
}
}
###
return $DB->table($table)->select ( ['Username'], { Username => $args->{Username}, Password => $args->{Password} } )->fetchrow;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

Last edited by:

Andy: Aug 7, 2010, 6:39 AM
Quote Reply
Re: [Andy] Can't modify constant item in scalar assignment In reply to
well, i don't understand what your code does, especially count. the original code passed the username and password from the login form, looked up this info in the usertable and returned the user info as valid user. i want to pass the password and either the email or username. if an email was passed, i want to lookup the email/password combo to find the username. then i thought it would be safer (because i don't know what i'm doing) to use the original return statement to send back my valid user info.
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
Hi,

All my code does, is:

Code:
if (RECORD EXISTS WITH Email AND Password COMBINATION) {
{ return the username for that combination }
}

otherwise, if we get here - just do the normal lookup code

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Can't modify constant item in scalar assignment In reply to
ok. i think my code is correct then because i still need to get the user info as if the username had been passed to this sub instead of looked up.
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
Hi,

Up to you - but my code does exactly the same ;) (just a bit cleaner)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
Actually, looking at it - this will work (all that routine wants returned, is a 1 or 0 ... i.e true or false)

Code:
sub auth_valid_user {
# -------------------------------------------------------------------
# This function returns 1 if the user/pass combo is valid, 0/undef
# otherwise.
#
my $args = shift;
my $table = $args->{Table};
my $email = $args->{Email};
# 8/06/2010
if ($email) {
if ($DB->table($table)->count ( { Email => $args->{Email}, Password => $args->{Password} } ) > 0) {
return 1;
} else {
return 0;
}
}
###
return $DB->table($table)->select ( ['Username'], { Username => $args->{Username}, Password => $args->{Password} } )->rows;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Can't modify constant item in scalar assignment In reply to
i tried this, but it doesn't work so i'm going back to what i had. this one says invalid user or password when i try to log in with email.
Quote Reply
Re: [delicia] Can't modify constant item in scalar assignment In reply to
now it doesn't work. i think i figured out why it worked before. after running the valid user check and failing, it tries to get a valid user from a session or cookie. now that i've been away from the computer awhile, i guess my cookie expired. so what's happening is, i think my routine (or yours) finds the username but it doesn't set the username variable. so when it returns 1, as you pointed out, it still has no username to take to the next step. how can i get it to return the username?

this is the call to the sub:

if ( Dbsql::Authenticate::auth('valid_user', { Table => $self->{glb_cfg}->{default_user_table},
Username => $username, Password => $password, Email => $email }) ) {