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') 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 From 5d3d384a5bf1e08951ed37ec5111314c1cce82dc Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:17:13 +0100 Subject: Better name: confirm_or_abort --- lib/Fripost/Prompt.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 4b11a19..ac40411 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -20,7 +20,7 @@ use String::MkPasswd qw/mkpasswd/; our @EXPORT = qw(prompt_password prompt_username); -sub ask_if_ok_or_abort { +sub confirm_or_abort { my ($msg) = @_; $msg //= "Is this OK? [no will abort] "; my $confirmed = prompt $msg, -ynt; -- cgit v1.2.3 From 2b7ec90b448c01266f6b5b5bf7ce87d66df7733d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:30:13 +0100 Subject: Improve output --- lib/Fripost/Prompt.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index ac40411..a7e517c 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -34,7 +34,7 @@ sub fix_username { my ($nam) = @_; if ($nam !~ /\@/) { $nam .= '@fripost.org'; - say "Using $nam"; + say "Using username: $nam"; } return $nam; } @@ -80,7 +80,7 @@ sub prompt_password { -minnum => 2, -minspecial => 2, ); - say "Generated password: $password"; + say "Using password: $password"; } return smd5($password); } -- cgit v1.2.3 From bad3c7cdf557c76f05bfee0b07257264b3c5d04e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:20:32 +0100 Subject: Fix package statements --- lib/Fripost/Logger.pm | 3 +-- lib/Fripost/Password.pm | 3 +-- lib/Fripost/Prompt.pm | 3 +-- lib/Fripost/Schema.pm | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Fripost/Logger.pm b/lib/Fripost/Logger.pm index c515a5c..0aacf2c 100755 --- a/lib/Fripost/Logger.pm +++ b/lib/Fripost/Logger.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Logger; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm index 767bee1..12be42f 100755 --- a/lib/Fripost/Password.pm +++ b/lib/Fripost/Password.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Password; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index a7e517c..76529ec 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Prompt; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Schema.pm b/lib/Fripost/Schema.pm index 440d2ed..c9cc832 100755 --- a/lib/Fripost/Schema.pm +++ b/lib/Fripost/Schema.pm @@ -1,7 +1,6 @@ package Fripost::Schema; use 5.010_000; -use warnings; use strict; use base qw/DBIx::Class::Schema/; -- cgit v1.2.3 From c6d17eebc6f40188a33fa8aca863129ed57868e9 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:40:45 +0100 Subject: Fix export --- lib/Fripost/Password.pm | 1 + lib/Fripost/Prompt.pm | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm index 12be42f..038d835 100755 --- a/lib/Fripost/Password.pm +++ b/lib/Fripost/Password.pm @@ -17,6 +17,7 @@ use Exporter; use MIME::Base64; our @EXPORT = qw/smd5 make_salt/; +our @ISA = qw(Exporter); sub smd5 { my $pw = shift; diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 76529ec..03c5fc4 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -17,7 +17,8 @@ use Exporter; use IO::Prompt; use String::MkPasswd qw/mkpasswd/; -our @EXPORT = qw(prompt_password prompt_username); +our @EXPORT = qw(confirm_or_abort fix_username prompt_email prompt_password); +our @ISA = qw(Exporter); sub confirm_or_abort { my ($msg) = @_; -- cgit v1.2.3 From 68708cd2430d4da548673fd612c891413448fddf Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 20:54:51 +0100 Subject: Send password with credentials mail --- lib/Fripost/Prompt.pm | 2 +- lib/Fripost/Schema/Result/Mailbox.pm | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 03c5fc4..b41f806 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -82,7 +82,7 @@ sub prompt_password { ); say "Using password: $password"; } - return smd5($password); + return $password; } =head1 AUTHOR diff --git a/lib/Fripost/Schema/Result/Mailbox.pm b/lib/Fripost/Schema/Result/Mailbox.pm index f12e1f7..48d81fb 100644 --- a/lib/Fripost/Schema/Result/Mailbox.pm +++ b/lib/Fripost/Schema/Result/Mailbox.pm @@ -6,6 +6,8 @@ use strict; use base qw/DBIx::Class::Core/; +use Fripost::Password; + # mysql> describe mailbox; # +-------------+--------------+------+-----+---------------------+-------+ # | Field | Type | Null | Key | Default | Extra | @@ -32,6 +34,22 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key('username'); +=head2 store_column + +override store_column to encrypt the password when stored + +=cut + +sub store_column { + my ($self, $col, $val) = @_; + + if ($col eq 'password') { + $val = smd5($val); + } + + return $self->next::method($col,$val); +} + =head1 NAME Fripost::Schema::Result::Mailbox - -- cgit v1.2.3