Catalyst-Plugin-Authorization-Abilities
view release on metacpan or search on metacpan
t/lib/MyApp/Controller/Admin/User.pm view on Meta::CPAN
sub index :Path Args(0) {
my ( $self, $c ) = @_;
$c->res->redirect('/admin/user/list');
$c->detach;
}
=head2 list
List all users
=cut
sub base_user : Chained('/') :PathPart('admin/user') : CaptureArgs(0) {
my ( $self, $c ) = @_;
# Save rs of users
$c->stash->{users} = $c->model('DBIC::User');
}
=head2 user
used to chained action
=cut
sub user : Chained('/') :PathPart('admin/user') : CaptureArgs(1){
my ( $self, $c, $id ) = @_;
# Save id of user
$c->stash->{user_id} = $id;
$c->stash->{user} = $c->model('DBIC::User')->find({ id => $id });
}
=head2 list_user
List all users
=cut
sub list_user : Chained('base_user') :PathPart('list') Args(0){
my ( $self, $c ) = @_;
}
=head2 view_user
View a user
=cut
sub view_user : Chained('user') :PathPart('view') Args(0){
my ( $self, $c ) = @_;
}
=head2 add_user
add a user
=cut
sub add_user : Chained('base_user') :PathPart('add') Args(0) {
my ( $self, $c ) = @_;
$c->stash->{legend} = "Add_a_user";
$c->forward('edit_user');
}
=head2 del_user
delete a user
=cut
sub del_user : Chained('user') :PathPart('del') Args(0){
my ( $self, $c ) = @_;
$c->stash->{user}->delete;
$c->res->redirect('/admin/user/list');
$c->detach;
}
=head2 edit_user
edit a user
=cut
sub edit_user : Chained('user') :PathPart('edit') Args(0){
my ( $self, $c ) = @_;
if ($c->stash->{user_id} ){
$c->stash->{legend} = "Edit_a_user";
my $user_roles_id;
foreach my $role ( $c->stash->{user}->user_roles ){
$user_roles_id->{$role->id} = 1;
}
$c->stash->{user_roles_id} = $user_roles_id;
my $user_actions_id;
foreach my $action ( $c->stash->{user}->actions ){
$user_actions_id->{$action->id} = 1;
}
$c->stash->{user_actions_id} = $user_actions_id;
}
$c->stash->{allroles} = $c->model('DBIC::Role');
$c->stash->{allactions} = $c->model('DBIC::Action');
# form FormFu ------------------------------------
my $form = HTML::FormFu->new;
my $fs = $form->element('Fieldset')->legend($c->stash->{legend})->attrs({ class => 'alt'});
$fs->element(
{type => 'Text',
name => 'name',
label => 'Name',
constraint => ['Required'],
});
$fs->element(
{type => 'Text',
name => 'username',
label => 'Login',
constraint => ['Required'],
});
$fs->element(
{type => 'Password',
name => 'password',
label => 'Password',
});
$fs->element(
{type => 'Text',
name => 'email',
label => 'Email',
constraint => ['Required', 'Email' ],
});
$fs->element(
{type => 'Select',
name => 'active',
label => 'Status',
options => [
[ 1 => 'active' ],
[ 0 => 'noactive' ] ],
});
$fs->element(
{type => 'Submit',
name => 'submit',
value => 'Save',
attributes => {
class => 'positive',
},
});
$form->process($c->request);
$c->stash->{form} = $form;
if ( $form->submitted_and_valid ) {
my $user = $c->model('DBIC::User')->update_or_create({
id => $c->stash->{user_id},
name => $c->req->params->{'name'},
username => $c->req->params->{'username'},
password => $c->req->params->{'password'},
email => $c->req->params->{'email'},
( run in 0.563 second using v1.01-cache-2.11-cpan-5a3173703d6 )