Skip to content

Commit

Permalink
Merge branch 'master' of github.com:davorg/kinza
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Sep 7, 2014
2 parents 917203a + f3d4605 commit 37a3299
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
54 changes: 52 additions & 2 deletions Kinza/lib/Kinza.pm
Expand Up @@ -3,6 +3,7 @@ use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Email;
use Dancer::Plugin::Passphrase;
use DateTime;

our $VERSION = '0.1';

Expand All @@ -19,6 +20,9 @@ my $course_rs = schema()->resultset('Course');
my $pres_rs = schema()->resultset('Presentation');
my $pass_rs = schema()->resultset('PasswordReset');

my $now = DateTime->now(time_zone => 'Europe/London');
my $live = '2014-09-04T12:45';

my %private = map { $_ => 1 } qw[/submit];

hook before => sub {
Expand All @@ -33,8 +37,10 @@ hook before_template => sub {
$params->{email} = session('email');
};


get '/' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $error = session('error');
session 'error' => undef;
my $choices = session('choices');
Expand All @@ -61,6 +67,9 @@ get '/' => sub {
};

post '/save' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my %params = params;

session 'choices' => { reverse %params };
Expand Down Expand Up @@ -138,7 +147,18 @@ EO_EMAIL
template 'saved', { student => $student };
};

get '/dummies' => sub {
my @students = $student_rs->search({
verify => { '!=' => undef },
});

template 'dummies', { students => \@students };
};

get '/register' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $error = session('error');
session 'error' => undef;
template 'register', {
Expand All @@ -147,7 +167,10 @@ get '/register' => sub {
};

post '/register' => sub {
unless (param('email')
if ($now le $live) {
return template 'comingsoon';
}
unless (param('name') and param('email')
and param('password') and param('password2')) {
session 'error' => 'You must fill in all values';
return redirect '/register';
Expand Down Expand Up @@ -184,6 +207,9 @@ post '/register' => sub {
};

get '/verify/:code' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $code = param('code');

my $student = $student_rs->find({
Expand All @@ -202,6 +228,9 @@ get '/verify/:code' => sub {
};

get '/resend' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $student = $student_rs->find({
email => session('email'),
});
Expand All @@ -214,6 +243,9 @@ get '/resend' => sub {
};

post '/resend' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $student = $student_rs->find({
email => session('email'),
});
Expand All @@ -235,12 +267,18 @@ post '/resend' => sub {
};

get '/login' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $error = session('error');
session 'error' => undef;
template 'login', { error => $error };
};

post '/login' => sub {
if ($now le $live) {
return template 'comingsoon';
}
session 'email' => undef;
session 'name' => undef;

Expand Down Expand Up @@ -280,12 +318,18 @@ get '/logout' => sub {
};

get '/password' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $error = session('error');
session 'error' => undef;
template 'password', { error => $error };
};

post '/password' => sub {
if ($now le $live) {
return template 'comingsoon';
}
unless (params->{email}) {
session 'error' => 'You must give an email address';
return redirect '/password';
Expand Down Expand Up @@ -331,6 +375,9 @@ EO_EMAIL
};

get '/passreset/:code' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $code = param('code');
my $ps = schema->resultset('PasswordReset')->find({
code => $code,
Expand All @@ -346,6 +393,9 @@ get '/passreset/:code' => sub {
};

post '/passreset' => sub {
if ($now le $live) {
return template 'comingsoon';
}
my $code = session('code');

unless ($code) {
Expand Down
2 changes: 2 additions & 0 deletions Kinza/views/comingsoon.tt
@@ -0,0 +1,2 @@
<h1>SCHS Kinza 2014/15</h1>
<p>Please come back later to register.</p>
14 changes: 14 additions & 0 deletions Kinza/views/dummies.tt
@@ -0,0 +1,14 @@
<h1>Unverified Users</h1>
<p>The following users are currently unverified:</p>
<table class="table table-striped table-bordered table-hover table-condensed">
<thead>
<th>#</th>
<th>Name</th>
<th>Email</th>
</thead>
[% FOREACH s IN students -%]
<tr>
<td>[% loop.count %]</td><td>[% s.name %]</td><td>[% s.email %]</td>
</tr>
[% END -%]
</table>

0 comments on commit 37a3299

Please sign in to comment.