You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.2 KiB
PHTML

4 years ago
<?php
4 years ago
namespace Modules\HttpHeaderAuth\Providers;
4 years ago
use Illuminate\Support\Facades\Password;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use App\User;
4 years ago
class HttpHeaderAuthServiceProvider extends ServiceProvider
4 years ago
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerConfig();
$this->registerViews();
$this->registerFactories();
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->hooks();
}
/**
* Module hooks.
*/
public function hooks()
{
\Eventy::addAction('middleware.web.custom_handle', function($request) {
if (!$request->user() && isset($_SERVER['HTTP_X_AUTH_EMAIL'])) {
$user = User::where('email',$_SERVER['HTTP_X_AUTH_EMAIL'])->first();
if (!isset($user)) {
$user = User::create([
"email" => $_SERVER['HTTP_X_AUTH_EMAIL'],
"first_name" => $_SERVER['HTTP_X_AUTH_USERNAME'],
"last_name" => ".",
"password" => str_random(64)
]);
}
if (isset($user->email)) {
\Auth::login($user);
}
}
}, 20, 1);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerTranslations();
}
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
4 years ago
__DIR__ . '/../Config/config.php' => config_path('httpheaderauth.php'),
4 years ago
], 'config');
$this->mergeConfigFrom(
4 years ago
__DIR__ . '/../Config/config.php', 'httpheaderauth'
4 years ago
);
}
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
4 years ago
$viewPath = resource_path('views/modules/httpheaderauth');
4 years ago
4 years ago
$sourcePath = __DIR__ . '/../Resources/views';
4 years ago
$this->publishes([
$sourcePath => $viewPath
4 years ago
], 'views');
4 years ago
$this->loadViewsFrom(array_merge(array_map(function ($path) {
4 years ago
return $path . '/modules/httpheaderauth';
}, \Config::get('view.paths')), [$sourcePath]), 'httpheaderauth');
4 years ago
}
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
4 years ago
$this->loadJsonTranslationsFrom(__DIR__ . '/../Resources/lang');
4 years ago
}
/**
* Register an additional directory of factories.
* @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66
*/
public function registerFactories()
{
4 years ago
if (!app()->environment('production')) {
4 years ago
app(Factory::class)->load(__DIR__ . '/../Database/factories');
}
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
}
}