From b197defa26836ed7eb3052bf5ef82e52078825e6 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:31:26 +0100 Subject: WIP: send credentials --- INSTALL | 5 ++-- fripost-adduser | 80 ++++++++++++++++++++++++++++++++++++++++++------------ templ/user_info.tt | 28 +++++++++++++++++++ 3 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 templ/user_info.tt diff --git a/INSTALL b/INSTALL index 74be19a..cfbaa4d 100644 --- a/INSTALL +++ b/INSTALL @@ -2,6 +2,7 @@ You need several cpan modules to use these scripts. If you use Debian GNU/Linux, you can install them like so: -aptitude install -R libdatetime-format-mysql-perl libdatetime-perl \ +sudo aptitude install -R libdatetime-format-mysql-perl libdatetime-perl \ libdbix-class-perl libemail-valid-perl libfile-slurp-perl libio-prompt-perl \ -libmime-base64-perl libmime-lite-perl libstring-mkpasswd-perl libyaml-syck-perl +libmime-base64-perl libmime-lite-perl libstring-mkpasswd-perl \ +libtemplate-perl libyaml-syck-perl diff --git a/fripost-adduser b/fripost-adduser index 9a2fa00..e71de69 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -26,6 +26,7 @@ use IO::Prompt; use MIME::Base64; use MIME::Lite; use MIME::QuotedPrint; +use Template; use YAML::Syck; ## Get command line options @@ -73,36 +74,81 @@ die "User already exists" if ($schema->resultset('Mailbox')->search({ username => $user->{username} })->count); +## Insert user into database if ($conf->{pretend}) { - say "Nothing to do since we are pretending..."; - exit 0; + say "Did not create user since we are pretending." +} +else { + $schema->resultset('Mailbox')->new($user)->insert; + say "New account $user->{username} added."; } -## Insert user into database -my $db_user = $schema->resultset('Mailbox')->new($user); -$db_user->insert; -say "New account $user->{username} added."; +### Prepare sending emails + +my $tt = Template->new({ + INCLUDE_PATH => "$Bin/templ", + INTERPOLATE => 1, +}) || die "$Template::ERROR\n"; -## Send email my $msg = MIME::Lite->new( - From => 'admin@fripost.org', - To => $user->{username}, + From => 'Friposts administratörer ', Subject => "=?UTF-8?B?" . encode_base64(encode("utf8", 'Välkommen till Fripost!'), "") . "?=", - Data => scalar slurp('templ/new_user_mail.tt'), # TODO: actually use TT Encoding => 'quoted-printable', ); $msg->attr('content-type.charset' => 'utf-8'); -$msg->send(); - -say "Sent welcome message: "; -say $msg->as_string; -#say decode_qp($msg->as_string); -confirm_or_abort("Send email with login information? "); +### Send welcome email to new user +{ + my ($vars, $data); + $vars = {}; + $tt->process('new_user_mail.tt', $vars, \$data) + || die $tt->error(), '\n'; + + $msg->replace(To => $user->{username}); + $msg->data($data); + + + unless ($conf->{pretend}) { + $msg->send() unless $conf->{pretend};; + say "Sent welcome message."; + } + say "----------------------------------- Welcome"; + say decode_qp($msg->as_string); + say "-----------------------------------"; +} -prompt_email("Where should the email be sent? "); +### Send login credentials to new user +{ + my ($vars, $data); + $vars = { + user => $user->{username}, + pass => $user->{password}, + real => $user->{name}, + }; + $tt->process('user_info.tt', $vars, \$data) + || die $tt->error(), '\n'; + + $msg->data($data); + + say "Login information mail:"; + say "----------------------------------- Credentials"; + say decode_qp($msg->as_string); + say "-----------------------------------"; + + + confirm_or_abort("Send email with login information? "); + my $to = prompt_email("Where should the email be sent? "); + $msg->replace(To => $to); + if (!$conf->{pretend}) { + $msg->send; + say "Credentials sent."; + } + else { + say "Pretending, will not send credentials."; + } +} =head1 AUTHOR diff --git a/templ/user_info.tt b/templ/user_info.tt new file mode 100644 index 0000000..e6b778f --- /dev/null +++ b/templ/user_info.tt @@ -0,0 +1,28 @@ +Hej [% real %], + +Du är nu tillagd på Friposts system. + +Användarnamn: [% user %] +Lösenord [% pass %] + +Tänk på att vara försiktig med dina uppgifter. Spara en kopia av det här mailet +på en säker plats. + +Du kan logga in på: + + https://mail.fripost.org/ + +Frågor gällande ditt konto kan du ta direkt med administratörerna. + + admin@fripost.org + +Du kan hitta information om hur du konfigurerar din e-postklient för Fripost på +vår wiki. Vi försöker bygga upp medlemswikin till att bli den bästa resursen +för intern information kring föreningen. Du får gärna hjälpa till! + + http://wiki.fripost.org/ + +Ha kul! + +Med vänliga hälsningar, +Administratörerna -- cgit v1.2.3