Permalink
Browse files

Adding user management basics. Very basic. Well, not really doing muc…

…h at all really...
  • Loading branch information...
1 parent 06c11c9 commit 01d7f65fb9e3dc809dba503bcbbc1e649a9e0d59 @idnorton idnorton committed Dec 14, 2011
Showing with 163 additions and 0 deletions.
  1. +59 −0 lib/PresentingPerl/Web/Controller/Admin/Users.pm
  2. +72 −0 root/admin/users/edit.tt
  3. +32 −0 root/admin/users/root.tt
@@ -0,0 +1,59 @@
+package PresentingPerl::Web::Controller::Admin::Users;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller::ActionRole' }
+
+
+sub edit :Path :Args(1) : Local Does('NeedsLogin') {
+ my ($self, $c, $user_id) = @_;
+
+ unless($c->user->get_object->has_role('admin')) {
+ $c->redirect('/login');
+ }
+
+ # Stash user details
+ $c->stash->{ user } = $c->model( 'DB::User' )->find({
+ id => $user_id,
+ });
+
+ # Stash the list of roles
+ my @roles = $c->model( 'DB::Role' )->search;
+ $c->stash->{ roles } = \@roles;
+}
+
+
+
+
+
+
+
+
+
+
+
+sub root :Path :Args(0) : Local Does('NeedsLogin') {
+ my ($self, $c) = @_;
+
+ unless($c->user->get_object->has_role('admin')) {
+ $c->redirect('/login');
+ }
+
+ # Stash the list of users
+ my @users = $c->model( 'DB::User' )->search(
+ {},
+ {
+ order_by => 'username',
+ },
+ );
+
+ $c->stash->{ users } = \@users;
+}
+
+
+
+
+__PACKAGE__->meta->make_immutable;
+
+1;
View
@@ -0,0 +1,72 @@
+[%- meta.wrapper = 'shinycms.tt';
+ IF user.id;
+ meta.title = 'Edit user';
+ ELSE;
+ meta.title = 'Add new user';
+ END;
+-%]
+
+<h2>
+ [%- IF user.id %]
+ Edit details for [% user.username | html %]
+ [%- ELSE %]
+ Add new user
+ [%- END %]
+</h2>
+
+<form id="edit_user" method="post" enctype="multipart/form-data" action="[% c.uri_for('edit-do') %]">
+ [%- UNLESS user.id %]
+ <p>
+ <label for="username">
+ Username
+ </label>
+ <br /><input type="text" class="textlong" id="username" name="username" value="[% user.username | html %]" size="50" maxlength="50" />
+ </p>
+ <p>
+ <label for="password">
+ Password
+ </label>
+ <br /><input type="password" class="textlong" id="password" name="password" size="50" maxlength="200" />
+ </p>
+ [%- END %]
+ <p>
+ <label for="email_address">
+ Email
+ </label>
+ <br /><input type="text" class="textlong" id="email_address" name="email_address" value="[% user.email_address | html %]" size="50" maxlength="200" />
+ </p>
+ <p>
+ <label for="first_name">
+ First name
+ </label>
+ <br /><input type="text" class="textshort" id="first_name" name="first_name" value="[% user.first_name | html %]" size="50" />
+ </p>
+ <p>
+ <label for="last_name">
+ Last name
+ </label>
+ <br /><input type="text" class="textshort" id="last_name" name="last_name" value="[% user.last_name | html %]" size="50" />
+ </p>
+ <p>
+ <label for="active">
+ Account active
+ </label>
+ <br /><input type="checkbox" id="active" name="active" [% IF user.active == 1 %] checked="checked" [%- END %] />
+ </p>
+ [%- IF c.user.has_role( 'User Admin' ) %]
+ <p>
+ <span class="label">Roles</span>
+ [%- FOREACH role IN roles %]
+ <br /><input id="role_[% role.id %]" name="role_[% role.id %]" type="checkbox"[% IF user.has_role(role.role) %] checked="checked"[% END %] /> <label for="role_[% role.id %]">[% role.role | html %]</label>
+ [%- END %]
+ </p>
+ [%- END %]
+ <p>
+ <input name="user_id" type="hidden" value="[% user.id %]" />
+ <input name="submit" type="submit" value="Save" />
+ <input name="reset" type="reset" value="Reset" />
+ [%- IF user.id %]
+ <input name="delete" type="submit" value="Delete" onclick="javascript:return confirm('Are you sure you want to delete this user?')" />
+ [%- END %]
+ </p>
+</form>
View
@@ -0,0 +1,32 @@
+[%- meta.wrapper = 'shinycms.tt';
+ meta.title = 'Users';
+-%]
+<table class="list">
+ <tr>
+ <th>
+ Username
+ </th>
+ <th>
+ Name
+ </th>
+ <th>
+ Actions
+ </th>
+ </tr>
+ [%- FOREACH user IN users %]
+ <tr onmouseover="style.backgroundColor='#eeffdd';" onmouseout="style.backgroundColor='transparent'">
+ <td>
+ [% user.username | html %]
+ </td>
+ <td>
+ [% user.first_name | html %] [% user.last_name | html %]
+ </td>
+ <td>
+ <a href="[% c.uri_for( 'view', user.id ) %]">View</a> /
+ <a href="[% c.uri_for( 'edit', user.id ) %]">Edit</a> /
+ <a href="[% c.uri_for( 'password', user.id ) %]">Change password</a>
+ </td>
+ </tr>
+ [%- END %]
+</table>
+

0 comments on commit 01d7f65

Please sign in to comment.