diff options
Diffstat (limited to 'lib/JWebmail')
-rw-r--r-- | lib/JWebmail/Model/ReadMails/Role.pm | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/JWebmail/Model/ReadMails/Role.pm b/lib/JWebmail/Model/ReadMails/Role.pm index 6d41964..3af73ed 100644 --- a/lib/JWebmail/Model/ReadMails/Role.pm +++ b/lib/JWebmail/Model/ReadMails/Role.pm @@ -5,19 +5,31 @@ use Params::Check 'check'; use Mojo::Base -role; # load after imports +package JWebmail::Model::ReadMails::Role::Shadow { + + use overload '""' => sub { '***' }; + + sub new { shift; bless \(shift.'') } + + sub show_password { ${shift()} } + +} + sub Auth { shift; state $AuthCheck = { - user => {required => 1, defined => 1}, - password => {required => 1, defined => 1}, + user => {defined => 1, required => 1}, + password => {defined => 1, required => 1}, challenge => {defined => 1}, }; my $self = @_ == 1 ? $_[0] : {@_}; - return check($AuthCheck, $self, 0) || die Params::Check::last_error; + my $res = check($AuthCheck, $self, 0) || die Params::Check::last_error; + $res->{password} = JWebmail::Model::ReadMails::Role::Shadow->new($res->{password}); + return $res; } -requires( +my @methods = ( # name:type parmeter of type # *key key => value # key=value default argument of value @@ -34,6 +46,19 @@ requires( 'move', # auth:Auth, mid, folder -> ^ 1 ); +requires(@methods); + +around @methods => sub { + my $orig = shift; + my $safe = $_[1]->{password}; + $_[1]->{password} = $safe->show_password; + my @res; + my $succ = eval { @res = $orig->(@_); 1 }; + $_[1]->{password} = $safe; + die $@ unless $succ; + return wantarray ? @res : $res[$#res]; +}; + around read_headers_for => sub { my $orig = shift; my $self = shift; |