klaus66
(Klaus Mergen)
January 21, 2024, 12:10pm
1
app/config/di/user-module.php
use Kmergen\User\UserModuleInterface;
use Kmergen\User\UserModule;
/** @var array $params */
return [
UserModuleInterface::class => [
'class' => UserModule::class,
// The username should be case sensitive.
// The time in seconds within which the user should confirm the account.
'tokenConfirmWithin()' => [7689],
// The time in seconds within which the user should recover the password.
'tokenRecoverWithin()' => [4500],
],
];
resource/views/register/index.php
<?php
declare(strict_types=1);
/**
* @var WebView $this
* @var TranslatorInterface $translator
* @var ApplicationParameters $applicationParameters
*/
use App\ApplicationParameters;
use Yiisoft\Translator\TranslatorInterface;
use Yiisoft\View\WebView;
use Kmergen\User\UserModuleInterface;
$this->setTitle($applicationParameters->getName());
?>
<div class="mil-banner">
<div class="container">
<div class="mil-banner-content-frame">
<div class="mil-banner-content">
<h1><?= $applicationParameters->getName() ?></h1>
<h2><?= $newCon ?></h2>
<h2><?= $module->getTokenConfirmWithin() ?></h2>
</div>
</div>
</div>
</div>
The output is 86400 and not how expected 7689.
The 86400 is the default value of kmergen/User/UserModule
Should be property name not function 'tokenConfirmWithin' => 7689,
https://github.com/kmergen/yii-user/blob/main/src/UserModule.php
klaus66
(Klaus Mergen)
January 22, 2024, 7:16am
3
No. that is a private property. Need setter function to set value.
Look at app-parameters, there it works as expected.
evstevemd
(Stefano Mtangoo)
January 22, 2024, 8:37am
4
Looks good to me.
Could it be that somehow Yii is not recognizing your configuration?
Am not too much yet into Yii3, but If you can provide a sample app I can look into it
vjik
(vjik)
January 22, 2024, 8:47am
5
Seems, problem in module: https://github.com/kmergen/yii-user/blob/31a156b12c1e256ca40d9ebcf89681785ab3a008/src/UserModule.php#L208
Need use $new->tokenConfirmWithin = $tokenConfirmWithin;
insted of $this->...
.
2 Likes
klaus66
(Klaus Mergen)
January 22, 2024, 9:14am
6
That’s it, thank you.
The solution here:
From
public function tokenConfirmWithin(int $tokenConfirmWithin): self
{
$new = clone $this;
$this->tokenConfirmWithin = $tokenConfirmWithin;
return $new;
}
to
public function tokenConfirmWithin(int $tokenConfirmWithin): self
{
$new = clone $this;
$new->tokenConfirmWithin = $tokenConfirmWithin;
return $new;
}
klaus66
(Klaus Mergen)
January 22, 2024, 9:37am
7
One question about the following behavior:
Is it normal that you cannot set the value on runtim for e.g in a controller action class
final class RegistrationAction extends AbstractAction
{
public function index(
UserModuleInterface $module,
ServerRequestInterface $request,
Validator $validator,
RegistrationFormModel $form
): ResponseInterface {
$hydrator = new Hydrator();
// $parsedBody = $request->getParsedBody([$form->getFormName()]);
if ($request->getMethod() === Method::POST) {
$hydrator->hydrate($form, $request->getParsedBody()[$form->getFormName()]);
$validator->validate($form);
}
$module->tokenConfirmWithin(34092);
$newCon = $module->getTokenConfirmWithin();
return $this->viewRenderer->withViewPath($this->module->getViewPath() ?: __DIR__ . '/view')->render('index', ['newCon' => $newCon, 'form' => $form]);
}
}
Then the $newCon is not 34092, it has the value from setting in configuration.
I see, didn’t paid attention to property scope.