Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

renommage des pages

master
Philippe Pittoli 2014-01-21 20:06:10 +01:00
parent f45b7afc4c
commit c4f54bfd0d
6 changed files with 188 additions and 145 deletions

View File

@ -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';
}

View File

@ -1,5 +1,14 @@
<div id="sidebar">
Welcome <% login %> !
<a href="/user/logout">Déconnexion</a>
<br />
<a href='/admin'>Page d'administration</a>
<br />
<a href='/'>Accueil</a>
</div>
<div id="page">

View File

@ -1,19 +1,27 @@
<div id="sidebar">
Welcome <% login %> !
<form action='logout' method="post" accept-charset="utf-8">
<input type="submit" name="logout" value="Déconnexion">
</form>
<br />
<a href="/user/logout">Déconnexion</a>
<br />
<a href="/home">Ma page</a>
<br />
<% IF admin == 1 %>
<a href='administration'>Page d'administration</a>
<a href='/admin'>Page d'administration</a>
<br />
<% END %>
<a href='/'>Accueil</a>
</div>
<div id="page">
<h3>Fichier de zone de <% domain %></h3>
<form action='/domainupdate/<% domain %>' method="post" >
<form action='/domain/update/<% domain %>' method="post" >
<label for='zone'>Votre zone :</label>
<br />
<textarea id='zone' name="zoneupdated" rows="20" cols="100"><% domain_zone %></textarea>

50
www/views/home.tt Normal file
View File

@ -0,0 +1,50 @@
<div id="sidebar">
Welcome <% login %> !
<br />
<a href="/user/logout">Déconnexion</a>
<br />
<% IF admin == 1 %>
<a href='/admin'>Page d'administration</a>
<br />
<% END %>
<a href='/'>Accueil</a>
</div>
<div id="page">
<% IF domains && domains.size %>
<h3>Vos domaines :</h3>
<br />
<table>
<% FOREACH domain in domains %>
<tr>
<td>
<a href="/domain/details/<%domain%>" ><%domain%></a>
</td>
<td>
<a href="/domain/del/<%domain%>">Supprimer</a>
</td>
</tr>
<% END %>
</table>
<br/>
<% ELSE %>
Vous n'avez pas encore de noms de domaines… réservez-en un ! \o/
<% END %>
<h3>Ajouter un nouveau domaine.</h3>
<form action='/domain/add/' method="post" >
<input type='text' name='domain'/>
<input type='submit' name='submit'/>
</form>
</div>

View File

@ -1,14 +1,16 @@
<div id="sidebar">
<% IF logged == 1 %>
Welcome <% login %> !
<form action='logout' method="get" accept-charset="utf-8">
<input type="submit" name="logout" value="Déconnexion">
</form>
<a href='mapage'>Votre page de configuration</a><br />
Welcome <% login %> !
<br />
<a href="/user/logout">Déconnexion</a>
<br />
<a href='/home'>Votre page de configuration</a><br />
<% IF admin == 1 %>
<a href='administration'>Page d'administration</a><br />
<a href='/admin'>Page d'administration</a>
<br />
<% END %>
<% IF domains %>
@ -19,9 +21,10 @@
<% END %>
<% ELSE %>
<form action="login" method="post" accept-charset="utf-8">
<form action="/user/login" method="post" accept-charset="utf-8">
<label for="login">Votre login : </label>
<input type="text" name="login" value="" />
<label for="password">Votre mot de passe : </label>
<input type="password" name="password" value="" />
<p><input type="submit" value="Connexion &rarr;" /></p>

View File

@ -1,37 +0,0 @@
<div id="sidebar">
Welcome <% login %> !
<form action='logout' method="get" accept-charset="utf-8">
<input type="submit" name="logout" value="Déconnexion">
</form>
<% IF admin == 1 %>
<a href='administration'>Page d'administration</a>
<% END %>
<a href='/'>Accueil</a>
</div>
<div id="page">
<% IF domains && domains.size %>
<h3>Vos domaines :</h3>
<br />
<table>
<% FOREACH domain in domains %>
<tr>
<td>
<a href="details/<%domain%>" ><%domain%></a>
</td>
<td>
<a href="domaindel/<%domain%>">Supprimer</a>
</td>
</tr>
<% END %>
</table>
<br/>
<% ELSE %>
Vous n'avez pas encore de noms de domaines… Voulez-vous en réserver un ?
<% END %>
<h3>Ajouter un nouveau domaine.</h3>
<form action='domainadd'>
<input type='text' name='domain'/>
<input type='submit' name='submit'/>
</form>
</div>