| … | |
… | |
| 6 | package WeBWorK::DB::Schema::Auth1Hash; |
6 | package WeBWorK::DB::Schema::Auth1Hash; |
| 7 | |
7 | |
| 8 | =head1 NAME |
8 | =head1 NAME |
| 9 | |
9 | |
| 10 | WeBWorK::DB::Schema::Auth1Hash - support access to the password, permission, |
10 | WeBWorK::DB::Schema::Auth1Hash - support access to the password, permission, |
| 11 | and key tables with a 1.x-structured hash-style backend. |
11 | and key tables with a WWDBv1 hash-style backend. |
| 12 | |
12 | |
| 13 | =cut |
13 | =cut |
| 14 | |
14 | |
| 15 | use strict; |
15 | use strict; |
| 16 | use warnings; |
16 | use warnings; |
| 17 | use WeBWorK::DB::Record::User; |
|
|
| 18 | use WeBWorK::DB::Utils qw(record2hash hash2record hash2string string2hash); |
|
|
| 19 | |
17 | |
| 20 | use constant TABLES => qw(password permission key); |
18 | use constant TABLES => qw(password permission key); |
| 21 | use constant STYLE => "hash"; |
19 | use constant STYLE => "hash"; |
| 22 | |
20 | |
| 23 | ################################################################################ |
21 | ################################################################################ |
| … | |
… | |
| 35 | ################################################################################ |
33 | ################################################################################ |
| 36 | # constructor |
34 | # constructor |
| 37 | ################################################################################ |
35 | ################################################################################ |
| 38 | |
36 | |
| 39 | sub new($$$$) { |
37 | sub new($$$$) { |
| 40 | my ($proto, $driver, $table, $record) = @_; |
38 | my ($proto, $driver, $table, $record, $params) = @_; |
| 41 | my $class = ref($proto) || $proto; |
39 | my $class = ref($proto) || $proto; |
| 42 | die "$table: unsupported table" |
40 | die "$table: unsupported table" |
| 43 | unless grep { $_ eq $table } $proto->tables(); |
41 | unless grep { $_ eq $table } $proto->tables(); |
| 44 | die $driver->style(), ": style mismatch" |
42 | die $driver->style(), ": style mismatch" |
| 45 | unless $driver->style() eq $proto->style(); |
43 | unless $driver->style() eq $proto->style(); |
| 46 | my $self = { |
44 | my $self = { |
| 47 | driver => $driver, |
45 | driver => $driver, |
| 48 | table => $table, |
46 | table => $table, |
| 49 | record => $record, |
47 | record => $record, |
|
|
48 | params => $params, |
| 50 | }; |
49 | }; |
| 51 | bless $self, $class; |
50 | bless $self, $class; |
| 52 | return $self; |
51 | return $self; |
| 53 | } |
52 | } |
| 54 | |
53 | |
| … | |
… | |
| 56 | # table access functions |
55 | # table access functions |
| 57 | # Auth1Hash provides access to three tables, so it checks the $self->{table} |
56 | # Auth1Hash provides access to three tables, so it checks the $self->{table} |
| 58 | # field to know what data its dealing with. |
57 | # field to know what data its dealing with. |
| 59 | ################################################################################ |
58 | ################################################################################ |
| 60 | |
59 | |
| 61 | sub list($) { |
60 | sub list($@) { |
| 62 | my ($self) = @_; |
61 | my ($self, @keyparts) = @_; |
|
|
62 | my ($matchUserID) = @keyparts; |
| 63 | $self->{driver}->connect("ro"); |
63 | $self->{driver}->connect("ro"); |
| 64 | my @keys = keys %{ $self->{driver}->hash() }; |
64 | my @keys = keys %{ $self->{driver}->hash() }; |
| 65 | $self->{driver}->disconnect(); |
65 | $self->{driver}->disconnect(); |
| 66 | return @keys; |
66 | if (defined $matchUserID) { |
|
|
67 | @keys = grep { $_ eq $matchUserID } @keys; |
|
|
68 | } |
|
|
69 | return map { [$_] } @keys; |
| 67 | } |
70 | } |
| 68 | |
71 | |
| 69 | sub exists($$) { |
72 | sub exists($$) { |
| 70 | my ($self, $userID) = @_; |
73 | my ($self, $userID) = @_; |
| 71 | $self->{driver}->connect("ro"); |
74 | $self->{driver}->connect("ro"); |
| … | |
… | |
| 93 | sub get($$) { |
96 | sub get($$) { |
| 94 | my ($self, $userID) = @_; |
97 | my ($self, $userID) = @_; |
| 95 | $self->{driver}->connect("ro"); |
98 | $self->{driver}->connect("ro"); |
| 96 | my $value = $self->{driver}->hash()->{$userID}; |
99 | my $value = $self->{driver}->hash()->{$userID}; |
| 97 | $self->{driver}->disconnect(); |
100 | $self->{driver}->disconnect(); |
| 98 | return undef unless $value; |
101 | return undef unless defined $value; |
| 99 | if ($self->{table} eq "key") { |
102 | if ($self->{table} eq "key") { |
| 100 | # key's value contains two fields |
103 | # key's value contains two fields |
| 101 | my ($key, $timestamp) = $value =~ m/^(\S+)\s+(.*)$/; |
104 | my ($key, $timestamp) = $value =~ m/^(\S+)\s+(.*)$/; |
| 102 | return $self->{record}->new( |
105 | return $self->{record}->new( |
| 103 | user_id => $userID, |
106 | user_id => $userID, |