added auto login

This commit is contained in:
vedatakd 2021-04-01 16:35:46 +03:00
parent 78fc01eaf2
commit 1a2d74ea38
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php namespace Visiosoft\ProfileModule\Command;
use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface;
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
use Anomaly\UsersModule\User\UserActivator;
use Illuminate\Support\Facades\Auth;
class AuthAuto
{
protected $token;
public function __construct($token)
{
$this->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);
}
}
}

View File

@ -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('/');
}
}

View File

@ -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' => [