aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGustav Eek <gustaveek@student.gu.se>2011-03-14 20:54:34 +0100
committerGustav Eek <gustaveek@student.gu.se>2011-03-14 20:54:34 +0100
commit16ed1260dd2433d9c25cd550a06c175093416f58 (patch)
treec1caa0838e48db7a3b196186e2b8291facf4060f /lib
parent0df2709e4588f653fa680f4820dd2d696749723f (diff)
parent68708cd2430d4da548673fd612c891413448fddf (diff)
Merge branch 'master' of https://github.com/skangas/fripost-tools
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Fripost/Logger.pm3
-rwxr-xr-xlib/Fripost/Password.pm4
-rwxr-xr-xlib/Fripost/Prompt.pm75
-rwxr-xr-xlib/Fripost/Schema.pm1
-rw-r--r--lib/Fripost/Schema/Result/Mailbox.pm18
5 files changed, 62 insertions, 39 deletions
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..038d835 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
@@ -18,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 514a0b7..b41f806 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
@@ -18,26 +17,57 @@ 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) = @_;
+ $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 !~ /\@/) {
$nam .= '@fripost.org';
- say "Using $nam";
+ say "Using username: $nam";
}
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";
@@ -50,32 +80,9 @@ sub prompt_password {
-minnum => 2,
-minspecial => 2,
);
- say "Generated password: $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;
+ say "Using password: $password";
}
+ return $password;
}
=head1 AUTHOR
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/;
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 -