[Codestriker-commits] CVS update: codestriker/bin install.pl
Brought to you by:
sits
|
From: <si...@us...> - 2008-09-07 04:49:28
|
User: sits
Date: 08/09/06 21:49:27
Modified: lib/Codestriker/Model User.pm
lib/Codestriker/Http/Method LoginMethod.pm
AuthenticateMethod.pm
lib/Codestriker/Http UrlBuilder.pm Dispatcher.pm
bin install.pl
Added: template/en/default login.html.tmpl
lib/Codestriker/Action Login.pm
Log:
Now have the example login page in the system.
Index: login.html.tmpl
===================================================================
RCS file: login.html.tmpl
diff -N login.html.tmpl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ login.html.tmpl 7 Sep 2008 04:49:26 -0000 1.1
@@ -0,0 +1,57 @@
+[%# Screen for login form. #%]
+
+[% PROCESS header.html.tmpl version = version displaymenu = 1
+ closehead = 1 subtitle = "Login" %]
+<p>
+Please enter your email address and password to continue.
+</p>
+
+<form method="post" enctype="application/x-www-form-urlencoded" action="[% action_url %]">
+
+<input type="hidden" name="action" value="authenticate" />
+ <table>
+ <tr>
+ <th align="right">E-mail address:</th>
+ <td>
+ <input size="40" maxlength="80" name="email">
+ </td>
+ </tr>
+ <tr>
+ <th align="right">Password:</th>
+ <td>
+ <input type="password" size="40" name="password">
+ </td>
+ </tr>
+ <tr>
+ <th> </th><td> </td>
+ </tr>
+ </table>
+
+ <input type="submit" name=".submit" value="Log in" />
+
+</form>
+
+<!--
+<hr>
+
+<p>
+If you don't have a Codestriker account, you can create a new account.
+</p>
+
+<hr>
+
+<form method="post" enctype="application/x-www-form-urlencoded" action="[% action_url %]">
+ <input type="hidden" name="action" value="reset_password">
+ <p>
+ If you have an account, but have forgotten your password,
+ enter your e-mail address below to generate a new password.
+ </p>
+ <input size="40" maxlength="80" name="email">
+ <input type="submit" name=".submit2" value="Regenerate Password">
+</form>
+-->
+
+[% PROCESS trailer.html.tmpl %]
+
+</body>
+</html>
Index: User.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Model/User.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- User.pm 6 Sep 2008 11:33:06 -0000 1.2
+++ User.pm 7 Sep 2008 04:49:26 -0000 1.3
@@ -24,15 +24,16 @@
my $dbh = Codestriker::DB::DBI->get_connection();
eval {
my $select_user =
- $dbh->prepare_cached('SELECT password_hash, admin ' .
+ $dbh->prepare_cached('SELECT password_hash, challenge, admin ' .
'FROM usertable ' .
'WHERE email = ?');
$select_user->execute($email);
- my ($password_hash, $admin) = $select_user->fetchrow_array();
+ my ($password_hash, $challenge, $admin) = $select_user->fetchrow_array();
$select_user->finish();
$self->{password_hash} = $password_hash;
+ $self->{challenge} = $challenge;
$self->{admin} = $admin;
};
my $success = $@ ? 0 : 1;
@@ -45,11 +46,41 @@
return $self;
}
+# Determine if the specific user already exists.
+sub exists {
+ my ($type, $email) = @_;
+
+ # Obtain a database connection.
+ my $dbh = Codestriker::DB::DBI->get_connection();
+
+ my $count = 0;
+ eval {
+ my $select_email =
+ $dbh->prepare_cached('SELECT COUNT(*) FROM usertable ' .
+ 'WHERE email = ?');
+ $select_email->execute($email);
+ ($count) = $select_email->fetchrow_array();
+ $select_email->finish();
+ };
+ my $success = $@ ? 0 : 1;
+
+ Codestriker::DB::DBI->release_connection($dbh, $success);
+ die $dbh->errstr unless $success;
+
+ return $count;
+}
+
# Update an existing user record with a new password.
sub update_password {
my ($self, $new_password) = @_;
- my $password_hash = _hash_password($new_password);
+ $self->update_password_hash(_hash_password($new_password));
+}
+
+# Update an existing user record with a new password_hash.
+sub update_password_hash {
+ my ($self, $password_hash) = @_;
+
my $dbh = Codestriker::DB::DBI->get_connection();
eval {
my $update_user =
@@ -113,28 +144,33 @@
return $new_password;
}
-# Determine if the specific user already exists.
-sub exists {
- my ($type, $email) = @_;
+# Create a challenge key into the user table for supporting the
+# case where a user can update their password via a
+# challenge/response protocol.
+sub create_challenge {
+ my ($self, $email) = @_;
# Obtain a database connection.
my $dbh = Codestriker::DB::DBI->get_connection();
- my $count = 0;
+ # Create a random challenge for the user.
+ my $new_password = _create_random_password();
+ my $challenge = _hash_password($new_password);
+
+ # Set this challenge into the user record.
eval {
- my $select_email =
- $dbh->prepare_cached('SELECT COUNT(*) FROM usertable ' .
- 'WHERE email = ?');
- $select_email->execute($email);
- ($count) = $select_email->fetchrow_array();
- $select_email->finish();
+ my $challenge_update =
+ $dbh->prepare_cached('UPDATE usertable ' .
+ 'SET challenge = ? ' .
+ 'WHERE email = ? ');
+ $challenge_update->execute($self->{email}, $challenge);
};
my $success = $@ ? 0 : 1;
Codestriker::DB::DBI->release_connection($dbh, $success);
die $dbh->errstr unless $success;
- return $count;
+ return $challenge;
}
# Method for producing a hash from a password.
Index: LoginMethod.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/LoginMethod.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoginMethod.pm 7 Sep 2008 03:44:15 -0000 1.1
+++ LoginMethod.pm 7 Sep 2008 04:49:26 -0000 1.2
@@ -11,6 +11,7 @@
use strict;
use Codestriker::Http::Method;
+use Codestriker::Action::Login;
@Codestriker::Http::Method::LoginMethod::ISA = ("Codestriker::Http::Method");
@@ -50,7 +51,7 @@
sub execute {
my ($self, $http_input, $http_output) = @_;
- Codestriker::Action::LoginAction->process($http_input, $http_output);
+ Codestriker::Action::Login->process($http_input, $http_output);
}
1;
Index: AuthenticateMethod.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/AuthenticateMethod.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AuthenticateMethod.pm 7 Sep 2008 03:44:15 -0000 1.1
+++ AuthenticateMethod.pm 7 Sep 2008 04:49:26 -0000 1.2
@@ -44,7 +44,7 @@
sub execute {
my ($self, $http_input, $http_output) = @_;
- Codestriker::Action::AuthenticateAction->process($http_input, $http_output);
+ Codestriker::Action::Authenticate->process($http_input, $http_output);
}
1;
Index: UrlBuilder.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- UrlBuilder.pm 6 Sep 2008 06:03:56 -0000 1.49
+++ UrlBuilder.pm 7 Sep 2008 04:49:26 -0000 1.50
@@ -35,6 +35,8 @@
use Codestriker::Http::Method::UpdateTopicMetricsMethod;
use Codestriker::Http::Method::UpdateCommentMetricsMethod;
use Codestriker::Http::Method::UpdateTopicStateMethod;
+use Codestriker::Http::Method::LoginMethod;
+use Codestriker::Http::Method::AuthenticateMethod;
# Constructor for this class.
sub new {
@@ -225,4 +227,17 @@
return Codestriker::Http::Method::DownloadMetricsMethod->new($self->{query})->url();
}
+# Create the URL for going to the login page.
+sub login_url {
+ my ($self, %args) = @_;
+ return Codestriker::Http::Method::LoginMethod->new($self->{query})->url(%args);
+}
+
+# Create the URL for authenticating.
+sub authenticate_url {
+ my ($self, %args) = @_;
+ return Codestriker::Http::Method::AuthenticateMethod->new($self->{query})->url(%args);
+}
+
+
1;
Index: Dispatcher.pm
===================================================================
RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Dispatcher.pm 6 Sep 2008 00:31:47 -0000 1.10
+++ Dispatcher.pm 7 Sep 2008 04:49:26 -0000 1.11
@@ -38,6 +38,8 @@
use Codestriker::Http::Method::ViewMetricsMethod;
use Codestriker::Http::Method::UpdateTopicStateMethod;
use Codestriker::Http::Method::AddProjectMethod;
+use Codestriker::Http::Method::LoginMethod;
+use Codestriker::Http::Method::AuthenticateMethod;
# Initialise all of the methods that are known to the system.
# TODO: add configuration to the parameter.
@@ -77,6 +79,8 @@
push @methods, Codestriker::Http::Method::ViewMetricsMethod->new($query);
push @methods, Codestriker::Http::Method::UpdateTopicStateMethod->new($query);
push @methods, Codestriker::Http::Method::AddProjectMethod->new($query);
+ push @methods, Codestriker::Http::Method::LoginMethod->new($query);
+ push @methods, Codestriker::Http::Method::AuthenticateMethod->new($query);
$self->{methods} = \@methods;
return bless $self, $type;
@@ -87,6 +91,9 @@
sub dispatch {
my ($self, $http_input, $http_output) = @_;
+ # TODO: put login in here which redirects to the login form
+ # if appropriate with the full URL in the redirect parameter.
+
foreach my $method ( @{$self->{methods}} ) {
if ($method->extract_parameters($http_input)) {
$method->execute($http_input, $http_output);
Index: Login.pm
===================================================================
RCS file: Login.pm
diff -N Login.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Login.pm 7 Sep 2008 04:49:27 -0000 1.1
@@ -0,0 +1,35 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# si...@us...
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Action object for displaying the login page.
+
+package Codestriker::Action::Login;
+
+use strict;
+use Codestriker::Http::UrlBuilder;
+
+# Create an appropriate form for logging in.
+sub process {
+ my ($type, $http_input, $http_response) = @_;
+
+ my $query = $http_response->get_query();
+
+ $http_response->generate_header(topic_title=>"Login",
+ reload=>0, cache=>1);
+
+ # Target URL to divert the post to.
+ my $vars = {};
+ my $url_builder = Codestriker::Http::UrlBuilder->new($query);
+ $vars->{'action_url'} = $url_builder->authenticate_url();
+
+ my $template = Codestriker::Http::Template->new("login");
+ $template->process($vars);
+
+ $http_response->generate_footer();
+}
+
+1;
Index: install.pl
===================================================================
RCS file: /cvsroot/codestriker/codestriker/bin/install.pl,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- install.pl 6 Sep 2008 11:33:06 -0000 1.24
+++ install.pl 7 Sep 2008 04:49:27 -0000 1.25
@@ -579,6 +579,7 @@
table(name => "usertable",
columns => [col(name=>"email", type=>$VARCHAR, length=>200, pk=>1),
col(name=>"password_hash", type=>$VARCHAR, length=>128),
+ col(name=>"challenge", type=>$VARCHAR, length=>128, mandatory=>0),
col(name=>"admin", type=>$INT16)
],
indexes => []);
@@ -1071,12 +1072,14 @@
# Now create any admin users, if necessary.
$dbh->{PrintError} = 1;
+my $user_added = 0;
if (defined $Codestriker::admin_users) {
foreach my $admin_user (@{ $Codestriker::admin_users }) {
if (!Codestriker::Model::User->exists($admin_user)) {
print "Creating admin user $admin_user...\n";
Codestriker::Model::User->create($admin_user, 1);
# TODO: consider sending email with password details.
+ $user_added = 1;
print "Done\n";
} else {
# Existing user, check if they are an admin already.
@@ -1084,11 +1087,13 @@
if (! $user->{admin}) {
print "Upgrading non-admin user $admin_user to admin...\n";
$user->update_admin(1);
+ $user_added = 1;
print "Done\n";
}
}
}
}
+$database->commit() if $user_added;
# Now generate the contents of the codestriker.pl file, with the appropriate
# configuration details set (basically, the location of the lib dir).
|