Implement domain removal

This commit is contained in:
Al Beano 2017-07-17 00:35:13 +01:00
parent 7d883ebd63
commit 9590e6bb78
4 changed files with 89 additions and 0 deletions

View File

@ -72,4 +72,46 @@ post '/domains/new' => sub {
};
};
get '/domains/:id/remove' => sub {
my $domain = database->quick_select(
"domain",
{
"id" => param("id"),
},
);
return auth_test($domain->{"ownerid"}) if auth_test($domain->{"ownerid"});
template 'domains/remove.tt' => {
"domain" => $domain,
};
};
post '/domains/:id/remove' => sub {
my $domain = database->quick_select(
"domain",
{
"id" => param("id"),
},
);
if (!$domain) {
# quick and dirty error that shouldn't really appear
return "No such domain!";
}
return auth_test($domain->{"ownerid"}) if auth_test($domain->{"ownerid"});
database->quick_delete(
"domain",
{
"id" => param("id"),
},
);
template redir => {
redir => "../../domains?removed=$domain->{name}",
};
};
true;

View File

@ -6,10 +6,19 @@ use Exporter qw(import);
our @EXPORT = qw(auth_test);
sub auth_test {
my $id = undef;
if (@_) {
$id = shift;
}
if (!vars->{"auth"}) {
return template 'redir' => {
"redir" => "/index",
};
} elsif ($id && vars->{"auth"} != $id) {
return template 'redir' => {
"redir" => "/index",
};
} else {
return 0; # nothing to be returned, route can continue
}

View File

@ -9,6 +9,12 @@
</div>
<br /><br />
<% END %>
<% IF params.removed %>
<div class="msgBox">
The domain '<% params.removed | html_entity %>.cyb' was removed successfully.
</div>
<br /><br />
<% END %>
</center>
<div class="body">

32
views/domains/remove.tt Normal file
View File

@ -0,0 +1,32 @@
<% IF domain %>
<center>
<br />
<h1>Removal of <% domain.name %>.cyb</h1>
<br />
</center>
<div class="body">
<p>
You are about to permanently remove <% domain.name %>.cyb and all its records.
</p>
<p style="font-size:1.6em">
YOU ARE ABOUT TO PERMANENTLY REMOVE <% domain.name %>.cyb AND ALL ITS RECORDS!
</p>
<p>
There is <strong>no</strong> guarantee that you will be able to re-register this domain at a later date.
</p>
<p>
<center>
<form method="POST">
[&nbsp;<button class="textButton" action="submit">yes,&nbsp;destroy&nbsp;the&nbsp;domain</button>&nbsp;]
</form>
</center>
</p>
</div>
<% ELSE %>
<center>
No such domain!
<br />
[&nbsp;<a href="../../domains" class="bracketButton">go&nbsp;back</a>&nbsp;]
</center>
<% END %>