2021-04-02 19:48:41 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2022-06-27 01:39:01 +08:00
|
|
|
use App\Auth\NexusWebGuard;
|
|
|
|
|
use App\Auth\NexusWebUserProvider;
|
2022-11-08 19:06:37 +08:00
|
|
|
use App\Models\AudioCodec;
|
|
|
|
|
use App\Models\Category;
|
|
|
|
|
use App\Models\Codec;
|
|
|
|
|
use App\Models\Icon;
|
|
|
|
|
use App\Models\Media;
|
|
|
|
|
use App\Models\Plugin;
|
|
|
|
|
use App\Models\Processing;
|
|
|
|
|
use App\Models\SearchBox;
|
|
|
|
|
use App\Models\SecondIcon;
|
|
|
|
|
use App\Models\Source;
|
|
|
|
|
use App\Models\Standard;
|
|
|
|
|
use App\Models\Team;
|
2022-06-03 03:42:53 +08:00
|
|
|
use App\Models\User;
|
2022-11-08 19:06:37 +08:00
|
|
|
use App\Policies\CodecPolicy;
|
2021-04-02 19:48:41 +08:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2022-06-03 03:42:53 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-04-02 19:48:41 +08:00
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The policy mappings for the application.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $policies = [
|
2022-11-08 19:06:37 +08:00
|
|
|
SearchBox::class => CodecPolicy::class,
|
|
|
|
|
Category::class => CodecPolicy::class,
|
|
|
|
|
Icon::class => CodecPolicy::class,
|
|
|
|
|
SecondIcon::class => CodecPolicy::class,
|
|
|
|
|
|
|
|
|
|
Codec::class => CodecPolicy::class,
|
|
|
|
|
AudioCodec::class => CodecPolicy::class,
|
|
|
|
|
Source::class => CodecPolicy::class,
|
|
|
|
|
Media::class => CodecPolicy::class,
|
|
|
|
|
Standard::class => CodecPolicy::class,
|
|
|
|
|
Team::class => CodecPolicy::class,
|
|
|
|
|
Processing::class => CodecPolicy::class,
|
|
|
|
|
|
|
|
|
|
Plugin::class => CodecPolicy::class,
|
2021-04-02 19:48:41 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register any authentication / authorization services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
|
|
|
|
$this->registerPolicies();
|
|
|
|
|
|
2022-06-03 03:42:53 +08:00
|
|
|
Auth::viaRequest('nexus-cookie', function (Request $request) {
|
|
|
|
|
return $this->getUserByCookie($request->cookie());
|
|
|
|
|
});
|
2022-06-27 01:39:01 +08:00
|
|
|
|
|
|
|
|
Auth::extend('nexus-web', function ($app, $name, array $config) {
|
|
|
|
|
// 返回 Illuminate\Contracts\Auth\Guard 的实例 ...
|
2022-07-12 17:42:26 +08:00
|
|
|
return new NexusWebGuard($app['request'], new NexusWebUserProvider());
|
2022-06-27 01:39:01 +08:00
|
|
|
});
|
2022-07-12 17:42:26 +08:00
|
|
|
|
2022-06-03 03:42:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUserByCookie($cookie)
|
|
|
|
|
{
|
|
|
|
|
if (empty($cookie["c_secure_pass"]) || empty($cookie["c_secure_uid"]) || empty($cookie["c_secure_login"])) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$b_id = base64($cookie["c_secure_uid"],false);
|
|
|
|
|
$id = intval($b_id ?? 0);
|
|
|
|
|
if (!$id || !is_valid_id($id) || strlen($cookie["c_secure_pass"]) != 32) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$user = User::query()->find($id);
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if ($cookie["c_secure_login"] == base64("yeah")) {
|
2022-11-08 19:06:37 +08:00
|
|
|
/**
|
|
|
|
|
* Not IP related
|
|
|
|
|
* @since 1.8.0
|
|
|
|
|
*/
|
|
|
|
|
if ($cookie["c_secure_pass"] != md5($user->passhash)) {
|
2022-06-03 03:42:53 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($cookie["c_secure_pass"] !== md5($user->passhash)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $user;
|
2021-04-02 19:48:41 +08:00
|
|
|
}
|
|
|
|
|
}
|