Clean person refs and admin return url on logout.

master
Manager Bot 3 years ago
parent 13d7e5bc2a
commit a98a5c3583
  1. 4
      Web/lib/MJB/Web/Controller/Admin.pm
  2. 7
      Web/lib/MJB/Web/Controller/Auth.pm
  3. 1
      Web/templates/admin/blogs.html.ep
  4. 11
      Web/templates/admin/people.html.ep

@ -14,6 +14,7 @@ sub index ( $c ) {
# INPUT: # INPUT:
# uid | A user id # uid | A user id
# bid | A blog id belonging to the user # bid | A blog id belonging to the user
# url | A URL to return to when the admin logs out of the user account
# #
# When given a uid, become that user and go to the user's dashboard. # When given a uid, become that user and go to the user's dashboard.
# #
@ -21,10 +22,11 @@ sub index ( $c ) {
# and go to the blog's dashboard. # and go to the blog's dashboard.
# #
sub do_admin_become ( $c ) { sub do_admin_become ( $c ) {
my ( $uid, $bid ) = ( $c->param('uid'), $c->param('bid') ); my ( $uid, $bid, $url ) = ( $c->param('uid'), $c->param('bid'), $c->param('url') );
$c->session->{oid} = $c->stash->{person}->id; $c->session->{oid} = $c->stash->{person}->id;
$c->session->{uid} = $uid; $c->session->{uid} = $uid;
$c->session->{url} = $url if $url;
# If we have a blog id, then redirect to that blog's dashboard. # If we have a blog id, then redirect to that blog's dashboard.
# Otherwise, the normal dashboard.. # Otherwise, the normal dashboard..

@ -91,9 +91,14 @@ sub do_logout ( $c ) {
# When an admin has impersonated a user, they'll have their uid # When an admin has impersonated a user, they'll have their uid
# stored to oid. When they logout, they are logging out of the # stored to oid. When they logout, they are logging out of the
# impersonated user's account, back into their own account. # impersonated user's account, back into their own account.
# If a url is set in the session, the admin is returned to that page.
if ( $c->session->{oid} ) { if ( $c->session->{oid} ) {
$c->session->{uid} = delete $c->session->{oid}; $c->session->{uid} = delete $c->session->{oid};
$c->redirect_to( $c->url_for( 'show_admin' ) ); if ( $c->session->{url} ) {
$c->redirect_to( $c->url_for( delete $c->session->{url} ) );
} else {
$c->redirect_to( $c->url_for( 'show_admin' ) );
}
return; return;
} }

@ -45,6 +45,7 @@
<form style="margin-top: 1.5em; display: inline;" method="POST" action="<%= $c->url_for( 'do_admin_become' ) %>"> <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="uid" value="<%= $blog->person->id %>">
<input type="hidden" name="bid" value="<%= $blog->id %>"> <input type="hidden" name="bid" value="<%= $blog->id %>">
<input type="hidden" name="url" value="<%= $c->url_for %>">
<button type="submit" class="btn btn-sm btn-outline-danger">Manage Blog</button> <button type="submit" class="btn btn-sm btn-outline-danger">Manage Blog</button>
</form> </form>
</td> </td>

@ -36,14 +36,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
% for my $person ( @{$people} ) { % for my $user ( @{$people} ) {
<tr> <tr>
<td><a href="<%= $c->url_for( 'show_admin_person', { id => $person->id } ) %>"><%= $person->name %></a></td> <td><a href="<%= $c->url_for( 'show_admin_person', { id => $user->id } ) %>"><%= $user->name %></a></td>
<td><%= $person->email %></td> <td><%= $user->email %></td>
<td><%= $person->created_at->strftime( "%F" ) %></td> <td><%= $user->created_at->strftime( "%F" ) %></td>
<td> <td>
<form style="margin-top: 1.5em; display: inline;" method="POST" action="<%= $c->url_for( 'do_admin_become' ) %>"> <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 %>"> <input type="hidden" name="uid" value="<%= $user->id %>">
<input type="hidden" name="url" value="<%= $c->url_for %>">
<button type="submit" class="btn btn-sm btn-outline-danger">Login</button> <button type="submit" class="btn btn-sm btn-outline-danger">Login</button>
</form> </form>
</td> </td>

Loading…
Cancel
Save