registration api update

This commit is contained in:
Čarodej
2022-05-04 08:42:21 +02:00
parent 137021fcdc
commit cf7e17e188
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Users\Actions\CreateNewUserAction; use App\Users\Actions\CreateNewUserAction;
use App\Users\Requests\RegisterUserRequest; use App\Users\Requests\RegisterUserRequest;
use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\JsonResponse;
use VueFileManager\Subscription\Domain\Plans\Exceptions\MeteredBillingPlanDoesntExist; use VueFileManager\Subscription\Domain\Plans\Exceptions\MeteredBillingPlanDoesntExist;
class RegisterUserController extends Controller class RegisterUserController extends Controller
@@ -16,11 +17,11 @@ class RegisterUserController extends Controller
) { ) {
} }
public function __invoke(RegisterUserRequest $request) public function __invoke(RegisterUserRequest $request): JsonResponse
{ {
// Check if account registration is enabled // Check if account registration is enabled
if (! intval(get_settings('registration'))) { if (! intval(get_settings('registration'))) {
return response([ return response()->json([
'type' => 'error', 'type' => 'error',
'message' => 'User registration is not allowed', 'message' => 'User registration is not allowed',
], 401); ], 401);
@@ -37,7 +38,7 @@ class RegisterUserController extends Controller
try { try {
$user = ($this->createNewUser)($data); $user = ($this->createNewUser)($data);
} catch (MeteredBillingPlanDoesntExist $e) { } catch (MeteredBillingPlanDoesntExist $e) {
return response([ return response()->json([
'type' => 'error', 'type' => 'error',
'message' => 'User registrations are temporarily disabled', 'message' => 'User registrations are temporarily disabled',
], 409); ], 409);
@@ -48,6 +49,9 @@ class RegisterUserController extends Controller
$this->guard->login($user); $this->guard->login($user);
} }
return response('User successfully registered.', 201); return response()->json([
'type' => 'success',
'message' => 'User successfully registered.',
], 201);
} }
} }