package App::EzPz::User;
-use Authen::Htpasswd::User;
+use Module::Runtime qw(use_module);
use Moo;
has _htpasswd_user => (
handles => [ qw(username password check_password) ],
);
+has ezmlm_bindir => (is => 'rwp');
+
around BUILDARGS => sub {
my ($orig, $self) = (shift, shift);
my $args = $self->$orig(@_);
$args->{htpasswd_user} ||=
- Authen::Htpasswd::User->new(
+ use_module('Authen::Htpasswd::User')->new(
delete @{$args}{qw(username password)}
);
return $args
};
+sub list_names {
+ my ($self) = @_;
+ if (my $unsplit = ($self->_htpasswd_user->extra_info||[])->[0]) {
+ return split /\s*,\s*/, $unsplit;
+ } else {
+ return ();
+ }
+}
+
+sub set_list_names {
+ my ($self, @names) = @_;
+ my @extra = @{$self->_htpasswd_user->extra_info||[]};
+ $extra[0] = join(', ', @names);
+ $self->_htpasswd_user->extra_info(@extra);
+ return;
+}
+
+sub add_list_name {
+ my ($self, $name) = @_;
+ my %names; @names{my @names = $self->list_names} = ();
+ $self->set_list_names(@names, $name) unless exists $names{$name};
+ return $name;
+}
+
+sub remove_list_name {
+ my ($self, $name) = @_;
+ my %names; @names{my @names = $self->list_names} = ();
+ if (exists $names{$name}) {
+ $self->set_list_names(grep !($_ eq $name), $self->list_names)
+ }
+ return $name;
+}
+
1;
package App::EzPz::UserStore;
-use App::EzPz::User;
+use Module::Runtime qw(use_module);
use Scalar::Util 'blessed';
-use Authen::Htpasswd;
use Moo;
has ezmlm_bindir => (is => 'ro', required => 1);
sub _build__htpasswd {
my ($self) = @_;
- return Authen::Htpasswd->new($self->htpasswd_file);
+ return use_module('Authen::Htpasswd')->new($self->htpasswd_file);
}
sub all {
sub add {
my ($self, $user) = @_;
unless (blessed($user)) {
- $user = App::EzPz::User->new($user);
+ $user = use_module('App::EzPz::User')->new($user);
}
my $htp_file = $self->_htpasswd;
my $htp_user = $user->_htpasswd_user;
$htp_file->add_user($htp_user);
$htp_user->file($htp_file);
+ $user->_set_ezmlm_bindir($self->ezmlm_bindir);
return $user;
}
sub _inflate_user {
my ($self, $htp_user) = @_;
- return App::EzPz::User->new(
+ return use_module('App::EzPz::User')->new(
htpasswd_user => $htp_user,
+ ezmlm_bindir => $self->ezmlm_bindir,
);
}