Domain registration (excluding communication with nsd)

Domains are registered in the sqlite database but the information is not sent to nsd; nothing will really happen.
This commit is contained in:
Al Beano 2017-07-16 18:06:51 +01:00
parent 5024363f22
commit e3d00d0683
3 changed files with 89 additions and 0 deletions

View File

@ -20,4 +20,55 @@ get '/domains' => sub {
}
};
post '/domains/new' => sub {
my %errs;
if (!param("name")) {
$errs{"e_no_name"} = 1;
}
my $name = lc param("name");
if (scalar(keys(%errs)) == 0) {
if (param("name") !~ m/^[a-z0-9]([a-z0-9\-_]*[a-z0-9])?$/) {
$errs{"e_chars"} = 1;
}
}
if (scalar(keys(%errs)) == 0) {
my $result = database->quick_select(
"domain",
{
"name" => param("name"),
},
);
if ($result) {
$errs{"e_exists"} = 1;
}
}
if (scalar(keys(%errs)) != 0) {
return template 'domains/new' => {
params,
%errs,
error => 1,
};
}
# TODO: send domains to nsd
database->quick_insert(
"domain",
{
"name" => $name,
"ownerid" => vars->{"auth"},
},
);
template 'redir' => {
"redir" => "../domains",
};
};
true;

View File

@ -5,6 +5,10 @@
</center>
<div class="body">
<center>
[&nbsp;<a class="bracketButton" href="domains/new">Register a domain</a>&nbsp;]
</center>
<% IF domains.size > 0 %>
<em>
<% domains.size %>

34
views/domains/new.tt Normal file
View File

@ -0,0 +1,34 @@
<center>
<br />
<h1>Register a domain</h1>
<br />
</center>
<% IF error %>
<center>
<div class="msgBox">
<% IF e_no_name %>
You did not specify a domain to register.
<% END %>
<% IF e_exists %>
The domain '<% name | html_entity %>.cyb' has already been registered. Please choose a different domain name.
<% END %>
<% IF e_chars %>
The domain '<% name | html_entity %>.cyb' contains invalid characters. Domains must match the regular expression `^[a-z0-9]([a-z0-9\-_]*[a-z0-9])?$`.
<% END %>
</div>
<br /><br />
</center>
<% END %>
<%# TODO: a nice AJAX availability checker %>
<div class="body">
Please choose a domain to register:
<br /><br />
<form method="POST" class="login">
<input type="text" name="name">.cyb
<button action="submit" style="margin-left:20px">Register domain</button>
</form>
</div>