diff --git a/lib/cyberman/Domains.pm b/lib/cyberman/Domains.pm index 5d4c8e7..ab5829c 100644 --- a/lib/cyberman/Domains.pm +++ b/lib/cyberman/Domains.pm @@ -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; diff --git a/views/domains.tt b/views/domains.tt index e1f57c5..d9645ce 100644 --- a/views/domains.tt +++ b/views/domains.tt @@ -5,6 +5,10 @@
+
+ [ Register a domain ] +
+ <% IF domains.size > 0 %> <% domains.size %> diff --git a/views/domains/new.tt b/views/domains/new.tt new file mode 100644 index 0000000..c74827b --- /dev/null +++ b/views/domains/new.tt @@ -0,0 +1,34 @@ +
+
+

Register a domain

+
+
+ +<% IF error %> +
+
+ <% 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 %> +
+

+
+<% END %> + +<%# TODO: a nice AJAX availability checker %> + +
+ Please choose a domain to register: +

+ + +