|
Lines 30-35
use base 'Exporter';
Link Here
|
| 30 |
|
30 |
|
| 31 |
our $VERSION = '1.01'; |
31 |
our $VERSION = '1.01'; |
| 32 |
our @EXPORT_OK = qw(hash_password); |
32 |
our @EXPORT_OK = qw(hash_password); |
|
|
33 |
our @usernameAliasColumns = ('userid', 'cardnumber'); #Possible columns to treat as the username when authenticating. Must be UNIQUE in DB. |
| 33 |
|
34 |
|
| 34 |
=head1 NAME |
35 |
=head1 NAME |
| 35 |
|
36 |
|
|
Lines 145-172
sub generate_salt {
Link Here
|
| 145 |
Checks if the given username and password match anybody in the Koha DB |
146 |
Checks if the given username and password match anybody in the Koha DB |
| 146 |
@PARAM1 String, user identifier, either the koha.borrowers.userid, or koha.borrowers.cardnumber |
147 |
@PARAM1 String, user identifier, either the koha.borrowers.userid, or koha.borrowers.cardnumber |
| 147 |
@PARAM2 String, clear text password from the authenticating user |
148 |
@PARAM2 String, clear text password from the authenticating user |
| 148 |
@RETURN String 'superuser', if user is the Koha DB user (superuser account) |
149 |
@RETURN Koha::Borrower, if login succeeded. |
| 149 |
undef, if the user is but a man. |
150 |
Sets Koha::Borrower->isSuperuser() if the user is a superuser. |
|
|
151 |
Sets Koha::Borrower->isDemouser() if the user is a demouser. |
| 150 |
@THROWS Koha::Exception::LoginFailed, if no matching password was found for all username aliases in Koha. |
152 |
@THROWS Koha::Exception::LoginFailed, if no matching password was found for all username aliases in Koha. |
| 151 |
=cut |
153 |
=cut |
| 152 |
TODO:: Should return the Koha::Borrower if login succeeded. |
154 |
|
| 153 |
sub checkKohaPassword { |
155 |
sub checkKohaPassword { |
| 154 |
my ($userid, $password) = @_; |
156 |
my ($userid, $password) = @_; |
|
|
157 |
my $borrower; #Find the borrower to return |
| 155 |
|
158 |
|
| 156 |
if ( $userid && $userid eq C4::Context->config('user') ) { |
159 |
$borrower = _checkKohaSuperuser($userid, $password); |
| 157 |
if ( $password && $password eq C4::Context->config('pass') ) { |
160 |
return $borrower if $borrower; |
| 158 |
# Koha superuser account |
|
|
| 159 |
# C4::Context->set_userenv(0,0,C4::Context->config('user'),C4::Context->config('user'),C4::Context->config('user'),"",1); |
| 160 |
return 'superuser'; |
| 161 |
} |
| 162 |
else { |
| 163 |
Koha::Exception::LoginFailed->throw(error => "Password authentication failed"); |
| 164 |
} |
| 165 |
} |
| 166 |
|
161 |
|
| 167 |
my $usernameFound = 0; #Report to the user if userid/barcode was found, even if the login failed. |
162 |
my $usernameFound = 0; #Report to the user if userid/barcode was found, even if the login failed. |
| 168 |
#Check for each username alias if we can confirm a login with that. |
163 |
#Check for each username alias if we can confirm a login with that. |
| 169 |
my @usernameAliasColumns = ('userid', 'cardnumber'); |
|
|
| 170 |
for my $unameAlias (@usernameAliasColumns) { |
164 |
for my $unameAlias (@usernameAliasColumns) { |
| 171 |
my $borrower = Koha::Borrowers->find({$unameAlias => $userid}); |
165 |
my $borrower = Koha::Borrowers->find({$unameAlias => $userid}); |
| 172 |
if ( $borrower ) { |
166 |
if ( $borrower ) { |
|
Lines 240-245
sub checkLDAPPassword {
Link Here
|
| 240 |
return 0; |
234 |
return 0; |
| 241 |
} |
235 |
} |
| 242 |
|
236 |
|
|
|
237 |
=head _checkKohaSuperuser |
| 238 |
|
| 239 |
my $borrower = Koha::AuthUtils::_checkKohaSuperuser($userid, $password); |
| 240 |
|
| 241 |
Check if the userid and password match the ones in the $KOHA_CONF |
| 242 |
@PARAM1 String, user identifier, either the koha.borrowers.userid, or koha.borrowers.cardnumber |
| 243 |
@PARAM2 String, clear text password from the authenticating user |
| 244 |
@RETURNS Koha::Borrower branded as superuser with ->isSuperuser() |
| 245 |
or undef if user logging in is not a superuser. |
| 246 |
@THROWS Koha::Exception::LoginFailed if user identifier matches, but password doesn't |
| 247 |
=cut |
| 248 |
TODO: add Koha::Borrower->isSuperuser(1); |
| 249 |
sub _checkKohaSuperuser { |
| 250 |
my ($userid, $password) = @_; |
| 251 |
|
| 252 |
if ( $userid && $userid eq C4::Context->config('user') ) { |
| 253 |
if ( $password && $password eq C4::Context->config('pass') ) { |
| 254 |
return _createTemporarySuperuser(); |
| 255 |
} |
| 256 |
else { |
| 257 |
Koha::Exception::LoginFailed->throw(error => "Password authentication failed"); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
=head _createTemporarySuperuser |
| 263 |
|
| 264 |
Create a temporary superuser which should be instantiated only to the environment |
| 265 |
and then discarded. So do not ->store() it! |
| 266 |
@RETURN Koha::Borrower, stamped as superuser. |
| 267 |
=cut |
| 268 |
|
| 269 |
sub _createTemporarySuperuser { |
| 270 |
my $borrower = Koha::Borrower->new(); |
| 271 |
|
| 272 |
my $superuserName = C4::Context->config('user'); |
| 273 |
$borrower->isSuperuser(1); |
| 274 |
$borrower->update({borrowernumber => 0, |
| 275 |
userid => $superuserName, |
| 276 |
cardnumber => $superuserName, |
| 277 |
firstname => $superuserName, |
| 278 |
surname => $superuserName, |
| 279 |
branchcode => 'NO_LIBRARY_SET', |
| 280 |
flags => 1, |
| 281 |
email => C4::Context->preference('KohaAdminEmailAddress') |
| 282 |
}); |
| 283 |
return $borrower; |
| 284 |
} |
| 285 |
|
| 243 |
1; |
286 |
1; |
| 244 |
|
287 |
|
| 245 |
__END__ |
288 |
__END__ |
| 246 |
- |
|
|