Repository navigation
Expand file tree
/
Copy pathWebApplicationDBHandle.pm
More file actions
72 lines (49 loc) · 1.52 KB
/
Copy pathWebApplicationDBHandle.pm
File metadata and controls
72 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package WebApplicationDBHandle;
# WebApplicationDBHandle - connector to the WebAppBackend database
use strict;
use warnings;
use Conf;
use DBMaster;
=pod
=head1 NAME
WebApplicationDBHandle - connector to the WebAppBackend database
=head1 DESCRIPTION
This module returns an array of the DBMaster object connected to the WebAppBackend database
and a possible error message. In case of an error, the dbmaster will be undef. Otherwise
the error will be undef.
=head1 METHODS
=over 4
=item * B<new> ()
Creates a new instance of the WebApplicationDBHandle object.
=cut
sub new {
# get the connection data from Conf.pm
my $dbmaster;
eval {
$dbmaster = DBMaster->new(-database => $Conf::webapplication_db || "WebAppBackend",
-host => $Conf::webapplication_host || "localhost",
-user => $Conf::webapplication_user || "root",
-password => $Conf::webapplication_password || "",
-socket => $Conf::webapplication_socket || "");
};
if ($@) {
return (undef, $@);
}
return ($dbmaster, undef);
}
sub authenticate_user {
my ($master, $key) = @_;
unless (defined($master) && ref($master) eq "DBMaster") {
die "Undefined or invalid dbmaster passed to authenticate_user in WebApplicationDBHandle";
}
unless (defined($key) && length($key)) {
die "No key passed to authenticate_user in WebApplicationDBHandle";
}
my $pref = $master->Preferences->get_objects( { value => $key } );
if (scalar(@$pref)) {
return $pref->[0]->user;
} else {
return undef;
}
}
1;