diff options
author | Gustav Eek <gustaveek@student.gu.se> | 2011-03-11 19:31:25 +0100 |
---|---|---|
committer | Gustav Eek <gustaveek@student.gu.se> | 2011-03-11 19:31:25 +0100 |
commit | 7b73cd7f6a4fb65ac5b28f0a53f644efb7a6726b (patch) | |
tree | ef304728411001c29b951254c7dae4950efb21d3 /fripost-adduser | |
parent | 34fcaf7c1e185d15310691432b2e8e210b2b5380 (diff) | |
parent | 846ba6f0a5a36ec34b48d9ebe8076fc69a42ff2a (diff) |
Merge branch 'master' of https://github.com/skangas/fripost-tools
Diffstat (limited to 'fripost-adduser')
-rwxr-xr-x | fripost-adduser | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/fripost-adduser b/fripost-adduser index 16f253c..0d65cf3 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -8,11 +8,6 @@ use strict; fripost-adduser - Add a new mailbox to the system -=head1 DESCRIPTION - -This script eases the burden of adding a new user to the system. It simply adds -a new user to the database. - =cut our $VERSION = '0.02'; @@ -21,16 +16,18 @@ use FindBin qw($Bin); use lib "$Bin/lib"; use Data::Dumper; +use File::Slurp qw(slurp); use Fripost::Password; use Fripost::Prompt; use Fripost::Schema; use IO::Prompt; use Getopt::Long; +use MIME::Lite; use YAML::Syck; # Prompt for user info sub read_user_info { - $username = prompt_username("New username: "); + my $username = prompt_username("New username: "); my $name = prompt "Full (real) name: "; my $domain = (split /\@/, $username)[1]; my $maildir = "$domain/". (split /\@/, $username)[0] . "/Maildir/"; # trailing slash important @@ -88,13 +85,27 @@ if ($conf->{pretend}) { exit 0; } -## TODO: Make sure the user does not already exist +die "User already exists" + if ($schema->resultset('Mailbox')->search({ + username => $user->{username} })->count); ## Insert user into database my $db_user = $schema->resultset('Mailbox')->new($user); $db_user->insert; say "New account $user->{username} added."; +## Send email +my $msg = MIME::Lite->new( + From => 'admin@fripost.org', + To => $user->{username}, + Subject => 'Välkommen till Fripost!', + Data => slurp('templ/new_user_mail.tt'), # TODO: actually use TT +); +$msg->send(); + +say "Sent welcome message: "; +say $message->as_text; + =head1 AUTHOR Stefan Kangas C<< <skangas at skangas.se> >> |