Bug 26171: Show biblionumber in Koha::Exceptions::Metadata::Invalid
[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 Exception::Class (
21
22     'Koha::Exceptions::Password' => {
23         description => 'Something went wrong!',
24     },
25     'Koha::Exceptions::Password::Invalid' => {
26         isa => 'Koha::Exceptions::Password',
27         description => 'Invalid password'
28     },
29     'Koha::Exceptions::Password::TooShort' => {
30         isa => 'Koha::Exceptions::Password',
31         description => 'Password is too short',
32         fields => ['length','min_length']
33     },
34     'Koha::Exceptions::Password::TooWeak' => {
35         isa => 'Koha::Exceptions::Password',
36         description => 'Password is too weak'
37     },
38     'Koha::Exceptions::Password::WhitespaceCharacters' => {
39         isa => 'Koha::Exceptions::Password',
40         description => 'Password contains leading/trailing whitespace character(s)'
41     },
42     'Koha::Exceptions::Password::Plugin' => {
43         isa => 'Koha::Exceptions::Password',
44         description => 'The password was rejected by a plugin'
45     },
46     'Koha::Exceptions::Password::NoCategoryProvided' => {
47         isa => 'Koha::Exceptions::Password',
48         description => 'You must provide a patron\'s category to validate password\'s strength and length'
49     }
50 );
51
52 sub full_message {
53     my $self = shift;
54
55     my $msg = $self->message;
56
57     unless ( $msg) {
58         if ( $self->isa('Koha::Exceptions::Password::TooShort') ) {
59             $msg = sprintf("Password length (%s) is shorter than required (%s)", $self->length, $self->min_length );
60         }
61     }
62
63     return $msg;
64 }
65
66 =head1 NAME
67
68 Koha::Exceptions::Password - Base class for password exceptions
69
70 =head1 Exceptions
71
72 =head2 Koha::Exceptions::Password
73
74 Generic password exception
75
76 =head2 Koha::Exceptions::Password::Invalid
77
78 The supplied password is invalid.
79
80 =head2 Koha::Exceptions::Password::TooShort
81
82 Password is too short.
83
84 =head2 Koha::Exceptions::Password::TooWeak
85
86 Password is too weak.
87
88 =head2 Koha::Exceptions::Password::WhitespaceCharacters
89
90 Password contains leading/trailing spaces, which is forbidden.
91
92 =head1 Class methods
93
94 =head2 full_message
95
96 Overloaded method for exception stringifying.
97
98 =cut
99
100 1;