Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved user/get-by-authclient endpoint to support additional authentication clients #180

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ 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
12 changes: 12 additions & 0 deletions controllers/user/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 @@ -102,6 +103,17 @@ 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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

0.10.4 (Unreleased)
---------------------------
- Enh #180: Added new `user/get-by-source` endpoint to get user by source

0.10.3 (September 13, 2024)
---------------------------
- Enh #177: Collect user data for Legal module
Expand Down
Loading
Loading