Use User::getUserByAuthData() in the 3rd party auth actions for better code reuse
authorSergey Fayngold <sergey@faynhost.com>
Fri, 11 Mar 2016 22:58:38 +0000 (23:58 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 13 Mar 2016 11:50:42 +0000 (12:50 +0100)
wcfsetup/install/files/lib/action/FacebookAuthAction.class.php
wcfsetup/install/files/lib/action/GithubAuthAction.class.php
wcfsetup/install/files/lib/action/GoogleAuthAction.class.php
wcfsetup/install/files/lib/action/TwitterAuthAction.class.php

index 6d2d4f0e4a9e21b9e00f980f2d806fdbf2d1c148..6afedcd7b5dc67a489f9e260d06e899187135eff 100644 (file)
@@ -82,7 +82,7 @@ class FacebookAuthAction extends AbstractAction {
                        $userData = JSON::decode($content);
                        
                        // check whether a user is connected to this facebook account
-                       $user = $this->getUser($userData['id']);
+                       $user = User::getUserByAuthData('facebook:'.$userData['id']);
                        
                        if ($user->userID) {
                                // a user is already connected, but we are logged in, break
@@ -148,26 +148,4 @@ class FacebookAuthAction extends AbstractAction {
                $this->executed();
                exit;
        }
-       
-       /**
-        * Fetches the User with the given userID.
-        * 
-        * @param       integer                 $userID
-        * @return      \wcf\data\user\User
-        */
-       public function getUser($userID) {
-               $sql = "SELECT  userID
-                       FROM    wcf".WCF_N."_user
-                       WHERE   authData = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array('facebook:'.$userID));
-               $row = $statement->fetchArray();
-               
-               if ($row === false) {
-                       $row = array('userID' => 0);
-               }
-               
-               $user = new User($row['userID']);
-               return $user;
-       }
 }
index 8e909b7c9152a3d9e374452edc28111fcabbbb3c..3ff3c2e9e0853284dad8fa227e94f0f684b38638 100644 (file)
@@ -78,7 +78,7 @@ class GithubAuthAction extends AbstractAction {
                        }
                        
                        // check whether a user is connected to this github account
-                       $user = $this->getUser($userData['id']);
+                       $user = User::getUserByAuthData('github:'.$userData['id']);
                        if (!$user->userID) {
                                $user = $this->getUser($data['access_token']);
                                $userEditor = new UserEditor($user);
@@ -166,26 +166,4 @@ class GithubAuthAction extends AbstractAction {
                $this->executed();
                exit;
        }
-       
-       /**
-        * Fetches the User with the given identifier.
-        * 
-        * @param       string                  $identifier
-        * @return      \wcf\data\user\User
-        */
-       public function getUser($identifier) {
-               $sql = "SELECT  userID
-                       FROM    wcf".WCF_N."_user
-                       WHERE   authData = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array('github:'.$identifier));
-               $row = $statement->fetchArray();
-               
-               if ($row === false) {
-                       $row = array('userID' => 0);
-               }
-               
-               $user = new User($row['userID']);
-               return $user;
-       }
 }
index 29ac71ad049b87677d950e68f6f340d8ae21278d..e6faaee13127f9682469661a4af16c542f128ac8 100644 (file)
@@ -84,7 +84,7 @@ class GoogleAuthAction extends AbstractAction {
                        $userData = JSON::decode($content);
                        
                        // check whether a user is connected to this google account
-                       $user = $this->getUser($userData['id']);
+                       $user = User::getUserByAuthData('google:'.$userData['id']);
                        
                        if ($user->userID) {
                                // a user is already connected, but we are logged in, break
@@ -154,26 +154,4 @@ class GoogleAuthAction extends AbstractAction {
                $this->executed();
                exit;
        }
-       
-       /**
-        * Fetches the User with the given userID.
-        * 
-        * @param       integer                 $userID
-        * @return      \wcf\data\user\User
-        */
-       public function getUser($userID) {
-               $sql = "SELECT  userID
-                       FROM    wcf".WCF_N."_user
-                       WHERE   authData = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array('google:'.$userID));
-               $row = $statement->fetchArray();
-               
-               if ($row === false) {
-                       $row = array('userID' => 0);
-               }
-               
-               $user = new User($row['userID']);
-               return $user;
-       }
 }
index 495c61128936e92519bb12183a61acd712a46189..3e8fb5de56c618c183c9b18ab6560728aa0729fd 100644 (file)
@@ -76,7 +76,7 @@ class TwitterAuthAction extends AbstractAction {
                        parse_str($content, $data);
                        
                        // check whether a user is connected to this twitter account
-                       $user = $this->getUser($data['user_id']);
+                       $user = User::getUserByAuthData('twitter:'.$data['user_id']);
                        
                        if ($user->userID) {
                                // a user is already connected, but we are logged in, break
@@ -231,26 +231,4 @@ class TwitterAuthAction extends AbstractAction {
                
                return base64_encode(hash_hmac('sha1', $base, $key, true));
        }
-       
-       /**
-        * Fetches the User with the given userID
-        * 
-        * @param       integer                 $userID
-        * @return      \wcf\data\user\User
-        */
-       public function getUser($userID) {
-               $sql = "SELECT  userID
-                       FROM    wcf".WCF_N."_user
-                       WHERE   authData = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array('twitter:'.$userID));
-               $row = $statement->fetchArray();
-               
-               if ($row === false) {
-                       $row = array('userID' => 0);
-               }
-               
-               $user = new User($row['userID']);
-               return $user;
-       }
 }