Permalink
Browse files

Use db-specific handle to find email addresses

  • Loading branch information...
1 parent bd4e101 commit af2b3977dfc04a1b0e6530fdd0818b35d3cab065 @xdg xdg committed Aug 13, 2011
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/PAUSE/MailAddress.pm
View
@@ -10,22 +10,16 @@ sub new {
}
sub new_from_userid {
- my($class,$userid,$opt) = @_;
- my $dbh = $opt->{dbh} ||
- DBI->connect(
- $PAUSE::Config->{MOD_DATA_SOURCE_NAME},
- $PAUSE::Config->{MOD_DATA_SOURCE_USER},
- $PAUSE::Config->{MOD_DATA_SOURCE_PW},
+ my($class,$userid) = @_;
+ my $dbh = DBI->connect(
+ $PAUSE::Config->{AUTHEN_DATA_SOURCE_NAME},
+ $PAUSE::Config->{AUTHEN_DATA_SOURCE_USER},
+ $PAUSE::Config->{AUTHEN_DATA_SOURCE_PW},
{ RaiseError => 1 }
)
or Carp::croak(qq{Can't DBI->connect(): $DBI::errstr});
- my $dsn = $PAUSE::Config->{AUTHEN_DATA_SOURCE_NAME};
- my(undef,undef,$dbname) = split /:/, $dsn;
- if ($dbname =~ /;/) {
- ($dbname) = $dsn =~ /database=(\w+)/;
- }
my $sth = $dbh->prepare("SELECT secretemail
- FROM $dbname.$PAUSE::Config->{AUTHEN_USER_TABLE}
+ FROM $PAUSE::Config->{AUTHEN_USER_TABLE}
WHERE $PAUSE::Config->{AUTHEN_USER_FLD}=?");
$sth->execute($userid);
my $me = {};
@@ -37,6 +31,13 @@ sub new_from_userid {
$me->{address} = $addr;
$me->{is_secret} = 1;
} else {
+ my $dbh = DBI->connect(
+ $PAUSE::Config->{MOD_DATA_SOURCE_NAME},
+ $PAUSE::Config->{MOD_DATA_SOURCE_USER},
+ $PAUSE::Config->{MOD_DATA_SOURCE_PW},
+ { RaiseError => 1 }
+ )
+ or Carp::croak(qq{Can't DBI->connect(): $DBI::errstr});
$sth = $dbh->prepare("SELECT email FROM users WHERE userid=?");
$sth->execute($userid);
if ($sth->rows >= 0){

0 comments on commit af2b397

Please sign in to comment.