Advertisement
Guest User

Untitled

a guest
Jan 31st, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.78 KB | None | 0 0
  1. sub login_user {
  2.     my ($self,$authenKey,$courseName,$userID) = @_;
  3.     my $soapEnv = new WebworkSOAP($authenKey,$courseName);
  4.     my $newKey;
  5.     my $timestamp = time;
  6.     my @chars = @{ $soapEnv->{ce}->{sessionKeyChars} };
  7.     my $length = $soapEnv->{ce}->{sessionKeyLength};
  8.     srand;
  9.     $newKey = join ("", @chars[map rand(@chars), 1 .. $length]);
  10.     my $Key = $soapEnv->{db}->newKey(user_id=>$userID, key=>$newKey, timestamp=>$timestamp);
  11.     eval { $soapEnv->{db}->deleteKey($userID) };
  12.     eval { $soapEnv->{db}->addKey($Key) };
  13.     $@ and soap_fault(SOAPERROR_USER_NOT_FOUND,"User not found.");
  14.     my $log_msg = "LOGIN OK: user_id=$userID login_type=SOAP";
  15.     writeCourseLog($soapEnv->{ce},"login_log",$log_msg);
  16.     return SOAP::Data->type( 'string', $newKey );
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement