From: Michael Andreen Date: Fri, 18 Jul 2008 22:18:28 +0000 (+0200) Subject: Converted mail page X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=a7501170f1ef98a5959db048b92db2e4a12179a1 Converted mail page --- diff --git a/NDWeb/Pages/Mail.pm b/NDWeb/Pages/Mail.pm deleted file mode 100644 index 897976e..0000000 --- a/NDWeb/Pages/Mail.pm +++ /dev/null @@ -1,83 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# This program is free software; you can redistribute it and/or modify * -# it under the terms of the GNU General Public License as published by * -# the Free Software Foundation; either version 2 of the License, or * -# (at your option) any later version. * -# * -# This program is distributed in the hope that it will be useful, * -# but WITHOUT ANY WARRANTY; without even the implied warranty of * -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# GNU General Public License for more details. * -# * -# You should have received a copy of the GNU General Public License * -# along with this program; if not, write to the * -# Free Software Foundation, Inc., * -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ - -package NDWeb::Pages::Mail; -use strict; -use warnings FATAL => 'all'; -use CGI qw/:standard/; -use Mail::Sendmail; - -use NDWeb::Forum; -use NDWeb::Include; - -use base qw/NDWeb::XMLPage/; - -$NDWeb::Page::PAGES{mail} = __PACKAGE__; - -sub render_body { - my $self = shift; - my ($BODY) = @_; - - my $DBH = $self->{DBH}; - - $self->{TITLE} = 'Mail members'; - - return $self->noAccess unless $self->isHC; - - my $groups = $DBH->prepare(q{SELECT gid,groupname FROM groups WHERE gid > 0 ORDER BY gid}); - $groups->execute; - my @groups; - push @groups,{gid => -1, groupname => 'Pick a group'}; - while (my $group = $groups->fetchrow_hashref){ - push @groups,$group; - } - $BODY->param(Groups => \@groups); - - if (defined param('cmd') && param('group') > 0){ - my $emails = $DBH->prepare(q{SELECT email FROM users - WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = $1) - AND email is not null}); - $emails->execute(param('group')); - my @emails; - while (my $email = $emails->fetchrow_hashref){ - push @emails,$email->{email}; - } - $ND::ERROR .= p (join ', ',@emails); - - my %mail = ( - smtp => 'ruin.nu', - BCC => (join ',',@emails), - From => 'NewDawn Command ', - 'Content-type' => 'text/plain; charset="UTF-8"', - Subject => param('subject'), - Message => param('message'), - ); - - if (sendmail %mail) { - $ND::ERROR .= p "Mail sent OK.\n" - }else { - $ND::ERROR .= p $Mail::Sendmail::error; - } - }elsif(defined param('message')) { - $BODY->param(Subject => param('subject')); - $BODY->param(Message => param('message')); - } - return $BODY; -} -1; diff --git a/lib/NDWeb/Controller/Users.pm b/lib/NDWeb/Controller/Users.pm index 36b94c3..781fc73 100644 --- a/lib/NDWeb/Controller/Users.pm +++ b/lib/NDWeb/Controller/Users.pm @@ -5,6 +5,7 @@ use warnings; use parent 'Catalyst::Controller'; use ND::Include; +use Mail::Sendmail; =head1 NAME @@ -139,6 +140,58 @@ sub findUser : Private { $c->stash(u => $user); } +sub mail : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + $c->stash(ok => $c->flash->{ok}); + $c->stash(error => $c->flash->{error}); + $c->stash(subject => $c->flash->{subject}); + $c->stash(message => $c->flash->{message}); + + my $groups = $dbh->prepare(q{SELECT gid,groupname FROM groups WHERE gid > 0 ORDER BY gid}); + $groups->execute; + my @groups; + push @groups,{gid => -1, groupname => 'Pick a group'}; + while (my $group = $groups->fetchrow_hashref){ + push @groups,$group; + } + $c->stash(groups => \@groups); +} + +sub postmail : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $emails = $dbh->prepare(q{SELECT email FROM users + WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = $1) + AND email is not null}); + $emails->execute($c->req->param('group')); + my @emails; + while (my $email = $emails->fetchrow_hashref){ + push @emails,$email->{email}; + } + + my %mail = ( + smtp => 'ruin.nu', + BCC => (join ',',@emails), + From => 'NewDawn Command ', + 'Content-type' => 'text/plain; charset="UTF-8"', + Subject => $c->req->param('subject'), + Message => $c->req->param('message'), + ); + + if (sendmail %mail) { + $c->flash(ok => ); + }else { + $c->flash(error => $Mail::Sendmail::error); + $c->flash(subject => $c->req->param('subject')); + $c->flash(message => $c->req->param('message')); + } + + $c->res->redirect($c->uri_for('mail')); +} + =head1 AUTHOR Micahel Andreen (harv@ruin.nu) diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 12794f0..73f7b01 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -101,6 +101,6 @@
  • Member Intel
  • Alliance resources
  • Planet Naps
  • -
  • Mail
  • +
  • Mail
  • [% END %] diff --git a/root/src/users/mail.tt2 b/root/src/users/mail.tt2 new file mode 100644 index 0000000..8613d8a --- /dev/null +++ b/root/src/users/mail.tt2 @@ -0,0 +1,17 @@ +[% META title = 'Mail' %] + +[% IF ok %] +

    Mail sent successfully

    +

    [% ok.join(', ') %]

    +[% END %] + +
    Mail +

    Subject:

    +

    To:

    +
    +
    +
    diff --git a/templates/mail.tmpl b/templates/mail.tmpl deleted file mode 100644 index 246de10..0000000 --- a/templates/mail.tmpl +++ /dev/null @@ -1,16 +0,0 @@ - - -

    -
    - -
    Mail - Subject: -
    To: -
    - -
    -