mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 11:00:39 +00:00
- set social login credentials
- disallow registration refactoring
This commit is contained in:
@@ -18,28 +18,40 @@ class SocialiteCallbackController extends Controller
|
||||
|
||||
public function __invoke($provider)
|
||||
{
|
||||
$isAllowedRegistration = intval(get_settings('registration'));
|
||||
|
||||
// Get socialite user
|
||||
if (app()->runningUnitTests()) {
|
||||
$provider_user = Socialite::driver($provider)->user();
|
||||
$socialite = Socialite::driver($provider)->user();
|
||||
} else {
|
||||
$provider_user = Socialite::driver($provider)->stateless()->user();
|
||||
$socialite = Socialite::driver($provider)->stateless()->user();
|
||||
}
|
||||
|
||||
// Check if user exist already
|
||||
$user = User::where('email', $provider_user->email)->first();
|
||||
// Get user by email
|
||||
$user = User::where('email', $socialite->email);
|
||||
|
||||
// Login User
|
||||
if ($user) {
|
||||
$this->guard->login($user);
|
||||
// Login user when exists
|
||||
if ($user->exists()) {
|
||||
$this->guard->login(
|
||||
$user->first()
|
||||
);
|
||||
|
||||
return response('User logged in', 201);
|
||||
}
|
||||
|
||||
// Check if account registration is enabled
|
||||
if (! $isAllowedRegistration) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registration is not allowed',
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Create data user data object
|
||||
$data = CreateUserData::fromArray([
|
||||
'name' => $provider_user->getName(),
|
||||
'email' => $provider_user->getEmail(),
|
||||
'avatar' => store_socialite_avatar($provider_user->getAvatar()),
|
||||
'name' => $socialite->getName(),
|
||||
'email' => $socialite->getEmail(),
|
||||
'avatar' => store_socialite_avatar($socialite->getAvatar()),
|
||||
'oauth_provider' => $provider,
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Users\Actions;
|
||||
|
||||
use App\Users\DTO\CreateUserData;
|
||||
use App\Users\Models\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
@@ -17,17 +18,12 @@ class CreateNewUserAction extends Controller
|
||||
/**
|
||||
* Validate and create a new user.
|
||||
*/
|
||||
public function __invoke($data)
|
||||
public function __invoke(CreateUserData $data)
|
||||
{
|
||||
$settings = get_settings([
|
||||
'registration', 'user_verification', 'subscription_type',
|
||||
'user_verification', 'subscription_type',
|
||||
]);
|
||||
|
||||
// Check if account registration is enabled
|
||||
if (! intval($settings['registration'])) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
// Create user
|
||||
$user = User::create([
|
||||
'password' => $data->password ? bcrypt($data->password) : null,
|
||||
|
||||
@@ -10,11 +10,18 @@ class RegisterUserController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public CreateNewUserAction $createNewUser,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function __invoke(RegisterUserRequest $request)
|
||||
{
|
||||
// Check if account registration is enabled
|
||||
if (! intval(get_settings('registration'))) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registration is not allowed',
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Map registration data
|
||||
$data = CreateUserData::fromRequest($request);
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Domain\Settings\Controllers;
|
||||
|
||||
use Artisan;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use Domain\Settings\Requests\StoreSocialServiceCredentialsRequest;
|
||||
|
||||
class StoreSocialServiceCredentialsController
|
||||
{
|
||||
/**
|
||||
* Configure stripe additionally
|
||||
*/
|
||||
public function __invoke(StoreSocialServiceCredentialsRequest $request): Response
|
||||
{
|
||||
// Abort in demo mode
|
||||
abort_if(is_demo(), 204, 'Done.');
|
||||
|
||||
// Set on social login
|
||||
Setting::updateOrCreate([
|
||||
'name' => "allowed_{$request->input('service')}_login",
|
||||
], [
|
||||
'value' => 1,
|
||||
]);
|
||||
|
||||
// Get and store credentials
|
||||
if (! app()->runningUnitTests()) {
|
||||
$credentials = [
|
||||
'facebook' => [
|
||||
'FACEBOOK_CLIENT_ID' => $request->input('client_id'),
|
||||
'FACEBOOK_CLIENT_SECRET' => $request->input('client_secret'),
|
||||
],
|
||||
'google' => [
|
||||
'GOOGLE_CLIENT_ID' => $request->input('client_id'),
|
||||
'GOOGLE_CLIENT_SECRET' => $request->input('client_secret'),
|
||||
],
|
||||
'github' => [
|
||||
'GITHUB_CLIENT_ID' => $request->input('client_id'),
|
||||
'GITHUB_CLIENT_SECRET' => $request->input('client_secret'),
|
||||
],
|
||||
];
|
||||
|
||||
// Store credentials into the .env file
|
||||
setEnvironmentValue($credentials[$request->input('service')]);
|
||||
|
||||
// Clear cache
|
||||
if (! is_dev()) {
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('config:cache');
|
||||
}
|
||||
}
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Settings\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreSocialServiceCredentialsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'client_id' => 'required|string',
|
||||
'client_secret' => 'required|string',
|
||||
'service' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user