aboutsummaryrefslogtreecommitdiffstats
path: root/fripost-adduser
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2010-12-31 06:27:19 +0100
committerStefan Kangas <stefankangas@gmail.com>2010-12-31 06:27:19 +0100
commit8528efc6b533dd72ee11a6e95c7b09f10752a405 (patch)
tree8c955f8cc448d5ffc44ce429a92c8196ef6b8b3b /fripost-adduser
parentb30fb0d7e1b16d60a769fa4c5d8053420cf06774 (diff)
move several prompts to a separate module
Diffstat (limited to 'fripost-adduser')
-rwxr-xr-xfripost-adduser33
1 files changed, 13 insertions, 20 deletions
diff --git a/fripost-adduser b/fripost-adduser
index d7a0fd3..1dab56e 100755
--- a/fripost-adduser
+++ b/fripost-adduser
@@ -27,29 +27,18 @@ use lib "$Bin/lib";
use Data::Dumper;
use DateTime;
-use Email::Valid;
use Fripost::Password;
+use Fripost::Prompt;
use Fripost::Schema;
use IO::Prompt;
use Getopt::Long;
-use String::MkPasswd qw/mkpasswd/;
use YAML::Syck;
# Prompt for user info
sub read_user_info {
my %user;
- # Get the full e-mail of the user (aka e-mail)
- while (not defined $user{username}) {
- $user{username} = prompt "New username: ";
- if (!($user{username} =~ /\@/)) {
- $user{username} .= '@fripost.org';
- say "Using $user{username}";
- }
- if (!Email::Valid->address($user{username})) {
- undef $user{username};
- say "This is not a valid e-mail address. Try again."
- }
- }
+
+ $user{username} = prompt_username("New username: ");
# Full name of user
$user{name} = prompt "Full (real) name: ";
@@ -76,16 +65,12 @@ sub read_user_info {
$user{active} = 1;
# Generate password
- my $password = mkpasswd(
- -length => 20,
- -minnum => 5,
- -minspecial => 3
- );
+ my $password = prompt_password();
$user{password} = smd5($password);
# Show the information that will be inserted
say Dumper \%user;
- say "Generated password: $password";
+ say "Using password $password";
# Ask the user if the information is OK
my $confirmed = prompt "Is this OK? ", -yn;
@@ -104,6 +89,7 @@ GetOptions(
'dbi_dsn' => \$conf->{dbi_dsn},
'admuser=s' => \$conf->{admuser},
'admpass=s' => \$conf->{admpass},
+ 'pretend' => \$conf->{pretend},
) or die "Unable to get command line options.";
# Connect to the database
@@ -120,6 +106,11 @@ if (!defined $user) {
exit 1;
}
+if ($conf->{pretend}) {
+ say "Nothing to do since we are pretending...";
+ exit 0;
+}
+
## Create maildir
my ($login,$pass,$uid,$gid) = getpwnam($conf->{maildir_user})
or die "maildir_user not found: $conf->{maildir_user}";
@@ -133,6 +124,8 @@ system(qw/sudo chown -R/, "$conf->{maildir_user}:$conf->{maildir_group}", $conf-
say "Created maildir in $maildir_loc";
+## TODO: Make sure the user does not already exist
+
## Insert user into database
my $db_user = $schema->resultset('Mailbox')->new($user);
$db_user->insert;