From: Sergey Fayngold Date: Fri, 11 Mar 2016 22:58:38 +0000 (+0100) Subject: Use User::getUserByAuthData() in the 3rd party auth actions for better code reuse X-Git-Tag: 3.0.0_Beta_1~2037 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6901535c493de0acd63207fc9341e8b017c5f4e8;p=GitHub%2FWoltLab%2FWCF.git Use User::getUserByAuthData() in the 3rd party auth actions for better code reuse --- diff --git a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php index 6d2d4f0e4a..6afedcd7b5 100644 --- a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php @@ -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; - } } diff --git a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php index 8e909b7c91..3ff3c2e9e0 100644 --- a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php @@ -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; - } } diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index 29ac71ad04..e6faaee131 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -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; - } } diff --git a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php index 495c611289..3e8fb5de56 100644 --- a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php @@ -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; - } }