X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FUsers.pm;h=9d70fc2626585fc1389e9c9d37ac0de5d0cc7b8c;hb=fa041ffba328c26a58506d5ccabed93d29106473;hp=36b94c30256ad15172984ff6001220185ccd83ca;hpb=32bf807f4c912062de85f9beee5228a23014484d;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Users.pm b/lib/NDWeb/Controller/Users.pm index 36b94c3..9d70fc2 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 @@ -100,7 +101,7 @@ sub updateUser : Local { } $dbh->do(qq{UPDATE users SET $column = ? WHERE uid = ? } ,undef,$value,$user->{uid}); - $log->execute($c->user->id,"HC changed $column from $c->{$column} to $value for user: $user->{uid} ($user->{username})"); + $log->execute($c->user->id,"HC changed $column from $user->{$column} to $value for user: $user->{uid} ($user->{username})"); }elsif ($param =~ /^gr:(\d+)$/){ my $query; if ($c->req->param($param) eq 'remove'){ @@ -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 => \@emails); + }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)