awohld has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get CGI::Session::Auth::DBI to work with PostgreSQL but it's not erroring out or kicking back DB errors. When I put in the wrong dbname it doesn't die.

Here's what I'm trying to do:
1. Get a session authenticated and started.
2. Get DB connection errors kicked back to me.

Can someone see what I'm doing wrong?

Here's my script:
#!/usr/bin/perl -w use strict; use CGI; use CGI::Session; use CGI::Session::Auth::DBI; use CGI::Carp; use DBI; # CGI object for headers, cookies, etc. my $cgi = new CGI; my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'}); my $auth = new CGI::Session::Auth({ CGI => $cgi, Session => $session, DSN => 'DBI:PgPP:dbname=databasename', UserTable => 'users', DBUser => 'dbusername', DBPasswd => 'dbpassword', DBAttr => 'PrintError => 1, RaiseError => 1' }); $auth->authenticate(); # check if visitor has already logged in if ($auth->loggedIn) { &showSecretPage; } else { &showLoginPage; } sub showLoginPage { print $cgi->header; print <<EOF; <html> <head> <title>Login</title> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="r +ed"> <form name="form1" method="post" action="./auth.pl"> <p>Password: <input type="text" name="log_username" maxlength="10" + size="10"></p> <p>Username: <input type="text" name="log_password" maxlength="10" + size="10"></p> <p><input type="submit" name="Submit"></p> </form> <p>&nbsp;</p> </body> </html> EOF } sub showSecretPage { print $cgi->header; print "Sucess!"; }
Here's the SQL to create the table in PostgreSQL. The username is "test" with password "pass":
-- -- PostgreSQL database dump -- SET client_encoding = 'LATIN1'; SET check_function_bodies = false; SET client_min_messages = warning; SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -- -- Name: users; Type: TABLE; Schema: public; Owner: dbusername; Tables +pace: -- CREATE TABLE users ( userid character varying(50) NOT NULL, first_name character varying(40) NOT NULL, last_name character varying(40) NOT NULL, passwd character varying(16) NOT NULL, email character varying(100) NOT NULL, privilege character varying(2) NOT NULL, username character varying(40) NOT NULL ); ALTER TABLE public.users OWNER TO dbusername; -- -- Name: userid; Type: DEFAULT; Schema: public; Owner: dbusername -- ALTER TABLE users ALTER COLUMN userid SET DEFAULT nextval('"users_user +_ID_seq"'::regclass); -- -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: dbus +ername -- COPY users (userid, first_name, last_name, passwd, email, privilege, u +sername) FROM stdin; 325684ec1b028eaf562dd484c5607a65 Allan Hubert pass adam@m +ysite.org 0 test \. -- -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: dbuserna +me; Tablespace: -- ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY KEY (userid); -- -- PostgreSQL database dump complete --


UPDATE: Found the problem. I was creating the object with CGI::Session::Auth when I should have been using CGI::Session::Auth::DBI

Replies are listed 'Best First'.
Re: Trying to get CGI::Session::Auth::DBI to work.
by jesuashok (Curate) on May 11, 2006 at 06:13 UTC
    Hi

    This is erroring out for me as expected ... !!!!!

    my $auth = new CGI::Session::Auth({ CGI => $cgi, Session => $session, DSN => 'DBI:PgPP:dbname=databasename', UserTable => 'users', DBUser => 'dbusername', DBPasswd => 'dbpassword', DBAttr => 'PrintError => 1, RaiseError => 1' }); print "Error\n" if ( not defined $auth );

    Pleasec check those conditions in your code too !!!!

    "Keep pouring your ideas"