Skip to content

Commit

Permalink
Improved user/get-by-authclient endpoint to support additional auth…
Browse files Browse the repository at this point in the history
…entication clients.
  • Loading branch information
gevorgmansuryan committed Sep 26, 2024
1 parent 7424b82 commit 457c28b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 56 deletions.
1 change: 0 additions & 1 deletion Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static function onBeforeRequest($event)
['pattern' => 'user/get-by-username', 'route' => 'rest/user/user/get-by-username', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/get-by-email', 'route' => 'rest/user/user/get-by-email', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/get-by-authclient', 'route' => 'rest/user/user/get-by-authclient', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/get-by-source', 'route' => 'rest/user/user/get-by-source', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/<id:\d+>', 'route' => 'rest/user/user/view', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/<id:\d+>', 'route' => 'rest/user/user/update', 'verb' => ['PUT', 'PATCH']],
['pattern' => 'user/<id:\d+>', 'route' => 'rest/user/user/delete', 'verb' => ['DELETE']],
Expand Down
19 changes: 6 additions & 13 deletions controllers/user/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use humhub\modules\user\models\Password;
use humhub\modules\user\models\Profile;
use humhub\modules\user\models\User;
use humhub\modules\user\models\Auth as UserAuth;
use Yii;
use yii\web\HttpException;

Expand Down Expand Up @@ -94,7 +93,12 @@ public function actionGetByEmail($email)
*/
public function actionGetByAuthclient($name, $id)
{
$user = User::findOne(['auth_mode' => $name, 'authclient_id' => $id]);
$user = User::find()
->alias('u')
->joinWith('auths a', false)
->where(['u.auth_mode' => $name, 'u.authclient_id' => $id])
->orWhere(['a.source' => $name, 'a.source_id' => $id])
->one();

if ($user === null) {
return $this->returnError(404, 'User not found!');
Expand All @@ -103,17 +107,6 @@ public function actionGetByAuthclient($name, $id)
return $this->actionView($user->id);
}

public function actionGetBySource($source, $id)
{
$auth = UserAuth::findOne(['source' => $source, 'source_id' => $id]);

if (empty($auth->user)) {
return $this->returnError(404, 'User not found!');
}

return $this->actionView($auth->user->id);
}

public function actionView($id)
{
$user = User::findOne(['id' => $id]);
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Changelog

0.10.4 (Unreleased)
---------------------------
- Enh #180: Added new `user/get-by-source` endpoint to get user by source
- Enh #180: Improved `user/get-by-authclient` endpoint to support additional authentication clients.

0.10.3 (September 13, 2024)
---------------------------
Expand Down
Loading

0 comments on commit 457c28b

Please sign in to comment.