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:
# -------------------------------------------------------------------
# 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
# -------------------------------------------------------------------
# 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!
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;
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;
}