Apache2-WebApp-Extra-Admin
view release on metacpan or search on metacpan
usr/share/webapp-toolkit/extra/class/admin_users.tt view on Meta::CPAN
open (OUTFILE, ">$htpasswd") or die $self->SUPER::_error($c, "Cannot open $htpasswd: $!");
foreach (@lines) {
chomp;
next if ($username eq 'admin');
if (/^(?:|\#)$username/i) {
if (/^#/) {
s/^#(\w+)/$1/gi;
}
else {
s/^(\w+)/\#$1/gi;
}
}
print OUTFILE "$_\n";
}
close(OUTFILE);
$self->SUPER::_log_action($c, "Changed Status to '$value' ($username)");
# list the users
$self->_list_users($c);
}
#----------------------------------------------------------------------------+
# _get_htpasswd_data(\%controller)
#
# Return the htpasswd user list as a reference to an array.
sub _get_htpasswd_data {
my ($self, $c) = @_;
my $htpasswd = $c->config->{apache_doc_root} . '/conf/htpasswd';
open (FILE, $htpasswd) or die $self->ERROR::_error($c, "Cannot open $htpasswd: $!");
my @lines = <FILE>;
close(FILE);
my @results;
foreach (@lines) {
chomp;
my ($user, $pass, $epoch) = split(/\:/);
my $status;
if ($user =~ /^#/) {
$status = 'Disabled';
$user =~ s/^#//;
}
else {
$status = 'Active';
}
$epoch ||= 110790000; # default
push( @results, {
username => $user,
status => $status,
created => $c->plugin('DateTime')->format_time($epoch, '%m-%d-%Y / %R %p'),
});
}
return \@results;
}
1;
__END__
=head1 NAME
[% project_title %]::Admin::Users - Web based admin control panel module
=head1 SYNOPSIS
use [% project_title %]::Admin::Users;
=head1 DESCRIPTION
Base class module that is used to manage admin control panel users.
=head1 OBJECT METHODS
=head2 _list_users
List the htpasswd users.
$self->_list_users(\%controller);
=head2 _get_htpasswd_data
Return the htpasswd user list as a reference to an array.
$self->_get_htpasswd_data(\%controller);
=head2 URI DISPATCHABLE
=head2 delete
Delete the user from the htpasswd file.
http://domain.com/app/admin/users/delete
=head2 status
Change the user status.
http://domain.com/app/admin/users/status
=head1 SEE ALSO
L<Apache2::WebApp>, L<Apache2::WebApp::Admin>, L<Apache2::WebApp::Plugin::DBI>,
L<Apache::Htpasswd>
=head1 AUTHOR
Marc S. Brooks, E<lt>mbrooks@cpan.orgE<gt> L<http://mbrooks.info>
=head1 COPYRIGHT
( run in 0.885 second using v1.01-cache-2.11-cpan-39bf76dae61 )