aboutsummaryrefslogtreecommitdiffstats
path: root/fripost-adduser
diff options
context:
space:
mode:
Diffstat (limited to 'fripost-adduser')
-rwxr-xr-xfripost-adduser25
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> >>