3
0

visualisation des users (pour suppr / passage admin), rendu

This commit is contained in:
Philippe Pittoli 2014-01-23 21:30:52 +01:00
parent 88d78b00b1
commit b729f6fc8e
6 changed files with 154 additions and 10 deletions

View File

@ -55,10 +55,9 @@ sub register_user {
${$self->um}->register_user($login, $passwd);
}
# TODO
sub set_admin {
my ($self, $login) = @_;
${$self->um}->set_admin($login);
my ($self, $login, $val) = @_;
${$self->um}->set_admin($login, $val);
}
sub update_passwd {
@ -131,6 +130,12 @@ sub get_all_domains {
${$self->um}->get_all_domains;
}
sub get_all_users {
my ($self) = @_;
# % login admin
${$self->um}->get_all_users;
}
sub new_tmp {
my ($self, $login, $domain) = @_;
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);

View File

@ -153,7 +153,7 @@ sub get_domains {
sub get_all_domains {
my ($self) = @_;
my ($sth, $user, %domains);
my ($sth, %domains);
$sth = $self->dbh->prepare('SELECT domain, login FROM domain');
unless ( $sth->execute()) {
@ -169,4 +169,35 @@ sub get_all_domains {
%domains;
}
sub get_all_users {
my ($self) = @_;
my ($sth, %users);
$sth = $self->dbh->prepare('SELECT login, admin FROM user');
unless ( $sth->execute()) {
$sth->finish();
undef;
}
while( my $ref = $sth->fetchrow_arrayref) {
$users{@$ref[0]} = @$ref[1];
}
$sth->finish();
%users;
}
sub set_admin {
my ($self, $login, $val) = @_;
my $sth = $self->dbh->prepare('update user set admin=? where login=?');
unless ( $sth->execute( $val, $login) ) {
$sth->finish();
return 0;
}
$sth->finish();
return 1;
}
1;

View File

@ -234,13 +234,15 @@ any ['get', 'post'] => '/admin' => sub {
else {
my %alldomains = $app->get_all_domains;
my %allusers = $app->get_all_users;
my ($success, @domains) = $app->get_domains( session('login') );
template administration => {
login => session('login')
, admin => session('admin')
, domains => [ @domains ]
, alldomains => { %alldomains } };
, alldomains => { %alldomains }
, allusers => { %allusers } };
}
}
};
@ -287,6 +289,69 @@ prefix '/user' => sub {
};
}
};
get '/unsetadmin/:user' => sub {
unless( defined param('user') )
{
# TODO ajouter une erreur à afficher
redirect request->referer;
}
elsif(! defined session('login') )
{
redirect '/';
}
else {
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 0);
}
redirect request->referer;
}
};
get '/setadmin/:user' => sub {
unless( defined param('user') )
{
# TODO ajouter une erreur à afficher
redirect request->referer;
}
elsif(! defined session('login') )
{
redirect '/';
}
else {
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(session('login'),
session('password') );
if ( $auth_ok && $isadmin ) {
$app->set_admin(param('user'), 1);
}
redirect request->referer;
}
};

View File

@ -20,11 +20,43 @@
<td><% pair.value %></td>
<td>
<a href="/domain/del/<% pair.key %>">sup. domaine</a>
<a href="/domain/del/<% pair.key %>"><button type="button" class="btn btn-danger">Supprimer le domaine</button></a>
</td>
<td>
<a href="/user/del/<% pair.value %>">sup. utilisateur</a>
<a href="/user/del/<% pair.value %>"><button type="button" class="btn btn-danger">Supprimer l'utilisateur</button></a>
</td>
</tr>
<% END %>
</table>
</div>
<div id="utilisateurs">
<h3>Utilisateurs enregistrés</h3>
<table class="table" >
<tr>
<th>utilisateur</th>
<th>supprimer</th>
<th>administrateur</th>
</tr>
<% FOREACH pair IN allusers.pairs %>
<tr>
<td><% pair.key %></td>
<td>
<a href="/user/del/<% pair.key %>"><button type="button" class="btn btn-danger">Supprimer l'utilisateur</button></a>
</td>
<td>
<% IF pair.value == 1 %>
<a href="/user/unsetadmin/<% pair.key %>"><button type="button" class="btn btn-danger">Passer utilisateur</button></a>
<% ELSE %>
<a href="/user/setadmin/<% pair.key %>"><button type="button" class="btn btn-primary">Passer administrateur</button></a>
<% END %>
</td>
</tr>

View File

@ -23,12 +23,14 @@
<table class="table">
<% FOREACH domain in domains %>
<tr>
<td><% domain %></td>
<td>
<a href="/domain/details/<% domain %>" ><% domain %></a>
<a href="/domain/details/<% domain %>" ><button type="button" class="btn btn-primary">Détails</button></a>
</td>
<td>
<a href="/domain/del/<% domain %>">Supprimer</a>
<a href="/domain/del/<% domain %>" ><button type="button" class="btn btn-danger">Supprimer</button></a>
</td>
</tr>
<% END %>

View File

@ -5,11 +5,20 @@
<% errmsg %> <br />
<form action='/user/add/' method="post" >
<h3>S'enregistrer</h3>
<hr />
<form class="form" action='/user/add/' method="post" >
<label for='login'>login : </label>
<input type='text' name='login' id='login' />
<br />
<label for='password'>password : </label>
<input type='password' name='password' id='password' />
<br />
<label for='password2'>password (pour être sûr): </label>
<input type='password' name='password2' id='password2' />
<input type='submit' name='submit'/>
</form>