Francois Gouget : testbot: Clean up the Authenticate() and NewSession() methods.

Alexandre Julliard julliard at winehq.org
Thu Jul 7 16:53:25 CDT 2022


Module: tools
Branch: master
Commit: 32f58a1c44f77f2a8907a325f1b15a8a1e45f27a
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=32f58a1c44f77f2a8907a325f1b15a8a1e45f27a

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Jul  7 15:11:09 2022 +0200

testbot: Clean up the Authenticate() and NewSession() methods.

Make sure all Authenticate() methods return an (error, user) pair
instead of just an error string. The result is the same but it's better
to be consistent.
Clearly identify unused variables and tweak the formatting a bit.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/lib/WineTestBot/CGI/Sessions.pm |  3 +-
 testbot/lib/WineTestBot/Users.pm        | 52 ++++++++-------------------------
 2 files changed, 13 insertions(+), 42 deletions(-)

diff --git a/testbot/lib/WineTestBot/CGI/Sessions.pm b/testbot/lib/WineTestBot/CGI/Sessions.pm
index 8594cfcd..afe78d06 100644
--- a/testbot/lib/WineTestBot/CGI/Sessions.pm
+++ b/testbot/lib/WineTestBot/CGI/Sessions.pm
@@ -131,8 +131,7 @@ sub NewSession($$$)
   $Session->User($User);
   $Session->Permanent($Permanent);
 
-  my ($ErrKey, $ErrProperty, $ErrMessage) = $self->Save();
-
+  my ($_ErrKey, $_ErrProperty, $ErrMessage) = $self->Save();
   return ($ErrMessage, $Session);
 }
 
diff --git a/testbot/lib/WineTestBot/Users.pm b/testbot/lib/WineTestBot/Users.pm
index 70d0d7b7..e9d68b09 100644
--- a/testbot/lib/WineTestBot/Users.pm
+++ b/testbot/lib/WineTestBot/Users.pm
@@ -223,15 +223,10 @@ sub Authenticate($$)
 
   if (! $self->Activated())
   {
-    if ($self->WaitingForApproval())
-    {
-      return ("Your account has not been approved yet", undef);
-    }
-    else
-    {
-      return ("You need to activate your account, see email for instructions",
-              undef);
-    }
+    return ($self->WaitingForApproval() ?
+            "Your account has not been approved yet" :
+            "You need to activate your account, see email for instructions",
+            undef);
   }
 
   my $CorrectHashedPassword = $self->Password;
@@ -352,41 +347,22 @@ sub AuthenticateLDAP($$$)
   my ($self, $Name, $Password) = @_;
 
   my $LDAP = Net::LDAP->new($LDAPServer);
-  if (! defined($LDAP))
-  {
-    return ("Can't connect to LDAP server: $@", undef);
-  }
+  return ("Can't connect to LDAP server: $@", undef) if (!$LDAP);
 
   my $BindDN = $LDAPBindDN;
   $BindDN =~ s/%USERNAME%/$Name/;
   my $Msg = $LDAP->bind($BindDN, password => $Password);
-  if ($Msg->code)
-  {
-    return "Unknown username or incorrect password";
-  }
+  return ("Unknown username or incorrect password", undef) if ($Msg->code);
 
   my $User = $self->GetItem($Name);
-  if (defined($User))
-  {
-    return (undef, $User);
-  }
+  return (undef, $User) if (defined $User);
 
   $User = $self->Add();
   my $ErrMessage = $User->FromLDAP($LDAP, $Name);
-  if ($ErrMessage)
-  {
-    return $ErrMessage;
-  }
-
-  my $ErrKey;
-  my $ErrProperty;
-  ($ErrKey, $ErrProperty, $ErrMessage) = $self->Save();
-  if ($ErrMessage)
-  {
-    return $ErrMessage;
-  }
+  return ($ErrMessage, undef) if ($ErrMessage);
 
-  return (undef, $User);
+  (my $_ErrKey, my $_ErrProperty, $ErrMessage) = $self->Save();
+  return $ErrMessage ? ($ErrMessage, undef) : (undef, $User);
 }
 
 sub AuthenticateBuiltin($$$)
@@ -394,12 +370,8 @@ sub AuthenticateBuiltin($$$)
   my ($self, $Name, $Password) = @_;
 
   my $User = $self->GetItem($Name);
-  if (! defined($User))
-  {
-    return "Unknown username or incorrect password";
-  }
-
-  return $User->Authenticate($Password);
+  return $User ? $User->Authenticate($Password) :
+                 ("Unknown username or incorrect password", undef);
 }
 
 sub Authenticate($$$)




More information about the wine-cvs mailing list