Bug 29857: Make the exception classes inherit from the base class
[koha.git] / Koha / Exceptions / Password.pm
1 package Koha::Exceptions::Password;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::Exceptions::Exception;
21
22 use Exception::Class (
23
24     'Koha::Exceptions::Password' => {
25         isa => 'Koha::Exceptions::Exception',
26     },
27     'Koha::Exceptions::Password::Invalid' => {
28         isa => 'Koha::Exceptions::Password',
29         description => 'Invalid password'
30     },
31     'Koha::Exceptions::Password::TooShort' => {
32         isa => 'Koha::Exceptions::Password',
33         description => 'Password is too short',
34         fields => ['length','min_length']
35     },
36     'Koha::Exceptions::Password::TooWeak' => {
37         isa => 'Koha::Exceptions::Password',
38         description => 'Password is too weak'
39     },
40     'Koha::Exceptions::Password::WhitespaceCharacters' => {
41         isa => 'Koha::Exceptions::Password',
42         description => 'Password contains leading/trailing whitespace character(s)'
43     },
44     'Koha::Exceptions::Password::Plugin' => {
45         isa => 'Koha::Exceptions::Password',
46         description => 'The password was rejected by a plugin'
47     },
48     'Koha::Exceptions::Password::NoCategoryProvided' => {
49         isa => 'Koha::Exceptions::Password',
50         description => 'You must provide a patron\'s category to validate password\'s strength and length'
51     }
52 );
53
54 sub full_message {
55     my $self = shift;
56
57     my $msg = $self->message;
58
59     unless ( $msg) {
60         if ( $self->isa('Koha::Exceptions::Password::TooShort') ) {
61             $msg = sprintf("Password length (%s) is shorter than required (%s)", $self->length, $self->min_length );
62         }
63     }
64
65     return $msg;
66 }
67
68 =head1 NAME
69
70 Koha::Exceptions::Password - Base class for password exceptions
71
72 =head1 Exceptions
73
74 =head2 Koha::Exceptions::Password
75
76 Generic password exception
77
78 =head2 Koha::Exceptions::Password::Invalid
79
80 The supplied password is invalid.
81
82 =head2 Koha::Exceptions::Password::TooShort
83
84 Password is too short.
85
86 =head2 Koha::Exceptions::Password::TooWeak
87
88 Password is too weak.
89
90 =head2 Koha::Exceptions::Password::WhitespaceCharacters
91
92 Password contains leading/trailing spaces, which is forbidden.
93
94 =head1 Class methods
95
96 =head2 full_message
97
98 Overloaded method for exception stringifying.
99
100 =cut
101
102 1;