Better admin tools.

master
Manager Bot 3 years ago
parent c6754fd269
commit 83a6681e0a
  1. 1
      Web/lib/MJB/Web.pm
  2. 33
      Web/lib/MJB/Web/Controller/Admin.pm
  3. 13
      Web/lib/MJB/Web/Controller/Auth.pm
  4. 28
      Web/templates/admin/blogs.html.ep
  5. 28
      Web/templates/admin/people.html.ep

@ -188,6 +188,7 @@ sub startup ($self) {
# Admin Dashboard
$auth->get ( '/admin' )->to('Admin#index' )->name('show_admin' );
$auth->post( '/admin' )->to('Admin#do_admin_become' )->name('do_admin_become' );
$auth->get ( '/admin/people' )->to('Admin#people' )->name('show_admin_people' );
$auth->get ( '/admin/person/:id' )->to('Admin#person' )->name('show_admin_person' );
$auth->get ( '/admin/blogs' )->to('Admin#blogs' )->name('show_admin_blogs' );

@ -5,8 +5,38 @@ sub index ( $c ) {
}
sub people ( $c ) {
# POST /admin
#
# An admin may inpersonate any other user for technical support purposes,
# this code is called to become another user. Sign out to become your origional
# user again.
#
# INPUT:
# uid | A user id
# bid | A blog id belonging to the user
#
# When given a uid, become that user and go to the user's dashboard.
#
# When given a uid and a bid that the user owns, become that user
# and go to the blog's dashboard.
#
sub do_admin_become ( $c ) {
my ( $uid, $bid ) = ( $c->param('uid'), $c->param('bid') );
$c->session->{oid} = $c->stash->{person}->id;
$c->session->{uid} = $uid;
# If we have a blog id, then redirect to that blog's dashboard.
# Otherwise, the normal dashboard..
if ( $bid ) {
$c->redirect_to( $c->url_for( 'show_dashboard_blog', { id => $bid } ) );
} else {
$c->redirect_to( $c->url_for( 'show_dashboard' ) );
}
}
sub people ( $c ) {
my $people = $c->stash->{people} = [ $c->db->people->all ];
}
sub person ( $c ) {
@ -14,6 +44,7 @@ sub person ( $c ) {
}
sub blogs ( $c ) {
my $blogs = $c->stash->{blogs} = [ $c->db->blogs->all ];
}

@ -87,8 +87,19 @@ sub do_login ( $c ) {
}
sub do_logout ( $c ) {
# When an admin has impersonated a user, they'll have their uid
# stored to oid. When they logout, they are logging out of the
# impersonated user's account, back into their own account.
if ( $c->session->{oid} ) {
$c->session->{uid} = delete $c->session->{oid};
$c->redirect_to( $c->url_for( 'show_admin' ) );
return;
}
# Delete the session cookie and return them to the homepage.
undef $c->session->{uid};
$c->redirect_to( $c->url_for( 'show_login' ) );
$c->redirect_to( $c->url_for( 'show_homepage' ) );
}
sub show_forgot ( $c ) { }

@ -25,3 +25,31 @@
</div>
% }
% if ( $blogs ) {
<table style="border: 1px solid #ccc" class="table">
<tbody>
<tr>
<th class="text-nowrap">Domain</th>
<th class="text-nowrap">Owner</th>
<th class="text-nowrap">Created</th>
<th class="text-nowrap">User View</th>
</tr>
</thead>
<tbody>
% for my $blog ( @{$blogs} ) {
<tr>
<td><a target="_blank" href="https://<%= $blog->domain->name %>"><%= $blog->domain->name %></a></td>
<td><a href="<%= $c->url_for( 'show_admin_person', { id => $blog->person->id } ) %>"><%= $blog->person->name %></a></td>
<td><%= $blog->created_at->strftime( "%F %T" ) %></td>
<td>
<form style="margin-top: 1.5em; display: inline;" method="POST" action="<%= $c->url_for( 'do_admin_become' ) %>">
<input type="hidden" name="uid" value="<%= $blog->person->id %>">
<input type="hidden" name="bid" value="<%= $blog->id %>">
<button type="submit" class="btn btn-sm btn-outline-danger">Manage Blog</button>
</form>
</td>
</tr>
% }
</tbody>
</table>
% }

@ -25,3 +25,31 @@
</div>
% }
% if ( $people ) {
<table style="border: 1px solid #ccc" class="table">
<tbody>
<tr>
<th class="text-nowrap">Name</th>
<th class="text-nowrap">Email Address</th>
<th class="text-nowrap">Created</th>
<th class="text-nowrap">Become User</th>
</tr>
</thead>
<tbody>
% for my $person ( @{$people} ) {
<tr>
<td><a href="<%= $c->url_for( 'show_admin_person', { id => $person->id } ) %>"><%= $person->name %></a></td>
<td><%= $person->email %></td>
<td><%= $person->created_at->strftime( "%F" ) %></td>
<td>
<form style="margin-top: 1.5em; display: inline;" method="POST" action="<%= $c->url_for( 'do_admin_become' ) %>">
<input type="hidden" name="uid" value="<%= $person->id %>">
<button type="submit" class="btn btn-sm btn-outline-danger">Login</button>
</form>
</td>
</tr>
% }
</tbody>
</table>
% }

Loading…
Cancel
Save