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

Diff of /trunk/webwork2/lib/WeBWorK/DB/Auth.pm

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

Revision 332 Revision 334
47 47
48sub disconnect($$) { 48sub disconnect($$) {
49 my $self = shift; 49 my $self = shift;
50 my $db = shift; 50 my $db = shift;
51 return unless defined $self->{$db."_db"}; 51 return unless defined $self->{$db."_db"};
52 $self->{$db."_db"}->disconnect(); 52 $self->{$db."_db"}->disconnect;
53} 53}
54 54
55# ----- 55# -----
56 56
57sub getPassword($$) { 57sub getPassword($$) {
58 my $self = shift; 58 my $self = shift;
59 my $user = shift; 59 my $user = shift;
60 return unless $self->{password_db}->connect("ro"); 60 return unless $self->{password_db}->connect("rw");
61 my $result = $self->{password_db}->hashRef()->{$user}; 61 my $result = $self->{password_db}->hashRef->{$user};
62 $self->{password_db}->disconnect(); 62 $self->{password_db}->disconnect;
63 return $result; 63 return $result;
64} 64}
65 65
66sub setPassword($$$) { 66sub setPassword($$$) {
67 my $self = shift; 67 my $self = shift;
68 my $user = shift; 68 my $user = shift;
69 my $password = crypt shift, join "", ('.','/','0'..'9','A'..'Z','a'..'z')[rand 64, rand 64]; 69 my $password = crypt shift, join "", ('.','/','0'..'9','A'..'Z','a'..'z')[rand 64, rand 64];
70 $self->{password_db}->connect("rw"); 70 $self->{password_db}->connect("rw");
71 $self->{password_db}->hashRef()->{$user} = $password; 71 $self->{password_db}->hashRef->{$user} = $password;
72 $self->{password_db}->disconnect(); 72 $self->{password_db}->disconnect;
73} 73}
74 74
75sub verifyPassword($$$) { 75sub verifyPassword($$$) {
76 my $self = shift; 76 my $self = shift;
77 my $user = shift; 77 my $user = shift;
83 83
84sub deletePassword($$) { 84sub deletePassword($$) {
85 my $self = shift; 85 my $self = shift;
86 my $user = shift; 86 my $user = shift;
87 $self->{password_db}->connect("rw"); 87 $self->{password_db}->connect("rw");
88 delete $self->{password_db}->hashRef()->{$user}; 88 delete $self->{password_db}->hashRef->{$user};
89 $self->{password_db}->disconnect(); 89 $self->{password_db}->disconnect;
90} 90}
91 91
92# ----- 92# -----
93 93
94sub getKey($$) { 94sub getKey($$) {
95 my $self = shift; 95 my $self = shift;
96 my $user = shift; 96 my $user = shift;
97 return unless $self->{keys_db}->connect("ro"); 97 return unless $self->{keys_db}->connect("rw");
98 my $result = $self->{keys_db}->hashRef()->{$user}; 98 my $result = $self->{keys_db}->hashRef->{$user};
99 $self->{keys_db}->disconnect(); 99 $self->{keys_db}->disconnect;
100 my ($key, $timestamp) = defined $result ? split /\s+/, $result : (undef, undef); 100 my ($key, $timestamp) = defined $result ? split /\s+/, $result : (undef, undef);
101 return defined $result ? split /\s+/, $result : undef; 101 return defined $result ? split /\s+/, $result : undef;
102} 102}
103 103
104sub setKey($$$$) { 104sub setKey($$$$) {
106 my $user = shift; 106 my $user = shift;
107 my $key = shift; 107 my $key = shift;
108 my $timestamp = shift; 108 my $timestamp = shift;
109 my $key_string = "$key $timestamp"; 109 my $key_string = "$key $timestamp";
110 $self->{keys_db}->connect("rw"); 110 $self->{keys_db}->connect("rw");
111 $self->{keys_db}->hashRef()->{$user} = $key_string; 111 $self->{keys_db}->hashRef->{$user} = $key_string;
112 $self->{keys_db}->disconnect(); 112 $self->{keys_db}->disconnect;
113} 113}
114 114
115sub verifyKey($$$$$) { 115sub verifyKey($$$$$) {
116 my $self = shift; 116 my $self = shift;
117 my $user = shift; 117 my $user = shift;
129 129
130sub deleteKey($$) { 130sub deleteKey($$) {
131 my $self = shift; 131 my $self = shift;
132 my $user = shift; 132 my $user = shift;
133 $self->{keys_db}->connect("rw"); 133 $self->{keys_db}->connect("rw");
134 delete $self->{keys_db}->hashRef()->{$user}; 134 delete $self->{keys_db}->hashRef->{$user};
135 $self->{keys_db}->disconnect(); 135 $self->{keys_db}->disconnect;
136} 136}
137 137
138# ----- 138# -----
139 139
140sub getPermissions($$) { 140sub getPermissions($$) {
141 my $self = shift; 141 my $self = shift;
142 my $user = shift; 142 my $user = shift;
143 return unless $self->{permissions_db}->connect("ro"); 143 return unless $self->{permissions_db}->connect("rw");
144 my $result = $self->{permissions_db}->hashRef()->{$user}; 144 my $result = $self->{permissions_db}->hashRef->{$user};
145 $self->{permissions_db}->disconnect(); 145 $self->{permissions_db}->disconnect;
146 return $result; 146 return $result;
147} 147}
148 148
149sub setPermissions($$$) { 149sub setPermissions($$$) {
150 my $self = shift; 150 my $self = shift;
151 my $user = shift; 151 my $user = shift;
152 my $permissions = shift; 152 my $permissions = shift;
153 $self->{permissions_db}->connect("rw"); 153 $self->{permissions_db}->connect("rw");
154 $self->{permissions_db}->hashRef()->{$user} = $permissions; 154 $self->{permissions_db}->hashRef->{$user} = $permissions;
155 $self->{permissions_db}->disconnect(); 155 $self->{permissions_db}->disconnect;
156} 156}
157 157
158sub deletePermissions($$) { 158sub deletePermissions($$) {
159 my $self = shift; 159 my $self = shift;
160 my $user = shift; 160 my $user = shift;
161 $self->{permissions_db}->connect("rw"); 161 $self->{permissions_db}->connect("rw");
162 delete $self->{permissions_db}->hashRef()->{$user}; 162 delete $self->{permissions_db}->hashRef->{$user};
163 $self->{permissions_db}->disconnect(); 163 $self->{permissions_db}->disconnect;
164} 164}
165 165
166# ----- ghetto for stupid functions ----- 166# ----- ghetto for stupid functions -----
167 167
168sub change_user_in_password_file($$$) { 168sub change_user_in_password_file($$$) {
169 my $self = shift; 169 my $self = shift;
170 my $user = shift; 170 my $user = shift;
171 my $new_user = shift; 171 my $new_user = shift;
172 $self->{password_db}->connect("rw"); 172 $self->{password_db}->connect("rw");
173 my $pwhash = $self->{password_db}->hashRef(); # make things easier 173 my $pwhash = $self->{password_db}->hashRef; # make things easier
174 if (exists $pwhash->{$user}) { 174 if (exists $pwhash->{$user}) {
175 $pwhash->{$new_user} = $pwhash->{$user}; 175 $pwhash->{$new_user} = $pwhash->{$user};
176 delete $pwhash->{$user}; 176 delete $pwhash->{$user};
177 } 177 }
178 $self->{password_db}->disconnect(); 178 $self->{password_db}->disconnect;
179} 179}
180 180
181sub change_user_in_permissions_file($$$) { 181sub change_user_in_permissions_file($$$) {
182 my $self = shift; 182 my $self = shift;
183 my $user = shift; 183 my $user = shift;
184 my $new_user = shift; 184 my $new_user = shift;
185 $self->{permissions_db}->connect("rw"); 185 $self->{permissions_db}->connect("rw");
186 my $permhash = $self->{permissions_db}->hashRef(); # make things easier 186 my $permhash = $self->{permissions_db}->hashRef; # make things easier
187 if (exists $permhash->{$user}) { 187 if (exists $permhash->{$user}) {
188 $permhash->{$new_user} = $permhash->{$user}; 188 $permhash->{$new_user} = $permhash->{$user};
189 delete $permhash->{$user}; 189 delete $permhash->{$user};
190 } 190 }
191 $self->{permissions_db}->disconnect(); 191 $self->{permissions_db}->disconnect;
192} 192}
193 193
1941; 1941;

Legend:
Removed from v.332  
changed lines
  Added in v.334

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9