mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
added auto login
This commit is contained in:
parent
78fc01eaf2
commit
1a2d74ea38
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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('/');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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' => [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user