~fkooman/vpn-user-portal

ca2937bd471b6e646320058a486808adf1f3ddb2 — François Kooman 3 months ago 4b9766b
return error if user not exists when using Admin API
1 files changed, 9 insertions(+), 1 deletions(-)

M src/Http/AdminApiModule.php
M src/Http/AdminApiModule.php => src/Http/AdminApiModule.php +9 -1
@@ 69,6 69,9 @@ class AdminApiModule implements ServiceModuleInterface
            '/v1/disable_user',
            function (Request $request, UserInfo $userInfo): Response {
                $userId = $request->requirePostParameter('user_id', fn(string $s) => Validator::userId($s));
                if (null === $this->storage->userInfo($userId)) {
                    throw new HttpException('user does not exist', 400);
                }
                $this->storage->userDisable($userId);

                // delete and disconnect all (active) VPN configurations


@@ 88,6 91,9 @@ class AdminApiModule implements ServiceModuleInterface
            '/v1/enable_user',
            function (Request $request, UserInfo $userInfo): Response {
                $userId = $request->requirePostParameter('user_id', fn(string $s) => Validator::userId($s));
                if (null === $this->storage->userInfo($userId)) {
                    throw new HttpException('user does not exist', 400);
                }

                // enabling the account will again allow the authorization of
                // OAuth clients, allow OpenVPN connections again and sync the


@@ 161,7 167,9 @@ class AdminApiModule implements ServiceModuleInterface
            function (Request $request, UserInfo $userInfo): Response {
                try {
                    $userId = $request->requirePostParameter('user_id', fn(string $s) => Validator::userId($s));

                    if (null === $this->storage->userInfo($userId)) {
                        throw new HttpException('user does not exist', 400);
                    }
                    // we will destroy all active configurations for this user
                    $this->connectionManager->disconnectByUserId($userId);
                    // delete the user account as well