Closed geertjanknapen1 closed 1 year ago
Update, it happens whenever there is an exception on the Activate account page. Not only regarding the passwords, but also password too short for example.
I have extended the Validation, registered Blade directives and registered view composers.
Could you provide these?
@jasonvarga
Below you can find all of them. They are all in AppServiceProvider::boot()
and it seems it's tried to save them in session (which throws the error), but since I am not saving them to session I don't know where or why that is happening.
Validation extends;
// Register custom site validation rules (e.g. for adding validation rules to form fields)
Validator::extend(
'phone',
function ($attribute, $value, $parameters, $validator) {
return (new Phone())->passes($attribute, $value);
}
);
// Register custom statamic control panel validation rules
Validator::extend(
'must_have_specific_term',
function ($attribute, $value, $parameters, $validator) {
return (new MustHaveSpecificTerm())->passes($attribute, $value);
}
);
Check if input matches a phone number
class Phone implements Rule
{
public function passes($attribute, $value)
{
return Regex::match('/^[0-9\-\(\)\x20\+]*$/', $value)->hasMatch();
}
public function message()
{
return '';
}
}
Check if an Entry has a taxonomy term (we call them tags) of a specific type
class MustHaveSpecificTerm implements Rule
{
public function passes($attribute, $value)
{
// 'tags' is a Terms field
if ($attribute === 'tags') {
$tagHandle= Taxonomy::CATEGORY->value . '::';
foreach ($value as $tag) {
if (str_contains($tag, $tagHandle)) {
return true;
}
}
}
return false;
}
public function message()
{
return '';
}
}
Blade directives;
Calls getTranslation method on the Entry ($page) in order to get translations from a Statamic array or globals Other one checks if a key in session is equal to a value
/** Blade directive to get translation key from globals */
Blade::directive('translate', function (string $translationKey) {
return '<?= !empty($page) ? $page->getTranslation(' . $translationKey . ') : translate(' . $translationKey .') ?>';
});
Blade::if('sessionValueIs', function ($key, $value) {
return (session()->get($key) && session()->get($key) === $value);
});
Viewcomposers;
Passes supported languages, locale, contentType (either commercial or not commercial) and isCommercial boolean to all views
View::composer('*', function (IlluminateView $view) {
/** Pass Statamic global sets to every view */
GlobalSet::all()->each(fn($set) => $view->with($set->handle(), $set->inCurrentSite()));
/** Pass selected variables to every view */
$view
->with('supportedLanguages', app(ITranslationService::class)->getAcceptedLocales())
->with('locale', app()->getLocale())
->with('contentType', request()->get('contentType'))
->with('isCommercial', request()->get('isCommercial'));
});
Is it possible Statamic isn't booted yet? What if you put all of those that reference Statamic in a Statamic::booted()
?
The only suspicious part about any of that to me is this one, because it's accessing the session.
Blade::if('sessionValueIs', function ($key, $value) {
return (session()->get($key) && session()->get($key) === $value);
});
Can you try commenting that one out and trying to trigger the validation error again?
Everything else doesn't seem to me like it would be a problem. I don't see why any of those would go into the session.
Commenting that out, clearing cache and restarting the docker containers does not change anything. It still throws the same error.
Is it possible Statamic isn't booted yet? What if you put all of those that reference Statamic in a
Statamic::booted()
?
Hey @edalzell , didn't notice your comment, and also failed to clarify. But to my knowledge nothing is referencing Statamic. Yes the rules are referencing the data column of an entry but the rule works, it's just that it seems to try to save it in session which is breaking.
Issue got put on the backburner (since we use Azure to authenticate new users we can handle creating accounts ourselves, it'd just be nicer to have it working). But I'm starting to suspect it might be Laravel-related and not Statamic.
Yeah we can't recreate this here at all – if you're able to do so on a new, empty Statamic site, we can use that to dig in, otherwise i think we need to look at something in Laravel-land as the culprite.
Bug description
When trying to activate an account, if the password and password confirmation do NOT match, I get the following exception. If the passwords do match, everything is fine. Not sure but this could just not be Statamic related but a Laravel thing
How to reproduce
On the Users part in Statamic
Click
Create User
Enter an e-mail address and a name.
Uncheck/un-toggle
Super Admin
Do not add roles.
Send the email.
Open the link to activate the account in the email
Use the same email as used above (to create the user) in the form
Choose a random password.
Make sure that for the confirmation, the password is not the same. (I.E if you chose
NewPassword
as password, make sure the confirmation password does not equalNewPassword
)Exception is thrown.
Logs
Environment
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
regex (default)
Additional details
I have extended the Validation, registered Blade directives and registered view composers. If I understand correctly those are
Closures
, and I also saw they are present in the session (unsure if they should be).