mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-08 01:14:29 +01:00
Apply Laravel Pint fixes
This commit is contained in:
parent
e0f0afc505
commit
c8c1530b51
@ -15,9 +15,9 @@
|
||||
use App\Api\v1\Resources\TwoFAccountStoreResource;
|
||||
use App\Facades\Groups;
|
||||
use App\Facades\TwoFAccounts;
|
||||
use App\Helpers\Helpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Helpers\Helpers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
|
@ -30,8 +30,8 @@ public function rules()
|
||||
'required',
|
||||
'string',
|
||||
'max:32',
|
||||
Rule::unique('groups')->where(fn ($query) => $query->where('user_id', $this->user()->id))
|
||||
]
|
||||
Rule::unique('groups')->where(fn ($query) => $query->where('user_id', $this->user()->id)),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
|
@ -47,8 +47,8 @@ public function options(AssertionRequest $request) : Responsable|JsonResponse
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
new \App\Rules\CaseInsensitiveEmailExists
|
||||
]
|
||||
new \App\Rules\CaseInsensitiveEmailExists,
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'admin' => \App\Http\Middleware\AdminOnly::class,
|
||||
'admin' => \App\Http\Middleware\AdminOnly::class,
|
||||
'guest' => \App\Http\Middleware\RejectIfAuthenticated::class,
|
||||
'SkipIfAuthenticated' => \App\Http\Middleware\SkipIfAuthenticated::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AdminOnly
|
||||
{
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
@ -38,7 +38,7 @@ protected function authenticate($request, array $guards)
|
||||
// by the SetLanguage global middleware
|
||||
$lang = $this->auth->guard()->user()->preferences['lang'] ?? null;
|
||||
|
||||
if ($lang && in_array($lang, config('2fauth.locales')) && !App::isLocale($lang)) {
|
||||
if ($lang && in_array($lang, config('2fauth.locales')) && ! App::isLocale($lang)) {
|
||||
App::setLocale($lang);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Facades\Settings;
|
||||
use Carbon\Carbon;
|
||||
use Closure;
|
||||
use Illuminate\Http\Response;
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SetLanguage
|
||||
{
|
||||
@ -22,7 +22,7 @@ public function handle($request, Closure $next)
|
||||
// - No language is specified
|
||||
//
|
||||
// We honor the language requested in the header or we use the fallback one.
|
||||
// Note that if a user is authenticated later by the auth guard, the app locale
|
||||
// Note that if a user is authenticated later by the auth guard, the app locale
|
||||
// will be overriden if the user has set a specific language in its preferences.
|
||||
|
||||
$lang = config('app.fallback_locale');
|
||||
@ -33,13 +33,14 @@ public function handle($request, Closure $next)
|
||||
array_diff(explode(',', $accepted), ['*']),
|
||||
function ($langs, $langItem) {
|
||||
[$langLong, $weight] = array_merge(explode(';q=', $langItem), [1]);
|
||||
$langShort = substr($langLong, 0, 2);
|
||||
$langShort = substr($langLong, 0, 2);
|
||||
if (array_key_exists($langShort, $langs)) {
|
||||
if ($langs[$langShort] < $weight) {
|
||||
$langs[$langShort] = (float) $weight;
|
||||
}
|
||||
} else {
|
||||
$langs[$langShort] = (float) $weight;
|
||||
}
|
||||
else $langs[$langShort] = (float) $weight;
|
||||
|
||||
return $langs;
|
||||
},
|
||||
|
@ -395,8 +395,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc
|
||||
// First we instanciate the OTP generator
|
||||
try {
|
||||
$this->generator = Factory::loadFromProvisioningUri($isSteamTotp ? str_replace('otpauth://steam', 'otpauth://totp', $uri) : $uri);
|
||||
}
|
||||
catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) {
|
||||
} catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) {
|
||||
throw ValidationException::withMessages([
|
||||
'uri' => __('validation.custom.uri.regex', ['attribute' => 'uri']),
|
||||
]);
|
||||
@ -696,6 +695,9 @@ private function encryptOrReturn(mixed $value) : mixed
|
||||
return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Builder<TwoFAccount>
|
||||
*/
|
||||
public function buildSortQuery()
|
||||
{
|
||||
return static::query()->where('user_id', $this->user_id);
|
||||
|
@ -62,7 +62,7 @@ public function sendPasswordResetNotification($token)
|
||||
|
||||
/**
|
||||
* Get Preferences attribute
|
||||
*
|
||||
*
|
||||
* @param string $value
|
||||
* @return \Illuminate\Support\Collection<array-key, mixed>
|
||||
*/
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\Group;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class GroupPolicy
|
||||
|
@ -3,14 +3,12 @@
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
trait OwnershipTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Ownership of single item condition
|
||||
*
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param mixed $item
|
||||
* @return bool
|
||||
@ -22,10 +20,10 @@ protected function isOwnerOf(User $user, mixed $item)
|
||||
|
||||
/**
|
||||
* Ownership of collection condition
|
||||
*
|
||||
*
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @return bool
|
||||
@ -40,5 +38,4 @@ protected function isOwnerOfEach(User $user, $items)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class TwoFAccountPolicy
|
||||
@ -68,8 +67,6 @@ public function create(User $user)
|
||||
public function update(User $user, TwoFAccount $twofaccount)
|
||||
{
|
||||
return $this->isOwnerOf($user, $twofaccount);
|
||||
// ? Response::allow()
|
||||
// : Response::deny('You do not own this post.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,10 +5,10 @@
|
||||
use App\Extensions\RemoteUserProvider;
|
||||
use App\Extensions\WebauthnCredentialBroker;
|
||||
use App\Facades\Settings;
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Models\Group;
|
||||
use App\Policies\TwoFAccountPolicy;
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Policies\GroupPolicy;
|
||||
use App\Policies\TwoFAccountPolicy;
|
||||
use App\Services\Auth\ReverseProxyGuard;
|
||||
use Illuminate\Auth\Passwords\DatabaseTokenRepository;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
@ -31,11 +31,9 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
|
||||
foreach ($otpauthURIs as $key => $uri) {
|
||||
try {
|
||||
$twofaccounts[$key] = new TwoFAccount;
|
||||
$twofaccounts[$key]->fillWithURI($uri, str_starts_with($uri, 'otpauth://steam/'));
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
|
||||
$twofaccounts[$key] = new TwoFAccount;
|
||||
$twofaccounts[$key]->fillWithURI($uri, str_starts_with($uri, 'otpauth://steam/'));
|
||||
} catch (\Exception $exception) {
|
||||
Log::error(sprintf('Cannot instanciate a TwoFAccount object with OTP parameters from imported item #%s', $key));
|
||||
Log::debug($exception->getMessage());
|
||||
|
||||
|
@ -5,12 +5,11 @@
|
||||
use App\Exceptions\DbEncryptionException;
|
||||
use App\Models\Option;
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Throwable;
|
||||
|
||||
class SettingService
|
||||
@ -25,7 +24,7 @@ class SettingService
|
||||
/**
|
||||
* Cache duration
|
||||
*
|
||||
* @var int $minutes
|
||||
* @var int
|
||||
*/
|
||||
private int $minutes = 10;
|
||||
|
||||
@ -41,6 +40,7 @@ public function __construct()
|
||||
{
|
||||
$this->settings = Cache::remember(self::CACHE_ITEM_NAME, now()->addMinutes($this->minutes), function () {
|
||||
self::build();
|
||||
|
||||
return $this->settings;
|
||||
});
|
||||
}
|
||||
@ -130,14 +130,13 @@ private function build()
|
||||
});
|
||||
|
||||
// Merge customized values with app default values
|
||||
$settings = collect(config('2fauth.settings'))->merge($options); /** @phpstan-ignore-line */
|
||||
|
||||
$settings = collect(config('2fauth.settings'))->merge($options); /** @phpstan-ignore-line */
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and cache the options collection
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function buildAndCache()
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Factories\MigratorFactoryInterface;
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Helpers\Helpers;
|
||||
use App\Models\TwoFAccount;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@ -117,5 +117,4 @@ private static function markAsDuplicate(Collection $twofaccounts) : Collection
|
||||
|
||||
return $twofaccounts;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\FeatureTestCase;
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
namespace Tests\Feature\Services;
|
||||
|
||||
use App\Facades\Settings;
|
||||
use App\Services\SettingService;
|
||||
use App\Models\TwoFAccount;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use App\Services\SettingService;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\FeatureTestCase;
|
||||
|
||||
@ -174,7 +174,7 @@ public function test_all_returns_default_and_overloaded_settings()
|
||||
*/
|
||||
public function test_set_setting_persist_correct_value_in_db_and_cache()
|
||||
{
|
||||
$value = Settings::set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
|
||||
$value = Settings::set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
|
||||
$cached = Cache::get(SettingService::CACHE_ITEM_NAME); // returns a Collection
|
||||
|
||||
$this->assertDatabaseHas('options', [
|
||||
@ -378,7 +378,7 @@ public function test_cache_is_requested_at_instanciation()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function test_cache_is_updated_when_setting_is_set()
|
||||
{
|
||||
@ -392,7 +392,7 @@ public function test_cache_is_updated_when_setting_is_set()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function test_cache_is_updated_when_setting_is_deleted()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user