From c4f54bfd0d7e3f0b9c3e64fbbb4d2b89cb8eeda7 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Tue, 21 Jan 2014 20:06:10 +0100 Subject: [PATCH] renommage des pages --- www/lib/DNSManager.pm | 202 +++++++++++++++++++----------------- www/views/administration.tt | 9 ++ www/views/details.tt | 18 +++- www/views/home.tt | 50 +++++++++ www/views/index.tt | 17 +-- www/views/mapage.tt | 37 ------- 6 files changed, 188 insertions(+), 145 deletions(-) create mode 100644 www/views/home.tt delete mode 100644 www/views/mapage.tt diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index 6214e94..193e9a6 100644 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -54,38 +54,9 @@ get '/' => sub { } }; -post '/login' => sub { - # Check if user is already logged - unless ( session('login') ) - { - # Check user login and password - if ( param('login') && param('password') ) - { - my $app = initco(); - my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), - param('password') ); - if( $auth_ok ) - { +get '/home' => sub { - session login => param('login'); - # TODO : change password storage… - session password => param('password'); - session user => freeze( $user ); - session admin => $isadmin; - - } - else - { - # User login and/or password are incorrect - } - } - } - redirect '/'; -}; - - -get '/mapage' => sub { unless( session('login') ) { redirect '/'; @@ -98,7 +69,7 @@ get '/mapage' => sub { my @d = @{$app->get_domains( session('login') )}; - template mapage => { + template home => { login => session('login') , domains => $app->get_domains(session('login')) , zones_domains => \%domains @@ -108,53 +79,85 @@ get '/mapage' => sub { } }; -any ['post', 'get'] => '/domainupdate/:domain' => sub { +prefix '/domain' => sub { - # check if user is logged & if domain parameter is set - unless( session('login') && param('domain')) - { - redirect '/'; - } - else - { + any ['post', 'get'] => '/update/:domain' => sub { + + # check if user is logged & if domain parameter is set + unless( session('login') && param('domain')) + { + redirect '/'; + } + else + { + my $app = initco(); + my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + param('password') ); + + $app->update_domain_raw(session('login') + , param('zoneupdated') + , param('domain')); + + redirect '/domain/details/' . param('domain'); + } + + }; + + get '/details/:domain' => sub { + + # check if user is logged & if domain parameter is set + unless( session('login') && param('domain')) + { + redirect '/'; + } + else + { + my $app = initco(); + my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + param('password') ); + + my $zone = $app->get_domain(session('login') , param('domain')); + + template details => { + login => session('login') + , domain => param('domain') + , domain_zone => $zone->output() }; + + } + + }; + + post '/add/' => sub { + + # check if user is logged & if domain parameter is set + unless( session('login') && param('domain')) + { + redirect '/'; + } + else + { + + my $app = initco(); + $app->add_domain( session('login'), param('domain') ); + redirect '/home'; + + } + + }; + + get '/del/:domain' => sub { + + # TODO tests des droits my $app = initco(); - my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), - param('password') ); + $app->delete_domain(session('login'), param('domain')); + redirect '/home'; - $app->update_domain_raw(session('login') - , param('zoneupdated') - , param('domain')); + }; - redirect '/mapage'; - } }; -get '/details/:domain' => sub { - - # check if user is logged & if domain parameter is set - unless( session('login') && param('domain')) - { - redirect '/'; - } - else - { - my $app = initco(); - my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), - param('password') ); - - my $zone = $app->get_domain(session('login') , param('domain')); - - template details => { - login => session('login') - , domain => param('domain') - , domain_zone => $zone->output() }; - - } - -}; - -any ['get', 'post'] => '/administration' => sub { +any ['get', 'post'] => '/admin' => sub { unless( session('login') ) { redirect '/'; @@ -167,37 +170,44 @@ any ['get', 'post'] => '/administration' => sub { } }; -any ['post', 'get'] => '/logout' => sub { - session->destroy; - redirect '/'; -}; +prefix '/user' => sub { -get '/domainadd' => sub { - # check if user is logged & if domain parameter is set - unless( session('login') ) - { + get '/logout' => sub { + session->destroy; redirect '/'; - } - else - { + }; - my $app = initco(); + post '/login' => sub { - if( param('domain') ) + # Check if user is already logged + unless ( session('login') ) { - # create domain - $app->add_domain( session('login'), param('domain') ); - # Then, redirect to mapage - redirect '/mapage'; + # Check user login and password + if ( param('login') && param('password') ) + { + + my $app = initco(); + my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), + param('password') ); + if( $auth_ok ) + { + + session login => param('login'); + # TODO : change password storage… + session password => param('password'); + session user => freeze( $user ); + session admin => $isadmin; + + } + else + { + # User login and/or password are incorrect + } + } } - } + redirect '/home'; + + }; }; - -get qr{/domaindel/(.*)} => sub { - my ($domainToDelete) = splat; - my $app = initco(); - $app->delete_domain(session('login'), $domainToDelete); - redirect '/mapage'; -} diff --git a/www/views/administration.tt b/www/views/administration.tt index acfc35f..6e98d76 100644 --- a/www/views/administration.tt +++ b/www/views/administration.tt @@ -1,5 +1,14 @@
diff --git a/www/views/details.tt b/www/views/details.tt index f049e86..bc9b02e 100644 --- a/www/views/details.tt +++ b/www/views/details.tt @@ -1,19 +1,27 @@

Fichier de zone de <% domain %>

-
+
diff --git a/www/views/home.tt b/www/views/home.tt new file mode 100644 index 0000000..6de350c --- /dev/null +++ b/www/views/home.tt @@ -0,0 +1,50 @@ + + +
+ +<% IF domains && domains.size %> +

Vos domaines :

+
+ + + <% FOREACH domain in domains %> + + + + + + <% END %> +
+ <%domain%> + + Supprimer +
+ +
+ +<% ELSE %> + Vous n'avez pas encore de noms de domaines… réservez-en un ! \o/ +<% END %> + +

Ajouter un nouveau domaine.

+ + + + + + +
diff --git a/www/views/index.tt b/www/views/index.tt index 628091b..ed323ad 100644 --- a/www/views/index.tt +++ b/www/views/index.tt @@ -1,14 +1,16 @@