Skip to content

Commit c99224d

Browse files
authored
Merge pull request #19009 from craftcms/feature/auth-refactor
[6.x] Move Laravel auth off of User element into CraftUser interface
2 parents 00312d2 + 70c8c06 commit c99224d

187 files changed

Lines changed: 1363 additions & 1086 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Added `CraftCms\Cms\User\Contracts\CraftUser` and `CraftUserTrait`. ([#19009](https://github.com/craftcms/cms/pull/19009))
6+
- Removed `CraftCms\Cms\Auth\UserProvider`; the Craft guard now defaults to Laravel’s Eloquent provider using `CraftCms\Cms\User\Models\User`. ([#19009](https://github.com/craftcms/cms/pull/19009))
7+
- Added `Auth::craftUser()`/`auth('craft')->craftUser()` and `request()->craftUser()` as Craft-safe ways to access the authenticated user. ([#19009](https://github.com/craftcms/cms/pull/19009))
58
- `Element::getIterator()` no longer includes custom field values. ([#19004](https://github.com/craftcms/cms/issues/19004))
69
- Fixed a bug where checking the elevated session timeout could overwrite newer session data, which could prevent passkeys from being created.
710
- Fixed a bug where legacy plugin-defined `actions.php` routes could collide between plugins. ([#18994](https://github.com/craftcms/cms/pull/18994))
@@ -95,7 +98,7 @@
9598
- Fixed a PHP error that occurred when saving a Structure section with a Max Levels value. ([#18809](https://github.com/craftcms/cms/issues/18809))
9699
- Fixed a bug where plugin settings pages were missing registered scripts and styles. ([#18815](https://github.com/craftcms/cms/pull/18815))
97100
- Fixed a PHP error that occurred when saving an entry type. ([#18816](https://github.com/craftcms/cms/pull/18816))
98-
- Fixed an issue with Typecast where typed setters wouldn't have precedence over private properties.
101+
- Fixed an issue with Typecast where typed setters wouldnt have precedence over private properties.
99102
- Fixed a bug where Control Panel templates failed to load on Windows due to mismatched directory separators or drive-letter casing in `CraftCms\Cms\View\TwigEngine`. ([#18804](https://github.com/craftcms/cms/issues/18804))
100103
- Fixed a bug where Craft’s Vite hot file configuration could override the host application’s Vite hot file. ([#18810](https://github.com/craftcms/cms/issues/18810))
101104
- Fixed a bug where `CraftCms\Cms\Support\Typecast` could give private properties precedence over typed setters.
@@ -124,9 +127,9 @@
124127
- Fixed a bug where a `yii\base\InvalidConfigException` would be thrown when a Yii2-based plugin registered an asset bundle. ([#18818](https://github.com/craftcms/cms/issues/18818))
125128
- Fixed a bug where using `{{ successMessageInput() }}` would not decrypt the resulting message for the flash message.
126129
- Fixed a bug where a missing widget from an uninstalled plugin would throw instead of mapping to a MissingWidget.
127-
- Fixed a bug where an address' ownership ids could be overridden unintentionally.
130+
- Fixed a bug where an address ownership ids could be overridden unintentionally.
128131
- Fixed a bug where `getHasSsoIdentity()` would return `false` when Socialite was not installed but the user had an SSO identity.
129-
- Fixed a bug where the site's offline status was not being enforced on matched element routes.
132+
- Fixed a bug where the sites offline status was not being enforced on matched element routes.
130133
- Fixed a user photo validation issue with file extensions.
131134
- Fixed a bug where legacy controllers could return `null` but were not considered handled.
132135
- Improved performance of the dashboard by reducing the amount of queries for widgets
@@ -281,7 +284,7 @@
281284

282285
#### Mutex
283286

284-
Craft's Mutex classes have been deprecated. [Laravel's atomic locking](https://laravel.com/docs/12.x/cache#atomic-locks) should be used instead.
287+
Crafts Mutex classes have been deprecated. [Laravels atomic locking](https://laravel.com/docs/12.x/cache#atomic-locks) should be used instead.
285288

286289
- Deprecated `craft\mutex\Mutex`
287290
- Deprecated `craft\mutex\MutexTrait`
@@ -371,7 +374,7 @@ Craft's Mutex classes have been deprecated. [Laravel's atomic locking](https://l
371374

372375
### Auth
373376

374-
- Refactored the authentication system to use Laravel's authentication system.
377+
- Refactored the authentication system to use Laravels authentication system.
375378
- Added `CraftCms\Cms\Auth\Events\SettingPassword`.
376379
- Added `CraftCms\Cms\User\Notifications\ResetPasswordNotification`.
377380
- Deprecated `craft\services\Auth`. `CraftCms\Cms\Auth\Auth` should be used instead.
@@ -386,7 +389,7 @@ Craft's Mutex classes have been deprecated. [Laravel's atomic locking](https://l
386389
- Deprecated `craft\behaviors\SessionBehavior::checkAuthorization`. `CraftCms\Cms\Auth\SessionAuth::checkAuthorization` should be used instead.
387390
- Deprecated `craft\services\Users::isVerificationCodeValidForUser()`. `Password::broker('craft')->tokenExists($user, $code)` should be used instead.
388391
- Deprecated the `elevatedSessionDuration` general config setting. The `auth.password_timeout` config value should be used instead. To disable password confirmation (elevated sessions), you now set this value to `-1` instead of `0`.
389-
- Elevated sessions now work through [Laravel's password confirmation](https://laravel.com/docs/12.x/authentication#password-confirmation) system.
392+
- Elevated sessions now work through [Laravels password confirmation](https://laravel.com/docs/12.x/authentication#password-confirmation) system.
390393
- Removed `craft\controllers\AuthController`. The following controllers now implement this functionality:
391394
- `CraftCms\Cms\Http\Controllers\Users\AuthMethodController`
392395
- `CraftCms\Cms\Http\Controllers\Users\PasskeysController`
@@ -395,7 +398,7 @@ Craft's Mutex classes have been deprecated. [Laravel's atomic locking](https://l
395398

396399
#### Authorization
397400

398-
Craft 6 now uses [Laravel's authorization system](https://laravel.com/docs/12.x/authorization) for element authorization checks.
401+
Craft 6 now uses [Laravels authorization system](https://laravel.com/docs/12.x/authorization) for element authorization checks.
399402

400403
##### Added
401404

@@ -592,14 +595,14 @@ Craft 6 now uses [Laravel's authorization system](https://laravel.com/docs/12.x/
592595

593596
#### Validation
594597

595-
Craft 6 introduces a new validation system that uses Laravel's Validator instead of Yii2's model validation.
598+
Craft 6 introduces a new validation system that uses Laravels Validator instead of Yii2s model validation.
596599

597600
##### Added
598601

599602
- Added `CraftCms\Cms\Validation\Contracts\Validatable` interface for classes that support Laravel-style validation.
600603
- Added `CraftCms\Cms\Validation\Contracts\ValidatableWithRuleset` interface for classes that use a `Ruleset` class to define validation rules.
601604
- Added `CraftCms\Cms\Validation\Ruleset` abstract class for defining validation rules, messages, and preparation logic.
602-
- Added `CraftCms\Cms\Validation\Attributes\Ruleset` PHP attribute for specifying a component's ruleset class.
605+
- Added `CraftCms\Cms\Validation\Attributes\Ruleset` PHP attribute for specifying a components ruleset class.
603606
- Added `CraftCms\Cms\Validation\Concerns\Validates` trait for simple validation support.
604607
- Added `CraftCms\Cms\Validation\Concerns\ValidatesWithRuleset` trait for ruleset-based validation.
605608
- Added `CraftCms\Cms\Validation\Concerns\HasScenarios` trait for scenario-based validation filtering.
@@ -622,7 +625,7 @@ Craft 6 introduces a new validation system that uses Laravel's Validator instead
622625

623626
##### Changed
624627

625-
- `FieldInterface::getElementValidationRules()` has been replaced by `FieldInterface::getElementRules()` which returns rules in Laravel's validation format.
628+
- `FieldInterface::getElementValidationRules()` has been replaced by `FieldInterface::getElementRules()` which returns rules in Laravels validation format.
626629
- Added `FieldInterface::prepareForElementValidation()` for preparing field values before validation.
627630
- Validation rules are now defined as Laravel-style arrays (e.g., `['required', 'string', 'max:255']`).
628631

@@ -685,7 +688,7 @@ Craft 6 introduces a new validation system that uses Laravel's Validator instead
685688

686689
### Component
687690

688-
- Added `CraftCms\Cms\Component\Component` base class, replacing Yii2's `BaseObject`/`Component` with config hydration, magic getters/setters, and `Arrayable` support.
691+
- Added `CraftCms\Cms\Component\Component` base class, replacing Yii2s `BaseObject`/`Component` with config hydration, magic getters/setters, and `Arrayable` support.
689692
- Added `CraftCms\Cms\Component\Exceptions\InvalidCallException`, replacing `yii\base\InvalidCallException`.
690693
- Added `CraftCms\Cms\Component\Exceptions\UnknownPropertyException`, replacing `yii\base\UnknownPropertyException`.
691694

@@ -810,11 +813,11 @@ Craft 6 introduces a new validation system that uses Laravel's Validator instead
810813

811814
### HTTP
812815

813-
- Deprecated the `errorTemplatePrefix` general config setting. Configure [Laravel's custom error pages](https://laravel.com/docs/13.x/errors#custom-http-error-pages) instead.
816+
- Deprecated the `errorTemplatePrefix` general config setting. Configure [Laravels custom error pages](https://laravel.com/docs/13.x/errors#custom-http-error-pages) instead.
814817
- Deprecated `craft\filters\BasicHttpAuthLogin`. Use the `auth.basic` middleware instead. (see https://laravel.com/docs/12.x/authentication#http-basic-authentication)
815818
- Deprecated `craft\filters\BasicHttpAuthStatic`. Use the `auth.basic` middleware instead. (see https://laravel.com/docs/12.x/authentication#http-basic-authentication)
816819
- Deprecated `craft\filters\BasicHttpAuthTrait`. Use the `auth.basic` middleware instead. (see https://laravel.com/docs/12.x/authentication#http-basic-authentication)
817-
- Deprecated `craft\filters\Cors`. Use Laravel's CORS settings instead. (see https://laravel.com/docs/12.x/routing#cors)
820+
- Deprecated `craft\filters\Cors`. Use Laravels CORS settings instead. (see https://laravel.com/docs/12.x/routing#cors)
818821
- Deprecated `craft\filters\Headers`. Use Laravel middleware instead. (see https://laravel.com/docs/middleware)
819822
- Deprecated `craft\filters\ConditionalFilterTrait`.
820823
- Deprecated `craft\filters\SiteFilterTrait`.
@@ -827,7 +830,7 @@ Craft 6 introduces a new validation system that uses Laravel's Validator instead
827830
- Removed `craft\controllers\AppController::actionGetPluginLicenseInfo()` and `actionUpdatePluginLicense()`. `CraftCms\Cms\Http\Controllers\App\PluginsController` should be used instead.
828831
- Removed `craft\controllers\AppController::actionBrokenImage()`. `CraftCms\Cms\Http\Middleware\ShowBrokenImage` should be used instead.
829832
- Removed `craft\controllers\AppController::actionRenderElements()` and `actionRenderComponents()`. `CraftCms\Cms\Http\Controllers\App\RenderController` should be used instead.
830-
- Removed `craft\controllers\NotFoundController`. Laravel's exception handling should be used instead.
833+
- Removed `craft\controllers\NotFoundController`. Laravels exception handling should be used instead.
831834
- Removed the header-setting logic in `yii2-adapter\legacy\web\Application`. The new `\CraftCms\Cms\Http\Middleware\SetHeaders` middleware handles this functionality.
832835
- Removed the licensing issues screen logic in `yii2-adapter\legacy\web\Application`. The new `\CraftCms\Cms\Http\Middleware\EnforceLicenses` middleware handles this functionality.
833836
- Removed `craft\controllers\AppController::actionTryEdition()` and `actionSwitchToLicensedEdition()` in favor of `CraftCms\Cms\Http\Controllers\EditionController`.
@@ -842,11 +845,11 @@ Craft 6 introduces a new validation system that uses Laravel's Validator instead
842845
- Deprecated `craft\helpers\MailerHelper`. Laravel mail configuration and drivers should be used instead.
843846
- Deprecated the `testToEmailAddress` general config setting. `Illuminate\Support\Facades\Mail::alwaysTo()` should be used instead.
844847
- Deprecated `craft\mail\Mailer::$template`, `craft\mail\Mailer::$siteOverrides`, `craft\models\MailSettings::$template`, and `craft\models\MailSettings::$siteOverrides`. Laravel mailable views and environment-specific Laravel mailers should be used instead.
845-
- Removed legacy `projectConfig.email` mail settings and mail transport adapter configuration in favor of Laravel's `mail` config and drivers.
848+
- Removed legacy `projectConfig.email` mail settings and mail transport adapter configuration in favor of Laravels `mail` config and drivers.
846849

847850
### Migrations
848851

849-
Craft and Yii's migrations have been removed in favor of [Laravel migrations](https://laravel.com/docs/12.x/migrations).
852+
Craft and Yiis migrations have been removed in favor of [Laravel migrations](https://laravel.com/docs/12.x/migrations).
850853

851854
The `php craft fields:merge` and `php craft entry-types:merge` commands will now generate Laravel migrations.
852855

@@ -914,8 +917,8 @@ The `php craft fields:merge` and `php craft entry-types:merge` commands will now
914917
- Added `CraftCms\Cms\Support\Security`.
915918
- Added `CraftCms\Cms\Support\Facades\Security`.
916919
- Added `CraftCms\Cms\Http\Middleware\AddLogContext`.
917-
- Deprecated `Craft::$app->getSecurity()` in favor of Laravel's Hash and Crypt facades, or `CraftCms\Cms\Support\Facades\Security`.
918-
- Deprecated the `blowfishHashCost` general config setting in favor of Laravel's `hashing.bcrypt.rounds` config or the `BCRYPT_ROUNDS` environment variable.
920+
- Deprecated `Craft::$app->getSecurity()` in favor of Laravels Hash and Crypt facades, or `CraftCms\Cms\Support\Facades\Security`.
921+
- Deprecated the `blowfishHashCost` general config setting in favor of Laravels `hashing.bcrypt.rounds` config or the `BCRYPT_ROUNDS` environment variable.
919922

920923
### Updates
921924

@@ -1001,7 +1004,7 @@ Moved the following controllers:
10011004
### Routes
10021005

10031006
- Deprecated `craft\services\Routes`. `CraftCms\Cms\Route\Routes` should be used instead.
1004-
- Using routes in `config/routes.php` is no longer supported. Register routes using [Laravel's routing](https://laravel.com/docs/12.x/routing) instead.
1007+
- Using routes in `config/routes.php` is no longer supported. Register routes using [Laravels routing](https://laravel.com/docs/12.x/routing) instead.
10051008

10061009
### Search
10071010

resources/templates/_components/fieldtypes/Matrix/block.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
]) %}
7373
{% endif %}
7474

75-
{% if entry.id or (Auth.user.admin and config('craft.general.allowAdminChanges')) %}
75+
{% if entry.id or (currentUser.admin and config('craft.general.allowAdminChanges')) %}
7676
{% set actionMenuItems = actionMenuItems|push({hr: true}) %}
7777

7878
{% if entry.id and not static %}
@@ -84,7 +84,7 @@
8484
}) %}
8585
{% endif %}
8686

87-
{% if Auth.user.admin and config('craft.general.allowAdminChanges') %}
87+
{% if currentUser.admin and config('craft.general.allowAdminChanges') %}
8888
{% set actionMenuItems = actionMenuItems|push({
8989
icon: 'gear',
9090
label: 'Entry type settings'|t('app'),

resources/templates/_components/widgets/CraftSupport/body.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
{{ hiddenInput('widgetId', widget.id) }}
102102
{{ hiddenInput('message', '', {class: 'cs-support-message'}) }}
103103

104-
{% set email = Auth.user.email %}
104+
{% set email = currentUser.email %}
105105
{% if email in ['support@pixelandtonic.com', 'support@craftcms.com'] %}
106106
{% set email = '' %}
107107
{% endif %}

resources/templates/_includes/forms/autosuggest.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ new Vue({
7777
name: (name ?? '')|namespaceInputName,
7878
size: size ?? '',
7979
maxlength: maxlength ?? '',
80-
autofocus: (autofocus ?? false) and Auth.user and Auth.user.getAutofocusPreferred() and not Request.isMobileBrowser(true),
80+
autofocus: (autofocus ?? false) and currentUser and currentUser.getAutofocusPreferred() and not Request.isMobileBrowser(true),
8181
disabled: disabled ?? false,
8282
title: title ?? '',
8383
placeholder: placeholder ?? '',

resources/templates/_includes/forms/text.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
name: name ?? false,
2424
value: value ?? false,
2525
maxlength: maxlength ?? false,
26-
autofocus: (autofocus ?? false) and Auth.user and Auth.user.getAutofocusPreferred() and not Request.isMobileBrowser(true),
26+
autofocus: (autofocus ?? false) and currentUser and currentUser.getAutofocusPreferred() and not Request.isMobileBrowser(true),
2727
autocomplete: autocomplete is boolean ? (autocomplete ? 'on' : 'off') : autocomplete,
2828
autocorrect: (autocorrect ?? true) ? false : 'off',
2929
autocapitalize: (autocapitalize ?? true) ? false : 'none',

resources/templates/_layouts/base.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
{% set bodyClass = (bodyClass ?? [])|explodeClass|merge([
88
orientation,
9-
(Auth.user.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false) ? 'use-shapes',
10-
(Auth.user.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false) ? 'underline-links',
11-
"notifications--#{Auth.user.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start'}",
9+
(currentUser.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false) ? 'use-shapes',
10+
(currentUser.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false) ? 'underline-links',
11+
"notifications--#{currentUser.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start'}",
1212
requestedSite ? "site--#{requestedSite.handle}",
1313
'cp-legacy-reset',
1414
'cp-legacy'

resources/templates/_layouts/components/global-sidebar.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
} %}
8888
</div>
8989

90-
{% if Auth.user.admin and devMode %}
90+
{% if currentUser.admin and devMode %}
9191
{% set devModeText = 'Craft CMS is running in Dev Mode.'|t('app') %}
9292
<div id="devmode">
9393
{% tag 'span' with {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="header-photo">
2-
{{ Auth.user.getThumbHtml(30)|raw }}
2+
{{ currentUser.getThumbHtml(30)|raw }}
33
</div>

resources/templates/_layouts/cp.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ history.replaceState(undefined, undefined, window.location.href.match(/^[^#]*/)[
164164
<ul>
165165
<li>
166166
<a href="{{ url('myaccount') }}" class="flex flex-nowrap">
167-
{% if Auth.user.photoId %}
167+
{% if currentUser.photoId %}
168168
{{ userPhoto|raw }}
169169
{% endif %}
170170
<div class="flex-grow">
171-
<div>{{ Auth.user.username }}</div>
171+
<div>{{ currentUser.username }}</div>
172172
{% if not config('craft.general.useEmailAsUsername') %}
173-
<div class="smalltext">{{ Auth.user.email }}</div>
173+
<div class="smalltext">{{ currentUser.email }}</div>
174174
{% endif %}
175175
</div>
176176
</a>
@@ -393,7 +393,7 @@ history.replaceState(undefined, undefined, window.location.href.match(/^[^#]*/)[
393393
{% endblock %}
394394

395395

396-
{% if Auth.user.can('performUpdates') and not Updates.isUpdateInfoCached() %}
396+
{% if currentUser.can('performUpdates') and not Updates.isUpdateInfoCached() %}
397397
{% js %}
398398
Craft.cp.checkForUpdates();
399399
{% endjs %}

resources/templates/users/_index.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% set canHaveDrafts = craft.users().drafts().draftOf(false).savedDraftsOnly().exists() %}
99

1010
{% block actionButton %}
11-
{% if Auth.user.canRegisterUsers() %}
11+
{% if canRegisterUsers %}
1212
<a class="btn submit add icon" href="{{ url('users/new') }}">
1313
{{ buttonLabel }}
1414
</a>

0 commit comments

Comments
 (0)