mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Merge remote-tracking branch 'origin/social_authentication' into subscription
# Conflicts: # .env.example # composer.lock # public/mix-manifest.json # resources/js/views/User/Password.vue # routes/api.php # src/App/Users/Actions/CreateNewUserAction.php # tests/App/Users/UserAccountTest.php
This commit is contained in:
@@ -60,4 +60,7 @@ PAYSTACK_PUBLIC_KEY=
|
|||||||
PAYPAL_CLIENT_ID=
|
PAYPAL_CLIENT_ID=
|
||||||
PAYPAL_CLIENT_SECRET=
|
PAYPAL_CLIENT_SECRET=
|
||||||
|
|
||||||
SANCTUM_STATEFUL_DOMAINS=localhost,localhost:8000,127.0.0.1,127.0.0.1:8000,::1
|
SANCTUM_STATEFUL_DOMAINS=localhost,localhost:8000,127.0.0.1,127.0.0.1:8000,::1
|
||||||
|
|
||||||
|
FACEBOOK_CLIENT_ID=
|
||||||
|
FACEBOOK_CLIENT_SECRET=
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
"laravel/fortify": "^1.8.3",
|
"laravel/fortify": "^1.8.3",
|
||||||
"laravel/framework": "^8.77.1",
|
"laravel/framework": "^8.77.1",
|
||||||
"laravel/sanctum": "^2.12.1",
|
"laravel/sanctum": "^2.12.1",
|
||||||
|
"laravel/socialite": "^5.2",
|
||||||
"laravel/tinker": "^2.6.2",
|
"laravel/tinker": "^2.6.2",
|
||||||
"laravel/ui": "^3.3.1",
|
"laravel/ui": "^3.3.1",
|
||||||
"league/flysystem-aws-s3-v3": "^1.0.29",
|
"league/flysystem-aws-s3-v3": "^1.0.29",
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ return [
|
|||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
|
|
||||||
TeamTNT\Scout\TNTSearchScoutServiceProvider::class,
|
TeamTNT\Scout\TNTSearchScoutServiceProvider::class,
|
||||||
|
Laravel\Socialite\SocialiteServiceProvider::class,
|
||||||
Intervention\Image\ImageServiceProvider::class,
|
Intervention\Image\ImageServiceProvider::class,
|
||||||
App\Providers\FortifyServiceProvider::class,
|
App\Providers\FortifyServiceProvider::class,
|
||||||
|
|
||||||
@@ -228,6 +229,7 @@ return [
|
|||||||
'Image' => Intervention\Image\Facades\Image::class,
|
'Image' => Intervention\Image\Facades\Image::class,
|
||||||
'Stripe' => Cartalyst\Stripe\Laravel\Facades\Stripe::class,
|
'Stripe' => Cartalyst\Stripe\Laravel\Facades\Stripe::class,
|
||||||
'Crawler' => Jaybizzle\LaravelCrawlerDetect\Facades\LaravelCrawlerDetect::class,
|
'Crawler' => Jaybizzle\LaravelCrawlerDetect\Facades\LaravelCrawlerDetect::class,
|
||||||
|
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'deploy_secret' => env('APP_DEPLOY_SECRET'),
|
'deploy_secret' => env('APP_DEPLOY_SECRET'),
|
||||||
|
|||||||
@@ -33,4 +33,22 @@ return [
|
|||||||
'client_id' => env('PASSPORT_CLIENT_ID'),
|
'client_id' => env('PASSPORT_CLIENT_ID'),
|
||||||
'client_secret' => env('PASSPORT_CLIENT_SECRET'),
|
'client_secret' => env('PASSPORT_CLIENT_SECRET'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'google' => [
|
||||||
|
'client_id' => env('GOOGLE_CLIENT_ID'),
|
||||||
|
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
|
||||||
|
'redirect' => env('APP_URL') . '/socialite/google/callback'
|
||||||
|
],
|
||||||
|
|
||||||
|
'github' => [
|
||||||
|
'client_id' => env('GITHUB_CLIENT_ID'),
|
||||||
|
'client_secret' => env('GITHUB_CLIENT_SECRET'),
|
||||||
|
'redirect' => env('APP_URL') . '/socialite/github/callback',
|
||||||
|
],
|
||||||
|
|
||||||
|
'facebook' => [
|
||||||
|
'client_id' => env('FACEBOOK_CLIENT_ID'),
|
||||||
|
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
|
||||||
|
'redirect' => env('APP_URL') . '/socialite/facebook/callback',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddOauthProviderToUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('oauth_provider')->nullable();
|
||||||
|
$table->string('password')->nullable()->change();
|
||||||
|
|
||||||
|
$table->charset = 'utf8mb4';
|
||||||
|
$table->collation = 'utf8mb4_unicode_ci';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<template>
|
||||||
|
<div class="wrapper flex flex-row w-1/2 ml-2">
|
||||||
|
<div class="w-1/3 grid justify-items-center items-center cursor-pointer">
|
||||||
|
<facebook-icon @click="socialiteRedirect('facebook')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-1/3 grid justify-items-center items-center cursor-pointer">
|
||||||
|
<github-icon @click="socialiteRedirect('github')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-1/3 grid justify-items-center items-center cursor-pointer">
|
||||||
|
<h1 @click="socialiteRedirect('google')">G</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { FacebookIcon, GithubIcon } from 'vue-feather-icons'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name:'SocialiteAuthenticationButtons',
|
||||||
|
components: {
|
||||||
|
FacebookIcon,
|
||||||
|
GithubIcon,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
socialiteRedirect(provider) {
|
||||||
|
|
||||||
|
this.isLoading = true
|
||||||
|
|
||||||
|
this.$store.dispatch('socialiteRedirect', provider)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
margin: 50px auto 0px auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
9
resources/js/routes/routesAuth.js
vendored
9
resources/js/routes/routesAuth.js
vendored
@@ -1,4 +1,13 @@
|
|||||||
const routesAuth = [
|
const routesAuth = [
|
||||||
|
{
|
||||||
|
name: 'SocialiteCallback',
|
||||||
|
path: '/socialite/:provider/callback',
|
||||||
|
component: () =>
|
||||||
|
import(/* webpackChunkName: "chunks/email-verified" */ '../views/Auth/SocialiteCallback'),
|
||||||
|
meta: {
|
||||||
|
requiresAuth: false
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'SuccessfullyVerified',
|
name: 'SuccessfullyVerified',
|
||||||
path: '/successfully-verified',
|
path: '/successfully-verified',
|
||||||
|
|||||||
11
resources/js/store/modules/userAuth.js
vendored
11
resources/js/store/modules/userAuth.js
vendored
@@ -48,6 +48,17 @@ const actions = {
|
|||||||
router.push({name: 'Homepage'})
|
router.push({name: 'Homepage'})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
socialiteRedirect: ({commit}, provider) => {
|
||||||
|
|
||||||
|
axios
|
||||||
|
.get(`/api/socialite/${provider}/redirect`)
|
||||||
|
.then((response) => {
|
||||||
|
if(response.data.url) {
|
||||||
|
window.location.href = response.data.url
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => this.$isSomethingWrong())
|
||||||
|
},
|
||||||
addToFavourites: (context, folder) => {
|
addToFavourites: (context, folder) => {
|
||||||
let addFavourites = []
|
let addFavourites = []
|
||||||
let items = [folder]
|
let items = [folder]
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
:disabled="isLoading" />
|
:disabled="isLoading" />
|
||||||
</ValidationObserver>
|
</ValidationObserver>
|
||||||
|
|
||||||
|
<SocialiteAuthenticationButtons/>
|
||||||
|
|
||||||
<span v-if="config.userRegistration" class="additional-link">
|
<span v-if="config.userRegistration" class="additional-link">
|
||||||
{{ $t('page_login.registration_text') }}
|
{{ $t('page_login.registration_text') }}
|
||||||
<router-link class="text-theme" :to="{name: 'SignUp'}">
|
<router-link class="text-theme" :to="{name: 'SignUp'}">
|
||||||
@@ -151,6 +153,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import AuthContentWrapper from '/resources/js/components/Auth/AuthContentWrapper'
|
import AuthContentWrapper from '/resources/js/components/Auth/AuthContentWrapper'
|
||||||
import {ValidationObserver, ValidationProvider} from 'vee-validate/dist/vee-validate.full'
|
import {ValidationObserver, ValidationProvider} from 'vee-validate/dist/vee-validate.full'
|
||||||
|
import SocialiteAuthenticationButtons from '/resources/js/components/Auth/SocialiteAuthenticationButtons'
|
||||||
import AuthContent from '/resources/js/components/Auth/AuthContent'
|
import AuthContent from '/resources/js/components/Auth/AuthContent'
|
||||||
import AuthButton from '/resources/js/components/Auth/AuthButton'
|
import AuthButton from '/resources/js/components/Auth/AuthButton'
|
||||||
import Spinner from '/resources/js/components/FilesView/Spinner'
|
import Spinner from '/resources/js/components/FilesView/Spinner'
|
||||||
@@ -162,10 +165,11 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'SignIn',
|
name: 'SignIn',
|
||||||
components: {
|
components: {
|
||||||
Headline,
|
Headline,
|
||||||
AuthContentWrapper,
|
AuthContentWrapper,
|
||||||
ValidationProvider,
|
ValidationProvider,
|
||||||
ValidationObserver,
|
ValidationObserver,
|
||||||
|
SocialiteAuthenticationButtons,
|
||||||
AuthContent,
|
AuthContent,
|
||||||
AuthButton,
|
AuthButton,
|
||||||
Spinner,
|
Spinner,
|
||||||
@@ -233,8 +237,15 @@
|
|||||||
|
|
||||||
this.checkedAccount = response.data
|
this.checkedAccount = response.data
|
||||||
|
|
||||||
// Show sign in password page
|
if(response.data.oauth_provider) {
|
||||||
this.goToAuthPage('sign-in')
|
// Redirect user to socialite login if he's accout is registered by socialite
|
||||||
|
this.$store.dispatch('socialiteRedirect', response.data.oauth_provider)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Show sign in password page
|
||||||
|
this.goToAuthPage('sign-in')
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</ValidationObserver>
|
</ValidationObserver>
|
||||||
|
|
||||||
|
<SocialiteAuthenticationButtons/>
|
||||||
|
|
||||||
<span class="additional-link">{{ $t('page_registration.have_an_account') }}
|
<span class="additional-link">{{ $t('page_registration.have_an_account') }}
|
||||||
<router-link :to="{name: 'SignIn'}" class="text-theme">
|
<router-link :to="{name: 'SignIn'}" class="text-theme">
|
||||||
{{ $t('page_forgotten_password.password_remember_button') }}
|
{{ $t('page_forgotten_password.password_remember_button') }}
|
||||||
@@ -78,6 +80,7 @@
|
|||||||
import {ValidationProvider, ValidationObserver} from 'vee-validate/dist/vee-validate.full'
|
import {ValidationProvider, ValidationObserver} from 'vee-validate/dist/vee-validate.full'
|
||||||
import AuthContent from '/resources/js/components/Auth/AuthContent'
|
import AuthContent from '/resources/js/components/Auth/AuthContent'
|
||||||
import AuthButton from '/resources/js/components/Auth/AuthButton'
|
import AuthButton from '/resources/js/components/Auth/AuthButton'
|
||||||
|
import SocialiteAuthenticationButtons from '/resources/js/components/Auth/SocialiteAuthenticationButtons'
|
||||||
import {required} from 'vee-validate/dist/rules'
|
import {required} from 'vee-validate/dist/rules'
|
||||||
import {mapGetters} from 'vuex'
|
import {mapGetters} from 'vuex'
|
||||||
import {events} from '/resources/js/bus'
|
import {events} from '/resources/js/bus'
|
||||||
@@ -86,6 +89,7 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'SignUp',
|
name: 'SignUp',
|
||||||
components: {
|
components: {
|
||||||
|
SocialiteAuthenticationButtons,
|
||||||
AuthContentWrapper,
|
AuthContentWrapper,
|
||||||
ValidationProvider,
|
ValidationProvider,
|
||||||
ValidationObserver,
|
ValidationObserver,
|
||||||
|
|||||||
33
resources/js/views/Auth/SocialiteCallback.vue
Normal file
33
resources/js/views/Auth/SocialiteCallback.vue
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<Spinner/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Spinner from '/resources/js/components/FilesView/Spinner'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'SocialiteCallback',
|
||||||
|
components: {Spinner},
|
||||||
|
created () {
|
||||||
|
axios
|
||||||
|
.get(`/api${this.$route.fullPath}`)
|
||||||
|
.then(() => {
|
||||||
|
|
||||||
|
// Set login state
|
||||||
|
this.$store.commit('SET_AUTHORIZED', true)
|
||||||
|
|
||||||
|
// Go to files page
|
||||||
|
this.$router.push({name: 'Files'})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
|
||||||
|
this.$isSomethingWrong()
|
||||||
|
|
||||||
|
this.$router.push({name: 'Homepage'})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Domain\Zip\Controllers\ZipController;
|
use Domain\Zip\Controllers\ZipController;
|
||||||
use App\Users\Actions\CreateNewUserAction;
|
|
||||||
use Domain\Pages\Controllers\PagesController;
|
use Domain\Pages\Controllers\PagesController;
|
||||||
use Domain\Sharing\Controllers\ShareController;
|
use Domain\Sharing\Controllers\ShareController;
|
||||||
use Domain\Trash\Controllers\DumpTrashController;
|
use Domain\Trash\Controllers\DumpTrashController;
|
||||||
@@ -23,6 +22,10 @@ use Domain\Browsing\Controllers\BrowseLatestFilesController;
|
|||||||
use Domain\Browsing\Controllers\BrowseSharedItemsController;
|
use Domain\Browsing\Controllers\BrowseSharedItemsController;
|
||||||
use Domain\Browsing\Controllers\BrowseTrashContentController;
|
use Domain\Browsing\Controllers\BrowseTrashContentController;
|
||||||
use Domain\Homepage\Controllers\SendContactMessageController;
|
use Domain\Homepage\Controllers\SendContactMessageController;
|
||||||
|
use Domain\Browsing\Controllers\SearchFilesAndFoldersController;
|
||||||
|
use App\Users\Controllers\Authentication\RegisterAuthenticationController;
|
||||||
|
use App\Socialite\Controllers\SocialiteRedirectController;
|
||||||
|
use App\Socialite\Controllers\SocialiteCallbackController;
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
Route::apiResource('/page', PagesController::class);
|
Route::apiResource('/page', PagesController::class);
|
||||||
@@ -32,7 +35,13 @@ Route::post('/contact', SendContactMessageController::class);
|
|||||||
Route::get('/settings', GetSettingsValueController::class);
|
Route::get('/settings', GetSettingsValueController::class);
|
||||||
|
|
||||||
// Register user
|
// Register user
|
||||||
Route::post('/register', CreateNewUserAction::class);
|
Route::post('/register', RegisterAuthenticationController::class);
|
||||||
|
|
||||||
|
// Login via socialite
|
||||||
|
Route::group(['prefix' => 'socialite'], function () {
|
||||||
|
Route::get('/{provider}/redirect', SocialiteRedirectController::class);
|
||||||
|
Route::get('/{provider}/callback', SocialiteCallbackController::class);
|
||||||
|
});
|
||||||
|
|
||||||
// Password reset
|
// Password reset
|
||||||
Route::group(['prefix' => 'password'], function () {
|
Route::group(['prefix' => 'password'], function () {
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Socialite\Controllers;
|
||||||
|
|
||||||
|
use App\Users\Models\User;
|
||||||
|
use App\Users\DTO\CreateUserData;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
use App\Users\Actions\CreateNewUserAction;
|
||||||
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||||
|
|
||||||
|
class SocialiteCallbackController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected StatefulGuard $guard,
|
||||||
|
public CreateNewUserAction $createNewUser,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke($provider)
|
||||||
|
{
|
||||||
|
// Get socialite user
|
||||||
|
if (app()->runningInConsole()) {
|
||||||
|
$provider_user = Socialite::driver($provider)->user();
|
||||||
|
} else {
|
||||||
|
$provider_user = Socialite::driver($provider)->stateless()->user();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if user exist already
|
||||||
|
$user = User::whereEmail($provider_user->email)->first();
|
||||||
|
|
||||||
|
if($user) {
|
||||||
|
// Login User
|
||||||
|
$this->guard->login($user);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$data = CreateUserData::fromArray([
|
||||||
|
'name' => $provider_user->getname(),
|
||||||
|
'email' => $provider_user->getEmail(),
|
||||||
|
'avatar' => store_socialite_avatar($provider_user->getAvatar()),
|
||||||
|
'oauth_provider' => $provider,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create User
|
||||||
|
($this->createNewUser)($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response('Loged in', 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Socialite\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
|
||||||
|
class SocialiteRedirectController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke($provider)
|
||||||
|
{
|
||||||
|
$url = Socialite::driver($provider)->stateless()->redirect()->getTargetUrl();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'url' => $url
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@ namespace App\Users\Actions;
|
|||||||
|
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use App\Users\Models\UserSettings;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
use App\Users\Requests\RegisterUserRequest;
|
|
||||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
@@ -20,13 +20,14 @@ class CreateNewUserAction extends Controller
|
|||||||
/**
|
/**
|
||||||
* Validate and create a new user.
|
* Validate and create a new user.
|
||||||
*/
|
*/
|
||||||
public function __invoke(
|
public function __invoke($data)
|
||||||
RegisterUserRequest $request
|
{
|
||||||
): Application | ResponseFactory | Response {
|
|
||||||
$settings = get_settings([
|
$settings = get_settings([
|
||||||
'default_max_storage_amount', 'registration', 'user_verification',
|
'storage_default', 'registration', 'user_verification',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$is_socialite = is_null($data->password);
|
||||||
|
|
||||||
// Check if account registration is enabled
|
// Check if account registration is enabled
|
||||||
if (! intval($settings['registration'])) {
|
if (! intval($settings['registration'])) {
|
||||||
abort(401);
|
abort(401);
|
||||||
@@ -34,28 +35,33 @@ class CreateNewUserAction extends Controller
|
|||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'password' => bcrypt($request->input('password')),
|
'password' => $is_socialite ? null : bcrypt($data->password),
|
||||||
'email' => $request->input('email'),
|
'oauth_provider' => $data->oauth_provider,
|
||||||
|
'email' => $data->email,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Mark as verified if verification is disabled
|
UserSettings::unguard();
|
||||||
if (! intval($settings['user_verification'])) {
|
|
||||||
$user->markEmailAsVerified();
|
|
||||||
}
|
|
||||||
|
|
||||||
$user
|
$user
|
||||||
->settings()
|
->settings()
|
||||||
->create([
|
->create([
|
||||||
'name' => $request->input('name'),
|
'name' => $data->name,
|
||||||
|
'storage_capacity' => $settings['storage_default'],
|
||||||
|
'avatar' => $data->avatar,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
UserSettings::reguard();
|
||||||
|
|
||||||
|
// Mark as verified if verification is disabled
|
||||||
|
if ($is_socialite || ! intval($settings['user_verification'])) {
|
||||||
|
$user->markEmailAsVerified();
|
||||||
|
}
|
||||||
|
|
||||||
event(new Registered($user));
|
event(new Registered($user));
|
||||||
|
|
||||||
// Log in if verification is disabled
|
// Log in if verification is disabled
|
||||||
if (! intval($settings['user_verification'])) {
|
if ($is_socialite || ! intval($settings['user_verification'])) {
|
||||||
$this->guard->login($user);
|
$this->guard->login($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response('User registered successfully', 201);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ class CheckAccountController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => $user->settings->name,
|
'name' => $user->settings->name,
|
||||||
'avatar' => $user->settings->avatar,
|
'avatar' => $user->settings->avatar,
|
||||||
'verified' => $user->email_verified_at ? 1 : 0,
|
'verified' => $user->email_verified_at ? 1 : 0,
|
||||||
|
'oauth_provider' => $user->password ? null : $user->oauth_provider,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Users\Controllers\Authentication;
|
||||||
|
|
||||||
|
use App\Users\DTO\CreateUserData;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Users\Actions\CreateNewUserAction;
|
||||||
|
use App\Users\Requests\RegisterUserRequest;
|
||||||
|
|
||||||
|
class RegisterAuthenticationController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public CreateNewUserAction $createNewUser,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(RegisterUserRequest $request)
|
||||||
|
{
|
||||||
|
$data = CreateUserData::fromRequest($request);
|
||||||
|
|
||||||
|
($this->createNewUser)($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/App/Users/DTO/CreateUserData.php
Normal file
36
src/App/Users/DTO/CreateUserData.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Users\DTO;
|
||||||
|
|
||||||
|
use Spatie\DataTransferObject\DataTransferObject;
|
||||||
|
|
||||||
|
class CreateUserData extends DataTransferObject
|
||||||
|
{
|
||||||
|
public $name;
|
||||||
|
public $email;
|
||||||
|
public $password;
|
||||||
|
public $oauth_provider;
|
||||||
|
public $avatar;
|
||||||
|
|
||||||
|
public static function fromRequest($request): self
|
||||||
|
{
|
||||||
|
return new self([
|
||||||
|
'name' => $request->input('name'),
|
||||||
|
'email' => $request->input('email'),
|
||||||
|
'avatar' => $request->input('avatar') ?? null,
|
||||||
|
'password' => $request->input('password'),
|
||||||
|
'oauth_provider' => $request->input('oauth_provider') ?? null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromArray(array $array): self
|
||||||
|
{
|
||||||
|
return new self([
|
||||||
|
'name' => $array['name'] ?? null,
|
||||||
|
'email' => $array['email'],
|
||||||
|
'avatar' => $array['avatar'],
|
||||||
|
'password' => $array['password'] ?? null,
|
||||||
|
'oauth_provider' => $array['oauth_provider'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
|
'oauth_provider',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class UserResource extends JsonResource
|
|||||||
'email' => is_demo() ? obfuscate_email($this->email) : $this->email,
|
'email' => is_demo() ? obfuscate_email($this->email) : $this->email,
|
||||||
'role' => $this->role,
|
'role' => $this->role,
|
||||||
'two_factor_authentication' => $this->two_factor_secret ? true : false,
|
'two_factor_authentication' => $this->two_factor_secret ? true : false,
|
||||||
|
'socialite_account' => $this->password ? false : true,
|
||||||
'folders' => $this->folder_tree,
|
'folders' => $this->folder_tree,
|
||||||
'storage' => $this->storage,
|
'storage' => $this->storage,
|
||||||
'created_at' => format_date($this->created_at, '%d. %b. %Y'),
|
'created_at' => format_date($this->created_at, '%d. %b. %Y'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use ByteUnits\Metric;
|
use ByteUnits\Metric;
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Domain\Files\Models\File;
|
use Domain\Files\Models\File;
|
||||||
use Domain\Sharing\Models\Share;
|
use Domain\Sharing\Models\Share;
|
||||||
@@ -358,14 +359,7 @@ if (! function_exists('store_avatar')) {
|
|||||||
$intervention = Image::make($image->getRealPath());
|
$intervention = Image::make($image->getRealPath());
|
||||||
|
|
||||||
// Generate avatar sizes
|
// Generate avatar sizes
|
||||||
collect(config('vuefilemanager.avatar_sizes'))
|
generate_avatar_thumbnails($intervention, $avatar_name);
|
||||||
->each(function ($size) use ($intervention, $avatar_name) {
|
|
||||||
// fit thumbnail
|
|
||||||
$intervention->fit($size['size'], $size['size'])->stream();
|
|
||||||
|
|
||||||
// Store thumbnail to disk
|
|
||||||
Storage::put("avatars/{$size['name']}-{$avatar_name}", $intervention);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return path to image
|
// Return path to image
|
||||||
return $avatar_name;
|
return $avatar_name;
|
||||||
@@ -1021,4 +1015,46 @@ if (! function_exists('replace_occurrence')) {
|
|||||||
$string
|
$string
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(! function_exists('get_socialite_avatar')) {
|
||||||
|
/**
|
||||||
|
* Get socialite avatar create and store his thumbnails
|
||||||
|
*/
|
||||||
|
function store_socialite_avatar($avatar)
|
||||||
|
{
|
||||||
|
// Get image from external source
|
||||||
|
$image = Http::get($avatar)->body();
|
||||||
|
|
||||||
|
// Generate avatar name
|
||||||
|
$avatar_name = Str::uuid() . '.jpg';
|
||||||
|
|
||||||
|
// Create intervention image
|
||||||
|
$intervention = Image::make($image);
|
||||||
|
|
||||||
|
// Generate avatar sizes
|
||||||
|
generate_avatar_thumbnails($intervention, $avatar_name);
|
||||||
|
|
||||||
|
// Return name of image
|
||||||
|
return $avatar_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! function_exists('generate_avatar_thumbnails')) {
|
||||||
|
/**
|
||||||
|
* Create avatar thumbnails
|
||||||
|
*/
|
||||||
|
function generate_avatar_thumbnails($intervention, $avatar_name)
|
||||||
|
{
|
||||||
|
collect(config('vuefilemanager.avatar_sizes'))
|
||||||
|
->each(function ($size) use ($intervention, $avatar_name) {
|
||||||
|
|
||||||
|
// fit thumbnail
|
||||||
|
$intervention->fit($size['size'], $size['size'])->stream();
|
||||||
|
|
||||||
|
// Store thumbnail to disk
|
||||||
|
Storage::put("avatars/{$size['name']}-{$avatar_name}", $intervention);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
96
tests/App/Socialite/SocialiteTest.php
Normal file
96
tests/App/Socialite/SocialiteTest.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\App\Socialite;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
use Storage;
|
||||||
|
use App\Users\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Laravel\Socialite\Two\FacebookProvider;
|
||||||
|
use Laravel\Socialite\Contracts\Factory as Socialite;
|
||||||
|
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SocialiteTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_socialite_redirect()
|
||||||
|
{
|
||||||
|
$response = $this->get('api/socialite/google/redirect');
|
||||||
|
|
||||||
|
$this->assertStringContainsString('accounts.google.com/o/oauth2/auth', $response['url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_socialite_callback()
|
||||||
|
{
|
||||||
|
// Set default settings
|
||||||
|
DB::table('settings')->insert([
|
||||||
|
[
|
||||||
|
'name' => 'registration',
|
||||||
|
'value' => 1,
|
||||||
|
], [
|
||||||
|
'name' => 'storage_default',
|
||||||
|
'value' => 5,
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create fake image
|
||||||
|
$fakeImage = UploadedFile::fake()
|
||||||
|
->image('fake-avatar.jpg');
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'https://vuefilemanager.com/avatar.jpg' => Http::response($fakeImage->getContent()),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create fake user
|
||||||
|
$socialiteUser = $this->createMock(\Laravel\Socialite\Two\User::class);
|
||||||
|
$socialiteUser->token = 'fake_token';
|
||||||
|
$socialiteUser->id = 'fake_id';
|
||||||
|
$socialiteUser->name = 'Jane Doe';
|
||||||
|
$socialiteUser->email = 'howdy@hi5ve.digital';
|
||||||
|
$socialiteUser->avatar = 'https://vuefilemanager.com/avatar.jpg';
|
||||||
|
|
||||||
|
// Mock user with FB provider
|
||||||
|
$provider = $this->createMock(FacebookProvider::class);
|
||||||
|
$provider->expects($this->any())
|
||||||
|
->method('user')
|
||||||
|
->willReturn($socialiteUser);
|
||||||
|
|
||||||
|
// Mock socialite
|
||||||
|
$stub = $this->createMock(Socialite::class);
|
||||||
|
|
||||||
|
$stub->expects($this->any())
|
||||||
|
->method('driver')
|
||||||
|
->willReturn($provider);
|
||||||
|
|
||||||
|
// Replace Socialite Instance with mock
|
||||||
|
$this->app->instance(Socialite::class, $stub);
|
||||||
|
|
||||||
|
$this->getJson('/api/socialite/facebook/callback');
|
||||||
|
|
||||||
|
$this
|
||||||
|
->assertDatabaseHas('users', [
|
||||||
|
'email' => 'howdy@hi5ve.digital',
|
||||||
|
'oauth_provider' => 'facebook',
|
||||||
|
'password' => null,
|
||||||
|
])
|
||||||
|
->assertDatabaseHas('user_settings', [
|
||||||
|
'name' => 'Jane Doe',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::first();
|
||||||
|
|
||||||
|
collect(config('vuefilemanager.avatar_sizes'))
|
||||||
|
->each(
|
||||||
|
fn($size) => Storage::disk('local')
|
||||||
|
->assertExists("avatars/{$size['name']}-{$user->settings->getRawOriginal('avatar')}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user