diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm
index 2276e29..6a352d2 100644
--- a/Web/lib/MJB/Web.pm
+++ b/Web/lib/MJB/Web.pm
@@ -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' );
diff --git a/Web/lib/MJB/Web/Controller/Admin.pm b/Web/lib/MJB/Web/Controller/Admin.pm
index c64df23..bcf6e28 100644
--- a/Web/lib/MJB/Web/Controller/Admin.pm
+++ b/Web/lib/MJB/Web/Controller/Admin.pm
@@ -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 ];
}
diff --git a/Web/lib/MJB/Web/Controller/Auth.pm b/Web/lib/MJB/Web/Controller/Auth.pm
index cadeb3f..e70a261 100644
--- a/Web/lib/MJB/Web/Controller/Auth.pm
+++ b/Web/lib/MJB/Web/Controller/Auth.pm
@@ -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 ) { }
diff --git a/Web/templates/admin/blogs.html.ep b/Web/templates/admin/blogs.html.ep
index dbe2146..f1a7cb9 100644
--- a/Web/templates/admin/blogs.html.ep
+++ b/Web/templates/admin/blogs.html.ep
@@ -25,3 +25,31 @@
% }
+% if ( $blogs ) {
+
+% }
diff --git a/Web/templates/admin/people.html.ep b/Web/templates/admin/people.html.ep
index db1d7ee..61485d3 100644
--- a/Web/templates/admin/people.html.ep
+++ b/Web/templates/admin/people.html.ep
@@ -25,3 +25,31 @@
% }
+% if ( $people ) {
+
+
+
+ | Name |
+ Email Address |
+ Created |
+ Become User |
+
+
+
+ % for my $person ( @{$people} ) {
+
+ | <%= $person->name %> |
+ <%= $person->email %> |
+ <%= $person->created_at->strftime( "%F" ) %> |
+
+
+ |
+
+ % }
+
+
+% }
+