aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfripost-adduser5
-rwxr-xr-xlib/Fripost/Prompt.pm63
2 files changed, 39 insertions, 29 deletions
diff --git a/fripost-adduser b/fripost-adduser
index 192a691..0fd534c 100755
--- a/fripost-adduser
+++ b/fripost-adduser
@@ -30,7 +30,7 @@ use YAML::Syck;
# Prompt for user info
sub read_user_info {
- my $username = prompt_username("New username: ");
+ my $username = prompt_email("New username: ", 'is_user');
my $name = prompt "Full (real) name: ";
my $domain = (split /\@/, $username)[1];
my $maildir = "$domain/". (split /\@/, $username)[0] . "/Maildir/"; # trailing slash important
@@ -103,6 +103,9 @@ say "Sent welcome message: ";
say $msg->as_string;
#say decode_qp($msg->as_string);
+ask_if_ok_or_abort("Send email with login information? ");
+
+prompt_email("Where should the email be sent? ");
=head1 AUTHOR
diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm
index 514a0b7..4b11a19 100755
--- a/lib/Fripost/Prompt.pm
+++ b/lib/Fripost/Prompt.pm
@@ -20,6 +20,16 @@ use String::MkPasswd qw/mkpasswd/;
our @EXPORT = qw(prompt_password prompt_username);
+sub ask_if_ok_or_abort {
+ my ($msg) = @_;
+ $msg //= "Is this OK? [no will abort] ";
+ my $confirmed = prompt $msg, -ynt;
+ unless ($confirmed) {
+ say "User aborted";
+ exit 1;
+ }
+}
+
sub fix_username {
my ($nam) = @_;
if ($nam !~ /\@/) {
@@ -29,15 +39,35 @@ sub fix_username {
return $nam;
}
+sub prompt_email {
+ my ($msg, $is_username) = @_;
+ $msg //= "Enter email: ";
+ my $email;
+ while (not defined $email) {
+ $email = prompt $msg;
+
+ if ($is_username) {
+ $email = fix_username($email)
+ }
+
+ if (!Email::Valid->address($email)) {
+ undef $email;
+ say "This is not a valid e-mail address. Try again."
+ }
+ }
+ return $email;
+
+}
+
sub prompt_password {
- my ($prompt, $prompt2) = @_;
- $prompt //= "Enter new password (blank for random): ";
- $prompt2 //= "Enter new password again (blank for random): ";
+ my ($msg, $msg2) = @_;
+ $msg //= "Enter new password (blank for random): ";
+ $msg2 //= "Enter new password again (blank for random): ";
my $password;
while (not defined $password) {
- $password = prompt $prompt, -e => '*';
- my $confirm = prompt $prompt2, -e => '*';
+ $password = prompt $msg, -e => '*';
+ my $confirm = prompt $msg2, -e => '*';
unless ($password eq $confirm) {
undef $password;
say "Passwords do not match";
@@ -55,29 +85,6 @@ sub prompt_password {
return smd5($password);
}
-sub prompt_username {
- my $prompt = shift;
- $prompt //= "Enter username: ";
- my $nam;
- while (not defined $nam) {
- $nam = prompt $prompt;
- $nam = fix_username($nam);
- if (!Email::Valid->address($nam)) {
- undef $nam;
- say "This is not a valid e-mail address. Try again."
- }
- }
- return $nam;
-}
-
-sub ask_if_ok_or_abort {
- my $confirmed = prompt "Is this OK? [no will abort]", -ynt;
- unless ($confirmed) {
- say "User aborted";
- exit 1;
- }
-}
-
=head1 AUTHOR
Stefan Kangas C<< <skangas at skangas.se> >>