diff options
author | Robert Haas | 2009-05-25 01:58:19 +0000 |
---|---|---|
committer | Robert Haas | 2009-05-25 01:58:19 +0000 |
commit | 1e5057be510f91d06c7f9d8c126f94f085bc0694 (patch) | |
tree | 9d9ece9555e14c1017b491f355f67408ea358058 | |
parent | ac388f52de42c45c1da5f5d99c86d2f6cc1adb12 (diff) |
Rearrange to work better with community logins.
-rw-r--r-- | etc/function.sql | 10 | ||||
-rw-r--r-- | etc/table.sql | 10 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/Handler.pm | 14 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/Patch.pm | 2 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/PatchComment.pm | 2 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/Request.pm | 2 | ||||
-rw-r--r-- | template/header.tt2 | 2 | ||||
-rw-r--r-- | template/login.tt2 | 6 |
8 files changed, 25 insertions, 23 deletions
diff --git a/etc/function.sql b/etc/function.sql index c65ad59..c83739d 100644 --- a/etc/function.sql +++ b/etc/function.sql @@ -21,3 +21,13 @@ BEGIN END LOOP; END $$ LANGUAGE plpgsql; + +-- Dummy implementation for testing purposes. +CREATE OR REPLACE FUNCTION community_login(INOUT userid text, password text, + OUT success integer) RETURNS record AS $$ +BEGIN + SELECT userid, CASE WHEN LOWER(userid) = 'rhaas' AND password = 'bob' + THEN 1 ELSE 0 END + INTO userid, success; +END +$$ LANGUAGE plpgsql; diff --git a/etc/table.sql b/etc/table.sql index 5f941f4..44ae05f 100644 --- a/etc/table.sql +++ b/etc/table.sql @@ -1,12 +1,6 @@ -CREATE TABLE person ( - username varchar not null, - sha512password varchar not null, - PRIMARY KEY (username) -); - CREATE TABLE session ( id varchar not null, - username varchar not null references person (username), + userid varchar not null, login_time timestamp not null default now(), PRIMARY KEY (id) ); @@ -75,7 +69,7 @@ CREATE TABLE patch_comment ( references patch_comment_type (id), message_id varchar, content varchar, - creator varchar not null references person (username), + creator varchar not null, creation_time timestamp with time zone not null default now(), PRIMARY KEY (id) ); diff --git a/perl-lib/PgCommitFest/Handler.pm b/perl-lib/PgCommitFest/Handler.pm index 6ad00d9..820364a 100644 --- a/perl-lib/PgCommitFest/Handler.pm +++ b/perl-lib/PgCommitFest/Handler.pm @@ -1,5 +1,4 @@ package PgCommitFest::Handler; -require Digest::SHA; require PgCommitFest::CommitFest; require PgCommitFest::CommitFestTopic; require PgCommitFest::Patch; @@ -80,9 +79,9 @@ sub handler { sub login { my ($r) = @_; - # Prompt for username and password. + # Prompt for user ID and password. $r->set_title('Log in'); - $r->add_control('username', 'text', 'Username', 'required' => 1); + $r->add_control('userid', 'text', 'User ID', 'required' => 1); $r->add_control('password', 'password', 'Password', 'required' => 1); $r->add_control('uri', 'hidden', 'URI'); my %value = $r->initialize_controls(); @@ -93,10 +92,9 @@ sub login { # Attempt to validate login. if ($r->cgi('go') && ! $r->is_error) { my $u = $r->db->select_one(<<EOM, -SELECT username FROM person WHERE username = ? AND sha512password = ? +SELECT userid FROM community_login(?, ?) WHERE success != 0 EOM - $value{'username'}, - Digest::SHA::sha512_base64($value{'password'})); + $value{'userid'}, $value{'password'}); if (defined $u) { my $random_bits; open(RANDOM_BITS, '</dev/urandom') || die "/dev/urandom: $!"; @@ -104,13 +102,13 @@ EOM close(RANDOM_BITS); my $session_cookie = unpack("H*", $random_bits); $r->db->insert('session', { 'id' => $session_cookie, - 'username' => $u->{'username'} }); + 'userid' => $u->{'userid'} }); $r->db->commit; $r->header('Set-Cookie', "session=$session_cookie; path=/"); $r->redirect($value{'uri'} ne '' ? $value{'uri'} : '/'); } else { - $r->error('Invalid username or password.'); + $r->error('Invalid user ID or password.'); } } diff --git a/perl-lib/PgCommitFest/Patch.pm b/perl-lib/PgCommitFest/Patch.pm index 4b1e323..d278812 100644 --- a/perl-lib/PgCommitFest/Patch.pm +++ b/perl-lib/PgCommitFest/Patch.pm @@ -107,7 +107,7 @@ EOM 'patch_comment_type_id' => 2, 'message_id' => $message_id, 'content' => 'Initial version.', - 'creator' => $aa->{'username'}, + 'creator' => $aa->{'userid'}, }); } $r->db->commit; diff --git a/perl-lib/PgCommitFest/PatchComment.pm b/perl-lib/PgCommitFest/PatchComment.pm index 6d7476b..a0a71e6 100644 --- a/perl-lib/PgCommitFest/PatchComment.pm +++ b/perl-lib/PgCommitFest/PatchComment.pm @@ -64,7 +64,7 @@ EOM } else { $value{'patch_id'} = $d->{'patch_id'}; - $value{'creator'} = $aa->{'username'}; + $value{'creator'} = $aa->{'userid'}; $id = $r->db->insert_returning_id('patch_comment', \%value); } $r->db->commit; diff --git a/perl-lib/PgCommitFest/Request.pm b/perl-lib/PgCommitFest/Request.pm index 2a2893d..78911c7 100644 --- a/perl-lib/PgCommitFest/Request.pm +++ b/perl-lib/PgCommitFest/Request.pm @@ -58,7 +58,7 @@ sub authenticate { if (!defined $self->{'authenticate'} && defined $self->cookie('session')) { $self->{'authenticate'} = $self->db->select_one(<<EOM, $self->cookie('session')); -SELECT p.* FROM person p, session s WHERE p.username = s.username AND s.id = ? +SELECT s.* FROM session s WHERE s.id = ? EOM } if (!defined $self->{'authenticate'} && $option{'require_login'}) { diff --git a/template/header.tt2 b/template/header.tt2 index 561259c..b4cdf74 100644 --- a/template/header.tt2 +++ b/template/header.tt2 @@ -15,7 +15,7 @@ </div> </td> <td id="commitfestNav"> - [% IF authenticate.username.defined %]Welcome, [% authenticate.username | htmlsafe %] - <a href='/https/git.postgresql.org/action/logout'>Log Out</a> + [% IF authenticate.userid.defined %]Welcome, [% authenticate.userid | htmlsafe %] - <a href='/https/git.postgresql.org/action/logout'>Log Out</a> [% ELSE %]<a href='/https/git.postgresql.org/action/login'>Log In</a> [% END %] </td> diff --git a/template/login.tt2 b/template/login.tt2 index e99bb8c..e7f581d 100644 --- a/template/login.tt2 +++ b/template/login.tt2 @@ -1,10 +1,10 @@ -<p>Please log in using your username and password.</p> +<p>Please log in using your community login user ID and password.</p> <div class='tblBasic'> <table cellspacing='0' class='tblBasicGrey'> <tr class='firstrow'> - <td class='colFirst'>[% control.username.display_name | htmlsafe %]</td> - <td class='colLast'>[% control.username.render %]</td> + <td class='colFirst'>[% control.userid.display_name | htmlsafe %]</td> + <td class='colLast'>[% control.userid.render %]</td> </tr> <tr class='lastrow'> <td class='colFirst'>[% control.password.display_name | htmlsafe %]</td> |