From: Robert Haas Date: Mon, 25 May 2009 01:58:19 +0000 (-0400) Subject: Rearrange to work better with community logins. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=1e5057be510f91d06c7f9d8c126f94f085bc0694;p=pgcommitfest.git Rearrange to work better with community logins. --- 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(<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(<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 @@ - [% IF authenticate.username.defined %]Welcome, [% authenticate.username | htmlsafe %] - Log Out + [% IF authenticate.userid.defined %]Welcome, [% authenticate.userid | htmlsafe %] - Log Out [% ELSE %]Log In [% END %] 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 @@ -

Please log in using your username and password.

+

Please log in using your community login user ID and password.

- - + +
[% control.username.display_name | htmlsafe %][% control.username.render %][% control.userid.display_name | htmlsafe %][% control.userid.render %]
[% control.password.display_name | htmlsafe %]