1 package App::EzPz::Web;
3 use Module::Runtime qw(use_module);
4 use App::EzPz::UserStore;
8 has users => (is => 'lazy');
12 my $config = $self->config;
13 return App::EzPz::UserStore->new(
14 htpasswd_file => $config->{htpasswd_file},
15 ($config->{ezmlm_bindir}
17 bindir => $config->{ezmlm_bindir},
18 list_base_dir => $config->{list_base_dir},
26 htpasswd_file => 'test-config/htpasswd',
27 ezmlm_bindir => 'test-ezmlm/bin',
28 list_base_dir => 'test-lists',
32 sub dispatch_request {
34 my $users = $self->users;
37 return if $_[PSGI_ENV]->{REMOTE_USER};
38 return use_module('Plack::Middleware::Auth::Basic')->new(
39 authenticator => sub { $users->check_password(@_) }
43 $current_user = $users->get(my $name = $_[PSGI_ENV]->{REMOTE_USER});
45 401, [ 'Content-type' => 'text/plain' ], [ "No such user $name" ]
46 ] unless $current_user;
50 $self->_render_front_page($current_user);
53 my $list = $current_user->get_list($_[1]);
56 $self->_list_dispatchers($list),
57 sub () { $self->_render_list_page($list) };
59 sub (/deny/|/allow/|/mod/|/digest/) {
61 my $sublist = $list->${\$_[1]};
62 $self->_list_dispatchers($sublist),
63 sub () { $self->_render_sublist_page($sublist) };
69 sub _list_dispatchers {
70 my ($self, $list) = @_;
73 $list->add_member($_[1]);
77 $list->remove_member($_[1]);
84 my ($self, $name) = @_;
85 my $my_file = __FILE__;
87 return HTML::Zoom->from_file("${my_file}/_templates/${name}.html");
91 my ($self, $name, $code) = @_;
93 200, [ 'Content-type' => 'text/html' ],
94 [ $self->_zoom_for($name)->${\sub { local $_ = $_[0]; &$code }}->to_html ]
98 sub _render_front_page {
99 my ($self, $user) = @_;
100 return $self->_render_page(index => sub {
101 $_->replace_content('.user-name',$user->username)
106 $_->select('.list-link')
107 ->replace_content($name)
109 ->set_attribute(href => "/list/${name}/");
116 sub _render_list_page {
117 my ($self, $list) = @_;
118 $self->_render_listcore_page(
120 map [ ucfirst($_)." list", "${_}/" ], qw(allow deny mod digest)
125 sub _render_sublist_page {
126 my ($self, $list) = @_;
127 $self->_render_listcore_page(
128 $list, [ [ "Back to list", "../" ] ],
132 sub _render_listcore_page {
133 my ($self, $list, $links) = @_;
134 $self->_render_page(list => sub {
135 $_->replace_content('.list-name', $list->name)
136 ->repeat('.list-link', [
138 my ($name, $href) = @$_;
140 $_->select('.list-link-anchor')
141 ->replace_content($name)
143 ->set_attribute(href => $href);
147 ->repeat('.list-member', [
151 $_->replace_content('.list-member-name', $email)
152 ->set_attribute('.list-member-remove', value => $email);
159 __PACKAGE__->run_if_script;