From 02fd9f27bb2f580c88a28d963ce27dcff210bf73 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:06:23 +0100 Subject: WIP: send login information to address when adding user --- lib/Fripost/Prompt.pm | 63 ++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'lib/Fripost') 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<< >> -- cgit v1.2.3