From 289b557754b2f76f25e3ad958500328999b97a1e Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Sun, 19 May 2024 18:07:05 +0300 Subject: [PATCH] Add Laravel point workflow and lint all files --- .github/workflows/lint.yml | 33 ++ composer.json | 1 + composer.lock | 461 +++++++++++++----- config/devdojo/auth/appearance.php | 4 +- config/devdojo/auth/descriptions.php | 6 +- config/devdojo/auth/fields.php | 14 +- config/devdojo/auth/language.php | 12 +- config/devdojo/auth/pages.php | 8 +- config/devdojo/auth/providers.php | 32 +- config/devdojo/auth/settings.php | 2 +- ..._000001_add_user_social_provider_table.php | 4 +- ..._update_passwords_field_to_be_nullable.php | 2 +- ..._07_000003_add_two_factor_auth_columns.php | 5 +- routes/web.php | 12 +- .../DisableTwoFactorAuthentication.php | 2 +- .../GenerateNewRecoveryCodes.php | 11 +- .../GenerateQrCodeAndSecretKey.php | 13 +- src/AuthServiceProvider.php | 25 +- src/Helper.php | 25 +- src/Http/Controllers/LogoutController.php | 5 +- src/Http/Controllers/SocialController.php | 30 +- src/Http/Middleware/TwoFactorChallenged.php | 3 +- src/Http/Middleware/TwoFactorEnabled.php | 3 +- src/Installer.php | 10 +- src/Livewire/Setup/Alignment.php | 25 +- src/Livewire/Setup/Background.php | 39 +- src/Livewire/Setup/Color.php | 29 +- src/Livewire/Setup/Css.php | 13 +- src/Livewire/Setup/Favicon.php | 32 +- src/Livewire/Setup/Logo.php | 50 +- src/Models/SocialProvider.php | 5 +- src/Models/SocialProviderUser.php | 7 +- src/Models/User.php | 7 +- .../HasConditionalEmailVerification.php | 4 +- src/Traits/HasConfigs.php | 19 +- src/Traits/HasSocialProviders.php | 9 +- tests/Datasets/Urls.php | 4 +- tests/Feature/AuthenticationTest.php | 9 +- tests/Feature/TwoFactorTest.php | 25 +- tests/Pest.php | 12 +- tests/TestCase.php | 2 +- 41 files changed, 660 insertions(+), 354 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c2fa64b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,33 @@ +name: Fix Code Style + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.2] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: json, dom, curl, libxml, mbstring + coverage: none + + - name: Install Pint + run: composer global require laravel/pint + + - name: Run Pint + run: pint + + - name: Commit linted files + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Fixes coding style" diff --git a/composer.json b/composer.json index 93fc13b..509ec8e 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "bacon/bacon-qr-code": "^2.0" }, "require-dev": { + "laravel/pint": "^1.15", "orchestra/testbench": "^9.0", "pestphp/pest": "^2.34", "pestphp/pest-plugin-laravel": "^2.4" diff --git a/composer.lock b/composer.lock index f07bc34..8a4dfeb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,62 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ebd8d254eb7a5c5d40a98094259b6883", + "content-hash": "677cb059648cc72bdadef766a2db5904", "packages": [ + { + "name": "bacon/bacon-qr-code", + "version": "2.0.8", + "source": { + "type": "git", + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/8674e51bb65af933a5ffaf1c308a660387c35c22", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22", + "shasum": "" + }, + "require": { + "dasprid/enum": "^1.0.3", + "ext-iconv": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phly/keep-a-changelog": "^2.1", + "phpunit/phpunit": "^7 | ^8 | ^9", + "spatie/phpunit-snapshot-assertions": "^4.2.9", + "squizlabs/php_codesniffer": "^3.4" + }, + "suggest": { + "ext-imagick": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-4": { + "BaconQrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "support": { + "issues": "https://github.com/Bacon/BaconQrCode/issues", + "source": "https://github.com/Bacon/BaconQrCode/tree/2.0.8" + }, + "time": "2022-12-07T17:46:57+00:00" + }, { "name": "blade-ui-kit/blade-icons", "version": "1.6.0", @@ -341,6 +395,120 @@ ], "time": "2024-04-08T19:02:17+00:00" }, + { + "name": "dasprid/enum", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/6faf451159fb8ba4126b925ed2d78acfce0dc016", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016", + "shasum": "" + }, + "require": { + "php": ">=7.1 <9.0" + }, + "require-dev": { + "phpunit/phpunit": "^7 | ^8 | ^9", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "support": { + "issues": "https://github.com/DASPRiD/Enum/issues", + "source": "https://github.com/DASPRiD/Enum/tree/1.0.5" + }, + "time": "2023-08-25T16:18:39+00:00" + }, + { + "name": "devdojo/config-writer", + "version": "0.0.7", + "source": { + "type": "git", + "url": "https://github.com/thedevdojo/config-writer.git", + "reference": "f4c7e88222634a989908123225af55ed9ce0bbfa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thedevdojo/config-writer/zipball/f4c7e88222634a989908123225af55ed9ce0bbfa", + "reference": "f4c7e88222634a989908123225af55ed9ce0bbfa", + "shasum": "" + }, + "require": { + "illuminate/config": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*|13.*|14.*|15.*|16.*|17.*|18.*|19.*|20.*", + "php": ">=7.1.0" + }, + "require-dev": { + "orchestra/testbench": "3.8", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Devdojo\\ConfigWriter\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Devdojo\\ConfigWriter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexey Bobkov", + "email": "aleksey.bobkov@gmail.com" + }, + { + "name": "Samuel Georges", + "email": "daftspunky@gmail.com" + } + ], + "description": "Laravel provider to be able to rewrite configuration", + "homepage": "http://octobercms.com", + "keywords": [ + "config", + "laravel", + "october", + "october cms", + "provider", + "write" + ], + "support": { + "source": "https://github.com/thedevdojo/config-writer/tree/0.0.7" + }, + "time": "2024-05-09T23:52:18+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -2759,62 +2927,6 @@ }, "time": "2024-01-17T16:50:36+00:00" }, - { - "name": "nikic/php-parser", - "version": "v4.19.1", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=7.1" - }, - "require-dev": { - "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.9-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "support": { - "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" - }, - "time": "2024-03-17T08:10:35+00:00" - }, { "name": "nunomaduro/termwind", "version": "v2.0.1", @@ -3205,6 +3317,58 @@ ], "time": "2024-03-03T02:14:58+00:00" }, + { + "name": "pragmarx/google2fa", + "version": "v8.0.1", + "source": { + "type": "git", + "url": "https://github.com/antonioribeiro/google2fa.git", + "reference": "80c3d801b31fe165f8fe99ea085e0a37834e1be3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antonioribeiro/google2fa/zipball/80c3d801b31fe165f8fe99ea085e0a37834e1be3", + "reference": "80c3d801b31fe165f8fe99ea085e0a37834e1be3", + "shasum": "" + }, + "require": { + "paragonie/constant_time_encoding": "^1.0|^2.0", + "php": "^7.1|^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.18", + "phpunit/phpunit": "^7.5.15|^8.5|^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "PragmaRX\\Google2FA\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Antonio Carlos Ribeiro", + "email": "acr@antoniocarlosribeiro.com", + "role": "Creator & Designer" + } + ], + "description": "A One Time Password Authentication package, compatible with Google Authenticator.", + "keywords": [ + "2fa", + "Authentication", + "Two Factor Authentication", + "google2fa" + ], + "support": { + "issues": "https://github.com/antonioribeiro/google2fa/issues", + "source": "https://github.com/antonioribeiro/google2fa/tree/v8.0.1" + }, + "time": "2022-06-13T21:57:56+00:00" + }, { "name": "psr/clock", "version": "1.0.0", @@ -6409,67 +6573,6 @@ "source": "https://github.com/webmozarts/assert/tree/1.11.0" }, "time": "2022-06-03T18:03:27+00:00" - }, - { - "name": "winter/laravel-config-writer", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/wintercms/laravel-config-writer.git", - "reference": "9b5d016beb0cbbfff4f1ee2d8184d6652417005e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/wintercms/laravel-config-writer/zipball/9b5d016beb0cbbfff4f1ee2d8184d6652417005e", - "reference": "9b5d016beb0cbbfff4f1ee2d8184d6652417005e", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^4.10", - "php": "^7.4.0 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.6", - "phpunit/phpunit": "^9.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Winter\\LaravelConfigWriter\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jack Wilkinson", - "email": "me@jaxwilko.com", - "role": "Original author" - }, - { - "name": "Winter CMS Maintainers", - "homepage": "https://wintercms.com", - "role": "Maintainers" - } - ], - "description": "Utility to create and update Laravel config and .env files", - "support": { - "issues": "https://github.com/wintercms/laravel-config-writer/issues", - "source": "https://github.com/wintercms/laravel-config-writer/tree/v1.1.0" - }, - "funding": [ - { - "url": "https://github.com/wintercms", - "type": "github" - }, - { - "url": "https://opencollective.com/wintercms", - "type": "open_collective" - } - ], - "time": "2023-08-09T15:37:13+00:00" } ], "packages-dev": [ @@ -7000,6 +7103,72 @@ }, "time": "2024-03-08T09:58:59+00:00" }, + { + "name": "laravel/pint", + "version": "v1.15.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/3600b5d17aff52f6100ea4921849deacbbeb8656", + "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.54.0", + "illuminate/view": "^10.48.8", + "larastan/larastan": "^2.9.5", + "laravel-zero/framework": "^10.3.0", + "mockery/mockery": "^1.6.11", + "nunomaduro/termwind": "^1.15.1", + "pestphp/pest": "^2.34.7" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2024-04-30T15:02:26+00:00" + }, { "name": "laravel/tinker", "version": "v2.9.0", @@ -7208,6 +7377,62 @@ ], "time": "2023-03-08T13:26:56+00:00" }, + { + "name": "nikic/php-parser", + "version": "v4.19.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.1" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" + }, + "time": "2024-03-17T08:10:35+00:00" + }, { "name": "nunomaduro/collision", "version": "v8.1.1", diff --git a/config/devdojo/auth/appearance.php b/config/devdojo/auth/appearance.php index cffce7b..b31d35e 100644 --- a/config/devdojo/auth/appearance.php +++ b/config/devdojo/auth/appearance.php @@ -22,11 +22,11 @@ 'button' => '#09090b', 'button_text' => '#ffffff', 'input_text' => '', - 'input_border' => '#212936' + 'input_border' => '#212936', ], 'alignment' => [ 'heading' => 'center', - 'container' => 'center' + 'container' => 'center', ], 'favicon' => [ 'light' => '/auth/img/favicon.png', diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index 0e90cf4..2f95df0 100644 --- a/config/devdojo/auth/descriptions.php +++ b/config/devdojo/auth/descriptions.php @@ -11,6 +11,6 @@ 'registration_require_email_verification' => 'During registration, require users to verify their email.', 'enable_branding' => 'This will toggle on/off the Auth branding at the bottom of each auth screen. Consider leaving on to support and help grow this project.', 'dev_mode' => 'This is for development mode, when set in Dev Mode Assets will be loaded from Vite', - 'enable_2fa' => 'Enable the ability for users to turn on Two Factor Authentication' - ] -]; \ No newline at end of file + 'enable_2fa' => 'Enable the ability for users to turn on Two Factor Authentication', + ], +]; diff --git a/config/devdojo/auth/fields.php b/config/devdojo/auth/fields.php index e506218..ba2ccfc 100644 --- a/config/devdojo/auth/fields.php +++ b/config/devdojo/auth/fields.php @@ -11,20 +11,20 @@ 'selected' => 'svg', 'options' => [ 'svg', - 'image' + 'image', ], ], // image, svg 'src' => '', - 'height' => '36' + 'height' => '36', ], 'heading' => [ - 'align' => 'center' + 'align' => 'center', ], 'login' => [ - 'show_subheadline' => false + 'show_subheadline' => false, ], 'register' => [ 'show_subheadline' => false, - ] - ] -]; \ No newline at end of file + ], + ], +]; diff --git a/config/devdojo/auth/language.php b/config/devdojo/auth/language.php index 88bf008..a7b16d9 100644 --- a/config/devdojo/auth/language.php +++ b/config/devdojo/auth/language.php @@ -8,19 +8,19 @@ 'page_title' => 'Sign in', 'headline' => 'Sign in', 'subheadline' => 'Login to your account below', - 'show_subheadline' => false + 'show_subheadline' => false, ], 'register' => [ 'page_title' => 'Sign up', 'headline' => 'Sign up', 'subheadline' => 'Register for your free account below.', - 'show_subheadline' => false + 'show_subheadline' => false, ], 'verify' => [ 'page_title' => 'Verify Your Account', 'headline' => 'Verify your email address', 'subheadline' => 'Before you can proceed you must verify your email.', - 'show_subheadline' => false + 'show_subheadline' => false, ], 'twoFactorChallenge' => [ 'page_title' => 'Two Factor Challenge', @@ -29,6 +29,6 @@ 'show_subheadline_auth' => false, 'headline_recovery' => 'Recovery Code', 'subheadline_recovery' => 'Please confirm access to your account by entering one of your emergency recovery codes.', - 'show_subheadline_recovery' => false - ] -]; \ No newline at end of file + 'show_subheadline_recovery' => false, + ], +]; diff --git a/config/devdojo/auth/pages.php b/config/devdojo/auth/pages.php index e572dc3..ecfe03e 100644 --- a/config/devdojo/auth/pages.php +++ b/config/devdojo/auth/pages.php @@ -8,18 +8,18 @@ 'name' => 'Login', 'route_name' => 'auth.login', 'description' => 'Add login description here', - 'url' => '/auth/login' + 'url' => '/auth/login', ], 'register' => [ 'name' => 'Register', 'route_name' => 'auth.register', 'description' => 'Add registration description here', - 'url' => '/auth/register' + 'url' => '/auth/register', ], 'verify' => [ 'name' => 'Verify', 'route_name' => 'auth.verify', 'description' => 'Add verify description here', - 'url' => '/auth/verify' + 'url' => '/auth/verify', ], -]; \ No newline at end of file +]; diff --git a/config/devdojo/auth/providers.php b/config/devdojo/auth/providers.php index 2ee4f05..7a6be7d 100644 --- a/config/devdojo/auth/providers.php +++ b/config/devdojo/auth/providers.php @@ -9,7 +9,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('FACEBOOK_CLIENT_ID'), - 'client_secret' => env('FACEBOOK_CLIENT_SECRET') + 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), ], 'twitter' => [ 'name' => 'Twitter', @@ -19,7 +19,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('TWITTER_CLIENT_ID'), - 'client_secret' => env('TWITTER_CLIENT_SECRET') + 'client_secret' => env('TWITTER_CLIENT_SECRET'), ], 'linkedin' => [ 'name' => 'LinkedIn', @@ -29,7 +29,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('LINKEDIN_CLIENT_ID'), - 'client_secret' => env('LINKEDIN_CLIENT_SECRET') + 'client_secret' => env('LINKEDIN_CLIENT_SECRET'), ], 'google' => [ 'name' => 'Google', @@ -39,7 +39,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('GOOGLE_CLIENT_ID'), - 'client_secret' => env('GOOGLE_CLIENT_SECRET') + 'client_secret' => env('GOOGLE_CLIENT_SECRET'), ], 'github' => [ 'name' => 'Github', @@ -49,7 +49,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('GITHUB_CLIENT_ID'), - 'client_secret' => env('GITHUB_CLIENT_SECRET') + 'client_secret' => env('GITHUB_CLIENT_SECRET'), ], 'gitlab' => [ 'name' => 'GitLab', @@ -59,7 +59,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('GITLAB_CLIENT_ID'), - 'client_secret' => env('GITLAB_CLIENT_SECRET') + 'client_secret' => env('GITLAB_CLIENT_SECRET'), ], 'bitbucket' => [ 'name' => 'Bitbucket', @@ -69,7 +69,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('BITBUCKET_CLIENT_ID'), - 'client_secret' => env('BITBUCKET_CLIENT_SECRET') + 'client_secret' => env('BITBUCKET_CLIENT_SECRET'), ], 'slack' => [ 'name' => 'Slack', @@ -79,7 +79,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('SLACK_CLIENT_ID'), - 'client_secret' => env('SLACK_CLIENT_SECRET') + 'client_secret' => env('SLACK_CLIENT_SECRET'), ], 'apple' => [ 'name' => 'Apple', @@ -89,7 +89,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('APPLE_CLIENT_ID'), - 'client_secret' => env('APPLE_CLIENT_SECRET') + 'client_secret' => env('APPLE_CLIENT_SECRET'), ], 'microsoft' => [ 'name' => 'Microsoft', @@ -99,7 +99,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('MICROSOFT_CLIENT_ID'), - 'client_secret' => env('MICROSOFT_CLIENT_SECRET') + 'client_secret' => env('MICROSOFT_CLIENT_SECRET'), ], 'pinterest' => [ 'name' => 'Pinterest', @@ -109,7 +109,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('PINTEREST_CLIENT_ID'), - 'client_secret' => env('PINTEREST_CLIENT_SECRET') + 'client_secret' => env('PINTEREST_CLIENT_SECRET'), ], 'reddit' => [ 'name' => 'Reddit', @@ -119,7 +119,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('REDDIT_CLIENT_ID'), - 'client_secret' => env('REDDIT_CLIENT_SECRET') + 'client_secret' => env('REDDIT_CLIENT_SECRET'), ], 'tiktok' => [ 'name' => 'TikTok', @@ -129,7 +129,7 @@ 'active' => false, 'svg' => '', 'client_id' => env('TIKTOK_CLIENT_ID'), - 'client_secret' => env('TIKTOK_CLIENT_SECRET') + 'client_secret' => env('TIKTOK_CLIENT_SECRET'), ], 'twitch' => [ 'name' => 'Twitch', @@ -139,6 +139,6 @@ 'active' => false, 'svg' => '', 'client_id' => env('TWITCH_CLIENT_ID'), - 'client_secret' => env('TWITCH_CLIENT_SECRET') - ] -]; \ No newline at end of file + 'client_secret' => env('TWITCH_CLIENT_SECRET'), + ], +]; diff --git a/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index 88d8de1..8467c3e 100644 --- a/config/devdojo/auth/settings.php +++ b/config/devdojo/auth/settings.php @@ -11,4 +11,4 @@ 'enable_branding' => true, 'dev_mode' => false, 'enable_2fa' => false, // Enable or disable 2FA functionality globally -]; \ No newline at end of file +]; diff --git a/database/migrations/2024_04_24_000001_add_user_social_provider_table.php b/database/migrations/2024_04_24_000001_add_user_social_provider_table.php index a548755..0c9a24e 100644 --- a/database/migrations/2024_04_24_000001_add_user_social_provider_table.php +++ b/database/migrations/2024_04_24_000001_add_user_social_provider_table.php @@ -13,8 +13,8 @@ public function up(): void { Schema::create('social_provider_user', function (Blueprint $table) { $table->foreignId('user_id')->constrained()->onDelete('cascade'); - $table->string('provider_slug'); // maps to providers slug in the devdojo.auth.providers - + $table->string('provider_slug'); // maps to providers slug in the devdojo.auth.providers + $table->string('provider_user_id'); $table->string('nickname')->nullable(); $table->string('name')->nullable(); diff --git a/database/migrations/2024_04_24_000002_update_passwords_field_to_be_nullable.php b/database/migrations/2024_04_24_000002_update_passwords_field_to_be_nullable.php index ad32c11..ece8fc8 100644 --- a/database/migrations/2024_04_24_000002_update_passwords_field_to_be_nullable.php +++ b/database/migrations/2024_04_24_000002_update_passwords_field_to_be_nullable.php @@ -27,4 +27,4 @@ public function down() $table->string('name')->nullable(false)->change(); }); } -}; \ No newline at end of file +}; diff --git a/database/migrations/2024_05_07_000003_add_two_factor_auth_columns.php b/database/migrations/2024_05_07_000003_add_two_factor_auth_columns.php index 15429bd..6f8ab66 100644 --- a/database/migrations/2024_05_07_000003_add_two_factor_auth_columns.php +++ b/database/migrations/2024_05_07_000003_add_two_factor_auth_columns.php @@ -3,7 +3,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -use Laravel\Fortify\Fortify; return new class extends Migration { @@ -37,8 +36,8 @@ public function down(): void $table->dropColumn([ 'two_factor_secret', 'two_factor_recovery_codes', - 'two_factor_confirmed_at' + 'two_factor_confirmed_at', ]); }); } -}; \ No newline at end of file +}; diff --git a/routes/web.php b/routes/web.php index 19b8584..76a3760 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,13 +1,10 @@ name('login'); @@ -15,10 +12,10 @@ // define the logout route Route::middleware(['auth', 'web'])->group(function () { - + Route::post('/auth/logout', LogoutController::class) ->name('logout'); - + Route::get('/auth/verify-email/{id}/{hash}', VerifyEmailController::class) ->middleware(['signed', 'throttle:6,1']) ->name('verification.verify'); @@ -27,9 +24,8 @@ }); - Route::middleware(['web'])->group(function () { // Add social routes Route::get('auth/{driver}/redirect', [SocialController::class, 'redirect']); Route::get('auth/{driver}/callback', [SocialController::class, 'callback']); -}); \ No newline at end of file +}); diff --git a/src/Actions/TwoFactorAuth/DisableTwoFactorAuthentication.php b/src/Actions/TwoFactorAuth/DisableTwoFactorAuthentication.php index 46a3198..8be7ea2 100644 --- a/src/Actions/TwoFactorAuth/DisableTwoFactorAuthentication.php +++ b/src/Actions/TwoFactorAuth/DisableTwoFactorAuthentication.php @@ -20,7 +20,7 @@ public function __invoke($user) $user->forceFill([ 'two_factor_secret' => null, 'two_factor_recovery_codes' => null, - 'two_factor_confirmed_at' => null + 'two_factor_confirmed_at' => null, ])->save(); TwoFactorAuthenticationDisabled::dispatch($user); diff --git a/src/Actions/TwoFactorAuth/GenerateNewRecoveryCodes.php b/src/Actions/TwoFactorAuth/GenerateNewRecoveryCodes.php index c599b69..98c0616 100644 --- a/src/Actions/TwoFactorAuth/GenerateNewRecoveryCodes.php +++ b/src/Actions/TwoFactorAuth/GenerateNewRecoveryCodes.php @@ -2,8 +2,8 @@ namespace Devdojo\Auth\Actions\TwoFactorAuth; -use Illuminate\Support\Str; use Illuminate\Support\Collection; +use Illuminate\Support\Str; class GenerateNewRecoveryCodes { @@ -13,14 +13,15 @@ class GenerateNewRecoveryCodes * @param mixed $user * @return void */ - public function __invoke($user) : Collection + public function __invoke($user): Collection { return Collection::times(8, function () { - return $this->generate(); - }); + return $this->generate(); + }); } - public function generate(){ + public function generate() + { return Str::random(10).'-'.Str::random(10); } } diff --git a/src/Actions/TwoFactorAuth/GenerateQrCodeAndSecretKey.php b/src/Actions/TwoFactorAuth/GenerateQrCodeAndSecretKey.php index 2e9f2c6..1ed2765 100644 --- a/src/Actions/TwoFactorAuth/GenerateQrCodeAndSecretKey.php +++ b/src/Actions/TwoFactorAuth/GenerateQrCodeAndSecretKey.php @@ -2,11 +2,11 @@ namespace Devdojo\Auth\Actions\TwoFactorAuth; -use PragmaRX\Google2FA\Google2FA; -use BaconQrCode\Renderer\ImageRenderer; use BaconQrCode\Renderer\Image\ImagickImageBackEnd; +use BaconQrCode\Renderer\ImageRenderer; use BaconQrCode\Renderer\RendererStyle\RendererStyle; use BaconQrCode\Writer; +use PragmaRX\Google2FA\Google2FA; class GenerateQrCodeAndSecretKey { @@ -16,7 +16,7 @@ class GenerateQrCodeAndSecretKey * @param mixed $user * @return void */ - public function __invoke($user) : array + public function __invoke($user): array { $google2fa = new Google2FA(); @@ -31,18 +31,17 @@ public function __invoke($user) : array $user->email, $secret_key ); - + $writer = new Writer( new ImageRenderer( new RendererStyle(800), new ImagickImageBackEnd() ) ); - - $qrcode_image = base64_encode($writer->writeString($g2faUrl)); + $qrcode_image = base64_encode($writer->writeString($g2faUrl)); return [$qrcode_image, $secret_key]; } -} \ No newline at end of file +} diff --git a/src/AuthServiceProvider.php b/src/AuthServiceProvider.php index 6d99b09..7f82714 100644 --- a/src/AuthServiceProvider.php +++ b/src/AuthServiceProvider.php @@ -2,16 +2,15 @@ namespace Devdojo\Auth; -use Livewire\Livewire; -use Livewire\Volt\Volt; -use Laravel\Folio\Folio; +use Devdojo\Auth\Http\Middleware\TwoFactorChallenged; +use Devdojo\Auth\Http\Middleware\TwoFactorEnabled; use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; +use Laravel\Folio\Folio; +use Livewire\Livewire; +use Livewire\Volt\Volt; use PragmaRX\Google2FA\Google2FA; -use Illuminate\Support\Facades\Route; -use Devdojo\Auth\Http\Middleware\TwoFactorChallenged; -use Devdojo\Auth\Http\Middleware\TwoFactorEnabled; class AuthServiceProvider extends ServiceProvider { @@ -20,7 +19,7 @@ class AuthServiceProvider extends ServiceProvider */ public function boot() { - + Route::middlewareGroup('two-factor-challenged', [TwoFactorChallenged::class]); Route::middlewareGroup('two-factor-enabled', [TwoFactorEnabled::class]); @@ -75,8 +74,9 @@ public function boot() //app()->register(\October\Rain\Config\ServiceProvider::class); } - private function registerAuthFolioDirectory(){ - $pagesDirectory = __DIR__ . '/../resources/views/pages'; + private function registerAuthFolioDirectory() + { + $pagesDirectory = __DIR__.'/../resources/views/pages'; if (File::exists($pagesDirectory)) { Folio::path($pagesDirectory)->middleware([ '*' => [ @@ -86,9 +86,10 @@ private function registerAuthFolioDirectory(){ } } - private function registerVoltDirectory(){ + private function registerVoltDirectory() + { Volt::mount([ - __DIR__ . '/../resources/views/pages' + __DIR__.'/../resources/views/pages', ]); } diff --git a/src/Helper.php b/src/Helper.php index 124c777..b781a31 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -5,31 +5,36 @@ class Helper { // Build your next great package. - public static function activeProviders(){ + public static function activeProviders() + { $providers = config('devdojo.auth.providers'); $activeProviders = []; - foreach($providers as $slug => $provider){ - if($provider['active']){ - $activeProviders[$slug] = (object)$provider; + foreach ($providers as $slug => $provider) { + if ($provider['active']) { + $activeProviders[$slug] = (object) $provider; } } + return $activeProviders; } - public static function convertSlugToTitle($slug){ - $readable = str_replace('_', ' ', str_replace('-', ' ', $slug)); - return ucwords($readable); + public static function convertSlugToTitle($slug) + { + $readable = str_replace('_', ' ', str_replace('-', ' ', $slug)); + + return ucwords($readable); } - public static function convertHexToRGBString($hex){ + public static function convertHexToRGBString($hex) + { // Remove the '#' character if present $hex = str_replace('#', '', $hex); // Ensure the hex string is properly formatted if (strlen($hex) === 3) { - $hex = str_repeat($hex[0], 2) . str_repeat($hex[1], 2) . str_repeat($hex[2], 2); + $hex = str_repeat($hex[0], 2).str_repeat($hex[1], 2).str_repeat($hex[2], 2); } elseif (strlen($hex) !== 6) { - throw new \Exception("Invalid hex color length"); + throw new \Exception('Invalid hex color length'); } // Split the hex color into its RGB components diff --git a/src/Http/Controllers/LogoutController.php b/src/Http/Controllers/LogoutController.php index d822c5f..4a21dc6 100644 --- a/src/Http/Controllers/LogoutController.php +++ b/src/Http/Controllers/LogoutController.php @@ -2,16 +2,15 @@ namespace Devdojo\Auth\Http\Controllers; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Auth; class LogoutController { public function __invoke(): RedirectResponse { Auth::logout(); + return redirect()->route('home'); } - } diff --git a/src/Http/Controllers/SocialController.php b/src/Http/Controllers/SocialController.php index ce666ad..8fb629a 100644 --- a/src/Http/Controllers/SocialController.php +++ b/src/Http/Controllers/SocialController.php @@ -3,19 +3,19 @@ namespace Devdojo\Auth\Http\Controllers; use App\Models\User; -use Illuminate\Support\Facades\DB; +use Devdojo\Auth\Models\SocialProvider; +use Devdojo\Auth\Models\SocialProviderUser; use Illuminate\Support\Facades\Auth; -use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Config; -use Devdojo\Auth\Models\SocialProvider; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Request; use Laravel\Socialite\Facades\Socialite; -use Devdojo\Auth\Models\SocialProviderUser; class SocialController { - public function __construct(){ - + public function __construct() + { + } public function redirect(Request $request, $driver) @@ -34,12 +34,13 @@ public function callback(Request $request, $driver) DB::transaction(function () use ($socialiteUser, $driver) { // Attempt to find the user based on the social provider's ID and slug $socialProviderUser = SocialProviderUser::where('provider_slug', $driver) - ->where('provider_user_id', $socialiteUser->id) - ->first(); + ->where('provider_user_id', $socialiteUser->id) + ->first(); if ($socialProviderUser) { // Log the user in and redirect to the home page Auth::login($socialProviderUser->user); + return redirect()->to(config('devdojo.auth.settings.redirect_after_auth')); } @@ -54,7 +55,7 @@ public function callback(Request $request, $driver) // No user exists, register a new user $newUser = User::create([ 'name' => $socialiteUser->name, - 'email' => $socialiteUser->email + 'email' => $socialiteUser->email, // Add other fields as necessary ]); @@ -71,7 +72,7 @@ public function callback(Request $request, $driver) 'provider_data' => json_encode($socialiteUser->user), 'token' => $socialiteUser->token, 'refresh_token' => $socialiteUser->refreshToken, - 'token_expires_at' => now()->addSeconds($socialiteUser->expiresIn) + 'token_expires_at' => now()->addSeconds($socialiteUser->expiresIn), ]); // Log in the newly created user @@ -82,12 +83,13 @@ public function callback(Request $request, $driver) return redirect()->to(config('devdojo.auth.settings.redirect_after_auth')); // Adjust according to your needs } - private function dynamicallySetSocialProviderCredentials($provider){ + private function dynamicallySetSocialProviderCredentials($provider) + { $socialProvider = SocialProvider::where('slug', $provider)->first(); - Config::set('services.' . $provider . '.client_id', $socialProvider->client_id); - Config::set('services.' . $provider . '.client_secret', $socialProvider->client_secret); - Config::set('services.' . $provider . '.redirect', '/auth/' . $provider . '/callback'); + Config::set('services.'.$provider.'.client_id', $socialProvider->client_id); + Config::set('services.'.$provider.'.client_secret', $socialProvider->client_secret); + Config::set('services.'.$provider.'.redirect', '/auth/'.$provider.'/callback'); } } diff --git a/src/Http/Middleware/TwoFactorChallenged.php b/src/Http/Middleware/TwoFactorChallenged.php index e2a7637..108526d 100644 --- a/src/Http/Middleware/TwoFactorChallenged.php +++ b/src/Http/Middleware/TwoFactorChallenged.php @@ -15,9 +15,10 @@ class TwoFactorChallenged */ public function handle(Request $request, Closure $next): Response { - if (!session()->has('login.id')) { + if (! session()->has('login.id')) { return redirect()->route('auth.login'); } + return $next($request); } } diff --git a/src/Http/Middleware/TwoFactorEnabled.php b/src/Http/Middleware/TwoFactorEnabled.php index e1639f6..13bba94 100644 --- a/src/Http/Middleware/TwoFactorEnabled.php +++ b/src/Http/Middleware/TwoFactorEnabled.php @@ -15,9 +15,10 @@ class TwoFactorEnabled */ public function handle(Request $request, Closure $next): Response { - if (!config('devdojo.auth.settings.enable_2fa')) { + if (! config('devdojo.auth.settings.enable_2fa')) { return redirect('/'); } + return $next($request); } } diff --git a/src/Installer.php b/src/Installer.php index c62d9bd..89f25d0 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -2,17 +2,19 @@ namespace Devdojo\Auth; -use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\ServiceProvider; class Installer extends ServiceProvider { - public function postInstall(){ + public function postInstall() + { Artisan::call('vendor:publish', ['--tag' => 'auth:assets', '--force' => true]); Artisan::call('vendor:publish', ['--tag' => 'auth:config', '--force' => true]); } - public function postUpdate(){ + public function postUpdate() + { Artisan::call('vendor:publish', ['--tag' => 'auth:assets', '--force' => true]); } -} \ No newline at end of file +} diff --git a/src/Livewire/Setup/Alignment.php b/src/Livewire/Setup/Alignment.php index 91eeffb..69060d6 100644 --- a/src/Livewire/Setup/Alignment.php +++ b/src/Livewire/Setup/Alignment.php @@ -2,37 +2,42 @@ namespace Devdojo\Auth\Livewire\Setup; -use Livewire\Component; use Illuminate\Support\Facades\Artisan; +use Livewire\Component; class Alignment extends Component { public $heading; + public $container; - public function mount(){ + public function mount() + { $this->heading = config('devdojo.auth.appearance.alignment.heading'); - $this->container = config('devdojo.auth.appearance.alignment.container'); + $this->container = config('devdojo.auth.appearance.alignment.container'); - if(!isset($this->heading)){ + if (! isset($this->heading)) { $this->heading = 'center'; } - if(!isset($this->container)){ + if (! isset($this->container)) { $this->container = 'center'; } } - public function updatingHeading($value){ + public function updatingHeading($value) + { $this->updateConfigKeyValue('alignment.heading', $value); } - public function updatingContainer($value){ + public function updatingContainer($value) + { $this->updateConfigKeyValue('alignment.container', $value); } - private function updateConfigKeyValue($key, $value){ - \Config::write('devdojo.auth.appearance.' . $key, $value); + private function updateConfigKeyValue($key, $value) + { + \Config::write('devdojo.auth.appearance.'.$key, $value); Artisan::call('config:clear'); $this->js('savedMessageOpen()'); } @@ -41,4 +46,4 @@ public function render() { return view('auth::livewire.setup.alignment'); } -} \ No newline at end of file +} diff --git a/src/Livewire/Setup/Background.php b/src/Livewire/Setup/Background.php index a47b909..780ad03 100644 --- a/src/Livewire/Setup/Background.php +++ b/src/Livewire/Setup/Background.php @@ -2,9 +2,9 @@ namespace Devdojo\Auth\Livewire\Setup; +use Illuminate\Support\Facades\Artisan; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Support\Facades\Artisan; class Background extends Component { @@ -13,52 +13,59 @@ class Background extends Component public $color; public $image; + public $image_overlay_color; + public $image_overlay_opacity; - - public function mount(){ + public function mount() + { $this->color = config('devdojo.auth.appearance.background.color'); $this->image = config('devdojo.auth.appearance.background.image'); $this->image_overlay_color = (config('devdojo.auth.appearance.background.image_overlay_color')); $this->image_overlay_opacity = (config('devdojo.auth.appearance.background.image_overlay_opacity') * 100); } - public function updatingColor($value){ + public function updatingColor($value) + { $this->updateConfigKeyValue('background.color', $value); } - public function updatingImageOverlayOpacity($value){ - $this->updateConfigKeyValue('background.image_overlay_opacity', (string)doubleval($value/100)); + public function updatingImageOverlayOpacity($value) + { + $this->updateConfigKeyValue('background.image_overlay_opacity', (string) floatval($value / 100)); } - public function updatingImageOverlayColor($value){ + public function updatingImageOverlayColor($value) + { $this->updateConfigKeyValue('background.image_overlay_color', $value); } - - public function updated($property, $value){ - if($property == 'image'){ + public function updated($property, $value) + { + if ($property == 'image') { $filename = $value->getFileName(); $extension = pathinfo($filename, PATHINFO_EXTENSION); - $value->storeAs('public/auth', 'background.' . $extension); - $this->image = '/storage/auth/background.' . $extension; + $value->storeAs('public/auth', 'background.'.$extension); + $this->image = '/storage/auth/background.'.$extension; - $this->updateConfigKeyValue('background.image', '/storage/auth/background.' . $extension); + $this->updateConfigKeyValue('background.image', '/storage/auth/background.'.$extension); $value = null; } } - private function updateConfigKeyValue($key, $value){ - \Config::write('devdojo.auth.appearance.' . $key, $value); + private function updateConfigKeyValue($key, $value) + { + \Config::write('devdojo.auth.appearance.'.$key, $value); Artisan::call('config:clear'); $this->js('savedMessageOpen()'); } - public function deleteBackgroundImage(){ + public function deleteBackgroundImage() + { $imagePath = config('devdojo.auth.appearance.background.image'); if ($imagePath && file_exists(public_path($imagePath))) { unlink(public_path($imagePath)); diff --git a/src/Livewire/Setup/Color.php b/src/Livewire/Setup/Color.php index f9c1eae..e055c3f 100644 --- a/src/Livewire/Setup/Color.php +++ b/src/Livewire/Setup/Color.php @@ -2,21 +2,26 @@ namespace Devdojo\Auth\Livewire\Setup; +use Illuminate\Support\Facades\Artisan; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Support\Facades\Artisan; class Color extends Component { use WithFileUploads; public $text_color; + public $button_color; + public $button_text_color; + public $input_text_color; + public $input_border_color; - public function mount(){ + public function mount() + { $this->text_color = config('devdojo.auth.appearance.color.text'); $this->button_color = config('devdojo.auth.appearance.color.button'); $this->button_text_color = config('devdojo.auth.appearance.color.button_text'); @@ -24,28 +29,34 @@ public function mount(){ $this->input_border_color = config('devdojo.auth.appearance.color.input_border'); } - public function updatingTextColor($value){ + public function updatingTextColor($value) + { $this->updateConfigKeyValue('color.text', $value); } - public function updatingButtonColor($value){ + public function updatingButtonColor($value) + { $this->updateConfigKeyValue('color.button', $value); } - public function updatingButtonTextColor($value){ + public function updatingButtonTextColor($value) + { $this->updateConfigKeyValue('color.button_text', $value); } - public function updatingInputTextColor($value){ + public function updatingInputTextColor($value) + { $this->updateConfigKeyValue('color.input_text', $value); } - public function updatingInputBorderColor($value){ + public function updatingInputBorderColor($value) + { $this->updateConfigKeyValue('color.input_border', $value); } - private function updateConfigKeyValue($key, $value){ - \Config::write('devdojo.auth.appearance.' . $key, $value); + private function updateConfigKeyValue($key, $value) + { + \Config::write('devdojo.auth.appearance.'.$key, $value); Artisan::call('config:clear'); $this->js('savedMessageOpen()'); } diff --git a/src/Livewire/Setup/Css.php b/src/Livewire/Setup/Css.php index 4bc2953..9dd1f06 100644 --- a/src/Livewire/Setup/Css.php +++ b/src/Livewire/Setup/Css.php @@ -3,21 +3,22 @@ namespace Devdojo\Auth\Livewire\Setup; use Livewire\Component; -use Illuminate\Support\Facades\Artisan; class Css extends Component { public $css = ''; - public function mount(){ + public function mount() + { $css_file = public_path('auth/app.css'); - if(file_exists($css_file)){ + if (file_exists($css_file)) { $this->css = file_get_contents($css_file); } - + } - public function update(){ + public function update() + { $css_file = public_path('auth/app.css'); file_put_contents($css_file, $this->css); $this->js('savedMessageOpen()'); @@ -27,4 +28,4 @@ public function render() { return view('auth::livewire.setup.css'); } -} \ No newline at end of file +} diff --git a/src/Livewire/Setup/Favicon.php b/src/Livewire/Setup/Favicon.php index 692b6a6..f7d86d0 100644 --- a/src/Livewire/Setup/Favicon.php +++ b/src/Livewire/Setup/Favicon.php @@ -2,50 +2,54 @@ namespace Devdojo\Auth\Livewire\Setup; +use Illuminate\Support\Facades\Artisan; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Support\Facades\Artisan; class Favicon extends Component { use WithFileUploads; public $favicon_light; + public $favicon_dark; - public function mount(){ + public function mount() + { $this->favicon_light = config('devdojo.auth.appearance.favicon.light'); $this->favicon_dark = config('devdojo.auth.appearance.favicon.dark'); } - public function updated($property, $value){ - if($property == 'favicon_light'){ + public function updated($property, $value) + { + if ($property == 'favicon_light') { $filename = $value->getFileName(); $extension = pathinfo($filename, PATHINFO_EXTENSION); - $value->storeAs('public/auth', 'favicon.' . $extension); - $this->favicon_light = '/storage/auth/favicon.' . $extension; + $value->storeAs('public/auth', 'favicon.'.$extension); + $this->favicon_light = '/storage/auth/favicon.'.$extension; - $this->updateConfigKeyValue('favicon.light', '/storage/auth/favicon.' . $extension); + $this->updateConfigKeyValue('favicon.light', '/storage/auth/favicon.'.$extension); $value = null; } - if($property == 'favicon_dark'){ + if ($property == 'favicon_dark') { $filename = $value->getFileName(); $extension = pathinfo($filename, PATHINFO_EXTENSION); - $value->storeAs('public/auth', 'favicon-dark.' . $extension); - $this->favicon_dark = '/storage/auth/favicon-dark.' . $extension; + $value->storeAs('public/auth', 'favicon-dark.'.$extension); + $this->favicon_dark = '/storage/auth/favicon-dark.'.$extension; - $this->updateConfigKeyValue('favicon.dark', '/storage/auth/favicon-dark.' . $extension); + $this->updateConfigKeyValue('favicon.dark', '/storage/auth/favicon-dark.'.$extension); $value = null; } } - private function updateConfigKeyValue($key, $value){ - \Config::write('devdojo.auth.appearance.' . $key, $value); + private function updateConfigKeyValue($key, $value) + { + \Config::write('devdojo.auth.appearance.'.$key, $value); Artisan::call('config:clear'); $this->js('savedMessageOpen()'); } @@ -54,4 +58,4 @@ public function render() { return view('auth::livewire.setup.favicon'); } -} \ No newline at end of file +} diff --git a/src/Livewire/Setup/Logo.php b/src/Livewire/Setup/Logo.php index 4bbe754..934fc28 100644 --- a/src/Livewire/Setup/Logo.php +++ b/src/Livewire/Setup/Logo.php @@ -2,82 +2,89 @@ namespace Devdojo\Auth\Livewire\Setup; +use Illuminate\Support\Facades\Artisan; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Support\Facades\Artisan; class Logo extends Component { use WithFileUploads; public $logo_type; + public $logo_image_src; + public $logo_svg_string; + public $logo_height; + public $logo_image; - public function mount(){ - + public function mount() + { + $this->logo_type = config('devdojo.auth.appearance.logo.type'); $this->logo_image_src = config('devdojo.auth.appearance.logo.image_src'); $this->logo_svg_string = config('devdojo.auth.appearance.logo.svg_string'); $this->logo_height = config('devdojo.auth.appearance.logo.height'); - if($this->logo_image_src){ + if ($this->logo_image_src) { $this->logo_image = true; } } - protected function rules(){ - + protected function rules() + { + return [ 'logo_type' => 'required', 'logo_image_src' => 'required', 'logo_image_string' => 'required', - 'logo_height' => 'required' + 'logo_height' => 'required', ]; } - - public function updateSvg($value){ + public function updateSvg($value) + { $this->updateConfigKeyValue('logo.svg_string', $value); } public function updating($property, $value) { - if($property == 'logo_image'){ - + if ($property == 'logo_image') { + $filename = $value->getFileName(); $extension = pathinfo($filename, PATHINFO_EXTENSION); - $value->storeAs('public/auth', 'logo.' . $extension); - $this->logo_image_src = '/storage/auth/logo.' . $extension; + $value->storeAs('public/auth', 'logo.'.$extension); + $this->logo_image_src = '/storage/auth/logo.'.$extension; - $this->updateConfigKeyValue('logo.image_src', '/storage/auth/logo.' . $extension); + $this->updateConfigKeyValue('logo.image_src', '/storage/auth/logo.'.$extension); $value = null; } - if($property == 'logo_type'){ + if ($property == 'logo_type') { $this->updateConfigKeyValue('logo.type', $value); } - if($property == 'logo_height'){ + if ($property == 'logo_height') { $this->updateConfigKeyValue('logo.height', $value); } } - - private function updateConfigKeyValue($key, $value){ - \Config::write('devdojo.auth.appearance.' . $key, $value); + private function updateConfigKeyValue($key, $value) + { + \Config::write('devdojo.auth.appearance.'.$key, $value); Artisan::call('config:clear'); $this->js('savedMessageOpen()'); } - public function logoValue(){ - + public function logoValue() + { + $logo = match ($this->logo_type) { 'image' => $this->logo_image, 'svg' => $this->logo_svg, @@ -86,6 +93,7 @@ public function logoValue(){ return $logo; } + public function render() { return view('auth::livewire.setup.logo'); diff --git a/src/Models/SocialProvider.php b/src/Models/SocialProvider.php index 4f51401..bcc3ea2 100644 --- a/src/Models/SocialProvider.php +++ b/src/Models/SocialProvider.php @@ -11,19 +11,20 @@ class SocialProvider extends Model protected $rows = []; - public function getRows() { // Fetching the social providers from the configuration file $this->rows = config('devdojo.auth.providers', []); + return $this->rows; } protected function sushiShouldCache() { - if(app()->isLocal()){ + if (app()->isLocal()) { return false; } + return true; } } diff --git a/src/Models/SocialProviderUser.php b/src/Models/SocialProviderUser.php index e69cb3d..50f9b43 100644 --- a/src/Models/SocialProviderUser.php +++ b/src/Models/SocialProviderUser.php @@ -2,9 +2,8 @@ namespace Devdojo\Auth\Models; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use App\Models\User; +use Illuminate\Database\Eloquent\Model; class SocialProviderUser extends Model { @@ -25,13 +24,13 @@ class SocialProviderUser extends Model 'provider_data', 'token', 'refresh_token', - 'token_expires_at' + 'token_expires_at', ]; // The attributes that should be cast to native types. protected $casts = [ 'token_expires_at' => 'datetime', - 'provider_data' => 'array' + 'provider_data' => 'array', ]; // Define a relationship to the User model diff --git a/src/Models/User.php b/src/Models/User.php index 49fcafa..5cbb516 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -2,9 +2,9 @@ namespace Devdojo\Auth\Models; -use Illuminate\Foundation\Auth\User as Authenticatable; use Devdojo\Auth\Traits\HasSocialProviders; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Foundation\Auth\User as Authenticatable; use PragmaRX\Google2FA\Google2FA; class User extends Authenticatable implements MustVerifyEmail @@ -17,14 +17,15 @@ class User extends Authenticatable implements MustVerifyEmail public function hasVerifiedEmail() { - if (!config('devdojo.auth.settings.registration_require_email_verification')) { + if (! config('devdojo.auth.settings.registration_require_email_verification')) { return true; } return $this->email_verified_at !== null; } - public function twoFactorQrCodeSvg(){ + public function twoFactorQrCodeSvg() + { return ''; } diff --git a/src/Traits/HasConditionalEmailVerification.php b/src/Traits/HasConditionalEmailVerification.php index 262a790..56f2c1f 100644 --- a/src/Traits/HasConditionalEmailVerification.php +++ b/src/Traits/HasConditionalEmailVerification.php @@ -21,8 +21,8 @@ public static function bootHasConditionalEmailVerification() */ private static function classImplements($interface) { - if (!isset(class_implements(static::class)[$interface])) { + if (! isset(class_implements(static::class)[$interface])) { class_uses_recursive(static::class)[$interface] = $interface; } } -} \ No newline at end of file +} diff --git a/src/Traits/HasConfigs.php b/src/Traits/HasConfigs.php index bcd0129..38f5bfb 100644 --- a/src/Traits/HasConfigs.php +++ b/src/Traits/HasConfigs.php @@ -5,29 +5,36 @@ trait HasConfigs { public $appearance = []; + public $language = []; + public $settings = []; - - public function loadConfigs(){ + + public function loadConfigs() + { $this->appearance = $this->configToArrayObject('devdojo.auth.appearance'); $this->language = $this->configToArrayObject('devdojo.auth.language'); $this->settings = $this->configToArrayObject('devdojo.auth.settings'); } - private function configToArrayObject($configPath) { + private function configToArrayObject($configPath) + { $configArray = config($configPath); + return $this->arrayToObject($configArray); } - private function arrayToObject($array) { - if (!is_array($array)) { + private function arrayToObject($array) + { + if (! is_array($array)) { return $array; } - + $object = new \stdClass(); foreach ($array as $key => $value) { $object->$key = $this->arrayToObject($value); } + return $object; } } diff --git a/src/Traits/HasSocialProviders.php b/src/Traits/HasSocialProviders.php index ae12dc6..9e7c2e8 100644 --- a/src/Traits/HasSocialProviders.php +++ b/src/Traits/HasSocialProviders.php @@ -3,7 +3,6 @@ namespace Devdojo\Auth\Traits; use Devdojo\Auth\Models\SocialProviderUser; -use Devdojo\Auth\Models\SocialProvider; trait HasSocialProviders { @@ -28,7 +27,7 @@ public function getLinkedSocialProvidersAttribute() /** * Get social provider user data for a specific provider. * - * @param string $providerSlug The slug of the social provider. + * @param string $providerSlug The slug of the social provider. * @return SocialProviderUser|null */ public function getSocialProviderUser($providerSlug) @@ -39,7 +38,7 @@ public function getSocialProviderUser($providerSlug) /** * Check if the user is linked to a specific social provider. * - * @param string $providerSlug The slug of the social provider. + * @param string $providerSlug The slug of the social provider. * @return bool */ public function hasSocialProvider($providerSlug) @@ -50,8 +49,8 @@ public function hasSocialProvider($providerSlug) /** * Add or update social provider user information for a given provider. * - * @param string $providerSlug The slug of the social provider. - * @param array $data Data to store/update for the provider. + * @param string $providerSlug The slug of the social provider. + * @param array $data Data to store/update for the provider. * @return SocialProviderUser */ public function addOrUpdateSocialProviderUser($providerSlug, array $data) diff --git a/tests/Datasets/Urls.php b/tests/Datasets/Urls.php index b770df8..bda05c7 100644 --- a/tests/Datasets/Urls.php +++ b/tests/Datasets/Urls.php @@ -6,5 +6,5 @@ '/auth/verify', '/auth/password/reset', '/auth/password/confirm', - '/auth/password/SomeReallyLongtoken' -]); \ No newline at end of file + '/auth/password/SomeReallyLongtoken', +]); diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index 4dd8228..678c29a 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -2,7 +2,6 @@ use App\Models\User; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Hash; beforeEach(function () { // Ensure each test starts with a clean slate @@ -64,18 +63,18 @@ 'google' => [ 'name' => 'Google', 'active' => true, - 'label' => 'Google' + 'label' => 'Google', ], 'facebook' => [ 'name' => 'Facebook', 'active' => true, - 'label' => 'Facebook' + 'label' => 'Facebook', ], 'twitter' => [ 'name' => 'Twitter', 'active' => false, - 'label' => 'Twitter' - ] + 'label' => 'Twitter', + ], ]); Livewire::test('auth.register') diff --git a/tests/Feature/TwoFactorTest.php b/tests/Feature/TwoFactorTest.php index 575c4a1..9739cf8 100644 --- a/tests/Feature/TwoFactorTest.php +++ b/tests/Feature/TwoFactorTest.php @@ -1,8 +1,6 @@ delete(); }); -test('Two factor challenge page redirects to login for guest user', function(){ +test('Two factor challenge page redirects to login for guest user', function () { $this->get('auth/two-factor-challenge') ->assertRedirect('auth/login'); }); -test('Two factor challenge page redirects if user is logged in and they don\'t have the login.id session', function(){ +test('Two factor challenge page redirects if user is logged in and they don\'t have the login.id session', function () { withANewUser()->get('auth/two-factor-challenge') ->assertRedirect('auth/login'); }); - -test('User logs in when two factor disabled, the login.id session should not be created', function(){ +test('User logs in when two factor disabled, the login.id session should not be created', function () { $user = createUser(['password' => \Hash::make('password123'), 'two_factor_confirmed_at' => now()]); - + Livewire::test('auth.login') ->set('email', $user->email) ->set('showPasswordField', true) @@ -32,13 +29,13 @@ ->assertHasNoErrors() ->assertRedirect('/'); - $this->assertTrue(!Session::has('login.id')); + $this->assertTrue(! Session::has('login.id')); }); -test('User logs in when two factor enabled, the login.id session should be created', function(){ +test('User logs in when two factor enabled, the login.id session should be created', function () { config()->set('devdojo.auth.settings.enable_2fa', true); $user = createUser(['password' => \Hash::make('password123'), 'two_factor_confirmed_at' => now()]); - + Livewire::test('auth.login') ->set('email', $user->email) ->set('showPasswordField', true) @@ -50,10 +47,10 @@ $this->assertTrue(Session::has('login.id')); }); -test('User logs in without 2FA, they should not be redirected to auth/two-factor-challenge page', function(){ +test('User logs in without 2FA, they should not be redirected to auth/two-factor-challenge page', function () { config()->set('devdojo.auth.settings.enable_2fa', true); $user = createUser(['password' => \Hash::make('password123')]); - + Livewire::test('auth.login') ->set('email', $user->email) ->set('showPasswordField', true) @@ -63,13 +60,13 @@ ->assertRedirect('/'); }); -it('user cannot view two factor challenge page logging in if it\'s disabled', function(){ +it('user cannot view two factor challenge page logging in if it\'s disabled', function () { $user = loginAsUser(); $this->get('user/two-factor-authentication') ->assertRedirect('/'); }); -it('user can view two factor challenge page when it\'s enabled', function(){ +it('user can view two factor challenge page when it\'s enabled', function () { config()->set('devdojo.auth.settings.enable_2fa', true); $user = loginAsUser(); $this->get('user/two-factor-authentication') diff --git a/tests/Pest.php b/tests/Pest.php index e8acb25..dba58d7 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -2,7 +2,6 @@ use Illuminate\Foundation\Testing\RefreshDatabase; - /* |-------------------------------------------------------------------------- | Test Case @@ -52,17 +51,20 @@ function something() use App\Models\User; -function loginAsUser(User $user = null, $data = []){ +function loginAsUser(?User $user = null, $data = []) +{ $user = $user ?? User::factory()->create($data); test()->actingAs($user); return $user; } -function createUser($data){ +function createUser($data) +{ return User::factory()->create($data); } -function withANewUser(){ +function withANewUser() +{ return test()->actingAs(User::factory()->create()); -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 76a2be6..f1ac0a1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,6 +11,6 @@ protected function setUp(): void { parent::setUp(); Artisan::call('view:clear'); - + } }