[system] / trunk / webwork2 / lib / WeBWorK / DB / Schema / Auth1Hash.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/DB/Schema/Auth1Hash.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 807 Revision 808
6package WeBWorK::DB::Schema::Auth1Hash; 6package WeBWorK::DB::Schema::Auth1Hash;
7 7
8=head1 NAME 8=head1 NAME
9 9
10WeBWorK::DB::Schema::Auth1Hash - support access to the password, permission, 10WeBWorK::DB::Schema::Auth1Hash - support access to the password, permission,
11and key tables with a 1.x-structured hash-style backend. 11and key tables with a WWDBv1 hash-style backend.
12 12
13=cut 13=cut
14 14
15use strict; 15use strict;
16use warnings; 16use warnings;
17use WeBWorK::DB::Record::User;
18use WeBWorK::DB::Utils qw(record2hash hash2record hash2string string2hash);
19 17
20use constant TABLES => qw(password permission key); 18use constant TABLES => qw(password permission key);
21use constant STYLE => "hash"; 19use constant STYLE => "hash";
22 20
23################################################################################ 21################################################################################
35################################################################################ 33################################################################################
36# constructor 34# constructor
37################################################################################ 35################################################################################
38 36
39sub new($$$$) { 37sub 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
61sub list($) { 60sub 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
69sub exists($$) { 72sub exists($$) {
70 my ($self, $userID) = @_; 73 my ($self, $userID) = @_;
71 $self->{driver}->connect("ro"); 74 $self->{driver}->connect("ro");
93sub get($$) { 96sub 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,

Legend:
Removed from v.807  
changed lines
  Added in v.808

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9