domain listing

This commit is contained in:
Al Beano 2017-07-16 17:13:15 +01:00
parent 9fc3263944
commit 5024363f22
5 changed files with 88 additions and 3 deletions

View File

@ -1,5 +1,9 @@
package cyberman; package cyberman;
use Dancer2; use Dancer2;
use cyberman::Domains;
use Dancer2::Plugin::Database; use Dancer2::Plugin::Database;
use Digest::Bcrypt; use Digest::Bcrypt;
use Math::Random::Secure qw(rand irand); use Math::Random::Secure qw(rand irand);
@ -64,7 +68,10 @@ get qr{^/(index)?$} => sub {
if (!vars->{auth}) { if (!vars->{auth}) {
return template 'index'; return template 'index';
} }
return "well done, you logged in, nothing to see yet";
template 'redir' => {
"redir" => "domains",
};
}; };
post '/register' => sub { post '/register' => sub {
@ -171,8 +178,8 @@ post '/login' => sub {
cookie id => $user->{"id"}; cookie id => $user->{"id"};
cookie token => $token; cookie token => $token;
template redir => { template 'redir' => {
"redir" => "index", "redir" => "domains",
}; };
}; };

23
lib/cyberman/Domains.pm Normal file
View File

@ -0,0 +1,23 @@
package cyberman::Domains;
use Dancer2 appname => "cyberman";
use Dancer2::Plugin::Database;
get '/domains' => sub {
return template 'redir' => {
"redir" => "index",
} unless vars->{"auth"};
my @domains = database->quick_select(
"domain",
{
"ownerid" => vars->{"auth"},
},
);
template 'domains' => {
"domains" => \@domains,
}
};
true;

View File

@ -14,3 +14,10 @@ create table session (
since integer not null, since integer not null,
token text not null token text not null
); );
drop table if exists domain;
create table domain (
id integer primary key,
name string not null,
ownerid integer not null
)

45
views/domains.tt Normal file
View File

@ -0,0 +1,45 @@
<center>
<br />
<h1>Your Domains</h1>
<br />
</center>
<div class="body">
<% IF domains.size > 0 %>
<em>
<% domains.size %>
<% IF domains.size == 1 %>
domain
<% ELSE %>
domains
<% END %>
</em>
<br />
<table class="domains">
<tr>
<td>
<strong>Domain name</strong>
</td>
<td>
<strong>Actions</strong>
</td>
</tr>
<% FOREACH d IN domains %>
<tr>
<td>
<% d.name | html_entity %>.cyb
</td>
<td>
[&nbsp;<a class="bracketButton" href="domains/<% d.id %>/edit">edit</a>&nbsp;]
[&nbsp;<a class="bracketButton" href="domains/<% d.id %>/remove">remove</a>&nbsp;]
</td>
</tr>
<% END %>
</table>
<% ELSE %>
You don't have any domains registered.
<% END %>
</div>

View File

@ -37,6 +37,9 @@ a.bracketButton:hover {
form.login>table>tbody>tr>td>label { form.login>table>tbody>tr>td>label {
margin-right: 10px; margin-right: 10px;
} }
table.domains>tbody>tr>td:first-child>* {
margin-right: 2em;
}
.msgBox { .msgBox {
border: 1px solid white; border: 1px solid white;