Rearrange to work better with community logins.
authorRobert Haas <[email protected]>
Mon, 25 May 2009 01:58:19 +0000 (21:58 -0400)
committerRobert Haas <[email protected]>
Mon, 25 May 2009 01:58:19 +0000 (21:58 -0400)
etc/function.sql
etc/table.sql
perl-lib/PgCommitFest/Handler.pm
perl-lib/PgCommitFest/Patch.pm
perl-lib/PgCommitFest/PatchComment.pm
perl-lib/PgCommitFest/Request.pm
template/header.tt2
template/login.tt2

index c65ad59a5e4626b92295546aad8c38afc83058d3..c83739d9d116b7cb6374eb3e3498c6a5d0707f60 100644 (file)
@@ -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;
index 5f941f480a08b89e086418bedf531060b538965d..44ae05faa49319f2d3759f06bd19733debcabf82 100644 (file)
@@ -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)
 );
index 6ad00d9f1f473b444cabc86f863962adb7a400ff..820364adcd8721458a874031c5b72f95c9b7b752 100644 (file)
@@ -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.');
                }
        }
 
index 4b1e32331f83a2e8cfacb1b6ef9b60c53c8fcdac..d278812e5c48c1f1b2eb2b5a0abc172211bf6cc1 100644 (file)
@@ -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;
index 6d7476bd4c021084d29e5536f53b23bb007b81c6..a0a71e61f580a9fc8c96fed582879722a6fd8a13 100644 (file)
@@ -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;
index 2a2893d87251f85deddd776048cc4a51089f9117..78911c7b676159f3e190a21c3b452cf691cec735 100644 (file)
@@ -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'}) {
index 561259c61f73b86b138a4d58abb98ac7a4f0285d..b4cdf74a50b1f666984113d24f6834f7dbe07190 100644 (file)
@@ -15,7 +15,7 @@
       </div>
     </td>
     <td id="commitfestNav">
-       [% IF authenticate.username.defined %]Welcome, [% authenticate.username | htmlsafe %] - <a href='/action/logout'>Log Out</a>
+       [% IF authenticate.userid.defined %]Welcome, [% authenticate.userid | htmlsafe %] - <a href='/action/logout'>Log Out</a>
        [% ELSE %]<a href='/action/login'>Log In</a>
        [% END %]
     </td>
index e99bb8cb2f09316614786a1f7ca5a13ff56c6fa9..e7f581d32f63a52fd1c31f4e4c5bcd4c4d3d84d9 100644 (file)
@@ -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>