mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
namespace App\Users\Actions;
|
|
|
|
use App\Users\Models\User;
|
|
use Illuminate\Http\Response;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use App\Users\Requests\RegisterUserRequest;
|
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
|
|
|
class CreateNewUserAction extends Controller
|
|
{
|
|
public function __construct(
|
|
protected StatefulGuard $guard
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Validate and create a new user.
|
|
*/
|
|
public function __invoke(
|
|
RegisterUserRequest $request
|
|
): Application | ResponseFactory | Response {
|
|
$settings = get_settings([
|
|
'default_max_storage_amount', 'registration', 'user_verification',
|
|
]);
|
|
|
|
// Check if account registration is enabled
|
|
if (! intval($settings['registration'])) {
|
|
abort(401);
|
|
}
|
|
|
|
// Create user
|
|
$user = User::create([
|
|
'password' => bcrypt($request->input('password')),
|
|
'email' => $request->input('email'),
|
|
]);
|
|
|
|
// Mark as verified if verification is disabled
|
|
if (! intval($settings['user_verification'])) {
|
|
$user->markEmailAsVerified();
|
|
}
|
|
|
|
$user
|
|
->settings()
|
|
->create([
|
|
'name' => $request->input('name'),
|
|
]);
|
|
|
|
event(new Registered($user));
|
|
|
|
// Log in if verification is disabled
|
|
if (! intval($settings['user_verification'])) {
|
|
$this->guard->login($user);
|
|
}
|
|
|
|
return response('User registered successfully', 201);
|
|
}
|
|
}
|