diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-09-17 20:40:40 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-09-17 20:40:40 (GMT) |
commit | 44fe836460e880cd130c2ab8fccf15e4400ca223 (patch) | |
tree | 2d9e3bdc3cd6bd806453164c95a1ed2b6776b346 | |
parent | 4a6024bc89becc2d6cd191de72851d68dded014d (diff) |
getting tokens from database should work now
-rwxr-xr-x | authtoken.json | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/authtoken.json b/authtoken.json index 3d6b8f4..2b27575 100755 --- a/authtoken.json +++ b/authtoken.json @@ -10,16 +10,27 @@ sub get_token my $username = shift; my $RD_CONF = "/etc/rd.conf"; - my $cfg = Config::IniFiles->new(-file => $RD_CONF) or return ('ERROR', "Config File Error: " . join("\n", @Config::IniFiles::errors), ''); + my $cfg = Config::IniFiles->new(-file => $RD_CONF) + or return ('ERROR', "Config File Error: " . join("\n", @Config::IniFiles::errors), ''); my $dbhost = $cfg->val('mySQL', 'Hostname'); my $dbname = $cfg->val('mySQL', 'Database'); my $dbuser = $cfg->val('mySQL', 'Loginname'); my $dbpasswd = $cfg->val('mySQL', 'Password'); - my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd") or return ('ERROR', "Database Error: $DBI::errstr", ''); + my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd") + or return ('ERROR', "Database Error: " . $DBI::errstr, ''); - return ('OK', 'success', 'this is still not the right token but we will get to it!!'); + my $sth = $dbh->prepare('select PASSWORD from USERS where LOGIN_NAME = ?') + or return ('ERROR', "Database Error: " . $dbh->errstr, ''); + + $sth->execute($username) + or return ('ERROR', "Database Error: " . $sth->errstr, ''); + + my ($token) = $sth->fetchrow_array; + return ('OK', 'success', $token) if(defined $token); + + return ('ERROR', "user '" . $username . "' not known", '') } my $status = 'ERROR'; @@ -30,7 +41,7 @@ if(defined $ENV{REMOTE_USER}) { ($status, $errorstring, $token) = get_token($ENV{REMOTE_USER}); $username = $ENV{REMOTE_USER}; } else { - $errorstring = 'no username defined'; + $errorstring = 'no username defined - are you logged in?'; } print "Content-type: application/json\n\n"; |