* Added authentication.

This commit is contained in:
Eelco Dolstra 2008-11-26 19:48:04 +00:00
parent 632d56e665
commit 50ae3ca9e9
23 changed files with 141 additions and 35 deletions

View file

@ -1 +1,19 @@
name Hydra
<authentication>
default_realm dbic
<realms>
<dbic>
<credential>
class Password
password_field password
password_type hashed
password_hash_type SHA-1
</credential>
<store>
class DBIx::Class
user_class DB::Users
</store>
</dbic>
</realms>
</authentication>

View file

@ -10,6 +10,10 @@ use Catalyst qw/-Debug
ConfigLoader
Static::Simple
StackTrace
Authentication
Session
Session::Store::FastMmap
Session::State::Cookie
/;
our $VERSION = '0.01';

View file

@ -61,8 +61,45 @@ sub index :Path :Args(0) {
}
sub login :Local {
my ($self, $c) = @_;
my $username = $c->request->params->{username} || "";
my $password = $c->request->params->{password} || "";
if ($username && $password) {
if ($c->authenticate({username => $username, password => $password})) {
$c->response->redirect(
defined $c->flash->{afterLogin}
? $c->flash->{afterLogin}
: $c->uri_for('/'));
$c->flash->{afterLogin} = undef;
return;
}
$c->stash->{errorMsg} = "Bad username or password.";
}
$c->stash->{template} = 'login.tt';
}
sub logout :Local {
my ($self, $c) = @_;
$c->logout;
$c->response->redirect($c->uri_for('/'));
}
sub requireLogin {
my ($c) = @_;
$c->flash->{afterLogin} = $c->request->uri;
$c->response->redirect($c->uri_for('/login'));
}
sub queue :Local {
my ($self, $c) = @_;
my ($self, $c) = @_;
return requireLogin($c) if !$c->user_exists;
$c->stash->{template} = 'queue.tt';
$c->stash->{queue} = [$c->model('DB::Builds')->search(
{finished => 0}, {join => 'schedulingInfo', order_by => ["priority DESC", "timestamp"]})];

View file

@ -8,8 +8,8 @@ use base 'DBIx::Class::Schema';
__PACKAGE__->load_classes;
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Pcp+OvDPqTvMftKcbkPkjA
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jK/9VMZBot2RJwtlHA6QIg
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -36,8 +36,8 @@ __PACKAGE__->belongs_to("build", "Hydra::Schema::Builds", { id => "build" });
__PACKAGE__->belongs_to("dependency", "Hydra::Schema::Builds", { id => "dependency" });
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LXmRVGbyhgP5UGYK5ekbog
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LRcAsbLWbetVw+DCDnv/9w
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -33,8 +33,8 @@ __PACKAGE__->set_primary_key("build", "productnr");
__PACKAGE__->belongs_to("build", "Hydra::Schema::Builds", { id => "build" });
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ai10FDZA/INuvAMu+1mvWw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Pu6gWxltfVJJ+9DBiC9bYg
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -29,8 +29,8 @@ __PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to("id", "Hydra::Schema::Builds", { id => "id" });
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KLmCZNoPd+vFmAj7XNtLMQ
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:X5GXZRLAaCMl8OKBGjtztw
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -70,8 +70,8 @@ __PACKAGE__->has_many(
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hm/IA7ESnKT9gls0lw1Daw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:h32zqOEGcpXQy7pshiWVMA
__PACKAGE__->has_many(dependents => 'Hydra::Schema::Buildinputs', 'dependency');

View file

@ -23,8 +23,8 @@ __PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to("id", "Hydra::Schema::Builds", { id => "id" });
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d/8LOVy+FfKFEo7iFbP3Gw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:egegc7kFKTt9cEGuomi0cQ
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -35,8 +35,8 @@ __PACKAGE__->set_primary_key("id", "stepnr");
__PACKAGE__->belongs_to("id", "Hydra::Schema::Builds", { id => "id" });
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a/DM38J4HR2LBDTeXvt4uA
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kFD90OFRM1aqVVCBCh/geA
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -22,8 +22,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("srcpath", "sha256hash");
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Pnefs6s7Y0i3YRE+BoWdDg
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:r/3GaLIIWaX1fh8kfuQp+w
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -20,8 +20,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("uri", "revision");
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gmw8LSLTRV00vCYDKiuZOw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yTp1XcBSQ+6OJvVLugRh1w
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -33,8 +33,8 @@ __PACKAGE__->belongs_to(
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:R26KAvuQZHKAyG/hEaB6Gw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lYdNLENxLW2mtZ2w+jou8w
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -43,8 +43,8 @@ __PACKAGE__->has_many(
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:quDswVe6ApUm4cYVVijAEw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Bk/vLWpBjR3ZU0p1KN7KfA
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -50,8 +50,8 @@ __PACKAGE__->has_many(
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nDI28mE5gmZwDozOG/0fnw
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9xvvQg/H0oibycB6B45V5A
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -30,8 +30,8 @@ __PACKAGE__->has_many(
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SKZ/imJK1fjPbBEXde23Og
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3YMBhMqCjtpUjoTx4JLTOw
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -16,8 +16,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("system");
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 18:03:19
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/NVhmxcHU6YWCXDX9sO8mA
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SSKVFeg7ieeLJcF+s1uWWw
# You can replace this text with custom content, and it will be preserved on regeneration

View file

@ -0,0 +1,28 @@
package Hydra::Schema::Users;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Users");
__PACKAGE__->add_columns(
"username",
{ data_type => "text", is_nullable => 0, size => undef },
"fullname",
{ data_type => "text", is_nullable => 0, size => undef },
"emailaddress",
{ data_type => "text", is_nullable => 0, size => undef },
"password",
{ data_type => "text", is_nullable => 0, size => undef },
);
__PACKAGE__->set_primary_key("username");
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2008-11-26 20:02:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BgF6FK+9d7+cc72sp6pfCQ
# You can replace this text with custom content, and it will be preserved on regeneration
1;

View file

@ -17,7 +17,7 @@
<h2>Information</h2>
<table>
<table class="layoutTable">
<tr>
<th>Build ID:</th>
<td>[% build.id %]</td>

View file

@ -109,8 +109,12 @@
<li>
<div class="title">Admin</div>
<ul class="submenu">
[% INCLUDE makeLink uri = c.uri_for('/users') title = "Users" %]
[% INCLUDE makeLink uri = c.uri_for('/createproject') title = "Create a project" %]
[% IF c.user_exists %]
[% INCLUDE makeLink uri = c.uri_for('/logout') title = "Logout" %]
[% ELSE %]
[% INCLUDE makeLink uri = c.uri_for('/login') title = "Login" %]
[% END %]
[% INCLUDE makeLink uri = c.uri_for('/createproject') title = "Create project" %]
</ul>
</li>
</ul>
@ -121,6 +125,9 @@
<div id="footer">
<hr />
Generated on [% date.format %].
[% IF c.user_exists %]
You are logged in as <tt>[% c.user.username %]</tt>.
[% END %]
</div>
</div>

View file

@ -74,7 +74,7 @@
<h4>Information</h4>
<table>
<table class="layoutTable">
[% IF edit %]
<tr>
<th>Identifier:</th>
@ -148,7 +148,7 @@
<h2>General information</h2>
<table>
<table class="layoutTable">
[% IF edit %]
<tr>
<th>Identifier:</th>
@ -258,7 +258,7 @@
<h2>Statistics</h2>
<table>
<table class="layoutTable">
<tr>
<th>Finished builds:</th>
<td>[% finishedBuilds %]</td>

View file

@ -29,6 +29,10 @@ table {
margin-bottom: 1em;
}
.layoutTable td, .layoutTable th {
border-style: none;
}
th {
text-align: center;
font-weight: bold;

View file

@ -261,3 +261,11 @@ create table SystemTypes (
system text primary key not null,
maxConcurrent integer not null default 2
);
create table Users (
userName text primary key not null,
fullName text,
emailAddress text not null,
password text not null -- sha256 hash
);