Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adopt suggestions in (#602)[yiisoft/demo#602]
  • Loading branch information
rossaddison committed Nov 18, 2023
1 parent f3d7432 commit 33ccf37
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 63 deletions.
8 changes: 4 additions & 4 deletions config/common/routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Contact\ContactController;
use App\Auth\Controller\AuthController;
use App\Auth\Controller\SignupController;
use App\Auth\Controller\ResetController;
use App\Auth\Controller\ChangeController;
use App\Controller\SiteController;
use App\Controller\Actions\ApiInfo;
use App\Middleware\AccessChecker;
Expand Down Expand Up @@ -106,13 +106,13 @@
) => new LimitRequestsMiddleware(new Counter($storage, 10, 10), $responseFactory))
->action([SignupController::class, 'signup'])
->name('auth/signup'),
Route::methods([Method::GET, Method::POST], '/reset')
Route::methods([Method::GET, Method::POST], '/change')
->middleware(fn(
ResponseFactoryInterface $responseFactory,
StorageInterface $storage
) => new LimitRequestsMiddleware(new Counter($storage, 10, 10), $responseFactory))
->action([ResetController::class, 'reset'])
->name('auth/reset'),
->action([ChangeController::class, 'change'])
->name('auth/change'),
Group::create('/user')
->routes(
// User
Expand Down
4 changes: 3 additions & 1 deletion resources/messages/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,14 @@
'menu.signup' => 'Signup',
'menu.swagger' => 'Swagger',
'menu.users' => 'Users',
'reset'=> 'Reset Password',
'password.reset' => 'Reset Password',
'password.change' => 'Change Password',
'signup' => 'Signup',
'validator.invalid.login.password' => 'Invalid login or password',
'validator.password.not.match' => 'Passwords do not match',
'validator.password.not.match.new' => 'Your new passwords do not match',
'validator.password.reset' => 'Your Password has been reset',
'validator.password.change' => 'Your Password has been changed',
'validator.user.exist' => 'A User with this login already exists',
'valiadator.user.exist.not' => 'A User with this login does not exist'
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use App\Auth\Form\ResetForm;
use App\Auth\Form\ChangeForm;
use Yiisoft\Form\Field;
use Yiisoft\Html\Html;
use Yiisoft\Html\Tag\Form;
Expand All @@ -15,9 +15,9 @@
* @var TranslatorInterface $translator
* @var UrlGeneratorInterface $urlGenerator
* @var string $csrf
* @var ResetForm $formModel
* @var ChangeForm $formModel
*/
$this->setTitle($translator->translate('reset'));
$this->setTitle($translator->translate('change'));
?>

<div class="container py-5 h-100">
Expand All @@ -29,20 +29,20 @@
</div>
<div class="card-body p-5 text-center">
<?= Form::tag()
// note: the reset function actually appears in the ResetController
->post($urlGenerator->generate('auth/reset'))
// note: the chagne function actually appears in the ChangeController
->post($urlGenerator->generate('auth/change'))
->csrf($csrf)
->id('resetForm')
->id('changeForm')
->open() ?>

<?= Field::text($formModel, 'login')->addInputAttributes(['value'=> $login ?? '', 'readonly'=>'readonly']) ?>
<?= Field::password($formModel, 'password') ?>
<?= Field::password($formModel, 'password_verify') ?>
<?= Field::password($formModel, 'new_password') ?>
<?= Field::password($formModel, 'new_password_verify') ?>
<?= Field::password($formModel, 'passwordVerify') ?>
<?= Field::password($formModel, 'newPassword') ?>
<?= Field::password($formModel, 'newPasswordVerify') ?>
<?= Field::submitButton()
->buttonId('reset-button')
->name('reset-button')
->buttonId('change-button')
->name('change-button')
->content($translator->translate('layout.submit'))
?>
<?= Form::tag()->close() ?>
Expand Down
6 changes: 6 additions & 0 deletions resources/views/invoice/info/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<p>Introducing Paypal.</p>
<p>Introducing India's PayTm payment gateway's QR code method of payment and comparing this with Stripe's method.</p>
<p>A General Sales Tax (GST) Tax System will have to be implemented first for this purpose.</p>
<p><b>What's next?</b></p>
<p>Upskilling on Docker.</p>
<p><b>18 November 2023</b></p>
<p>Do not use 'Reset' word in the context of changing a password. Use 'Change' instead. <a href=https://github.com/yiisoft/demo/pull/602>Pull request 602 under development.</a></p>
<p>So reset switched to change on all files</p>
<p>The reset password aspect of yii3 is still being developed</p>
<p><b>25 September 2023</b></p>
<p>Bugfix $ucR variable undefined. Retain within controller rather than view.</p>
<p>Testing on yii3i.co.uk</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
<div class="container">
<?php if ($invView && $invEdit) { ?>
<div class="row">
<?php foreach ($product_images as $productimage) { ?>
<div class="row">
<a data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
<img src="<?= '/products/'. $productimage->getFile_name_original(); ?>" class="img-fluid">
</a>
</div>
<?php foreach ($product_images as $productimage) { ?>
<a data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
<img src="<?= '/products/'. $productimage->getFile_name_original(); ?>" class="img-fluid">
</a>
<?php } ?>
</div>
<?php } ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ class="form-control" value="<?= $body['settings[invoices_due_after]']; ?>">
<?= $s->trans('mark_invoices_sent_pdf'); ?>
</label>
<?php $body['settings[mark_invoices_sent_pdf]'] = $s->get_setting('mark_invoices_sent_pdf');?>
<select name="settings[mark_invoices_sent_pdf]" id="settings[mark_invoices_sent_pdf]"
class="form-control" >
<select name="settings[mark_invoices_sent_pdf]" id="settings[mark_invoices_sent_pdf]" class="form-control" >
<option value="0">
<?= $s->trans('no'); ?>
</option>
Expand Down
20 changes: 10 additions & 10 deletions resources/views/layout/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
['options' => ['class' => 'nav fs-4'], 'label' => $s->trans('invoice_tax_rate'), 'url' => $urlGenerator->generate('taxrate/index')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('invoice.invoice.contract'), 'url' => $urlGenerator->generate('contract/index')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('invoice.user.account'), 'url' => $urlGenerator->generate('userinv/index')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('reset'), 'url' => $urlGenerator->generate('auth/reset')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('password.change'), 'url' => $urlGenerator->generate('auth/change')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('invoice.user.api.list'), 'url' => $urlGenerator->generate('user/index')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('invoice.setting.company'), 'url' => $urlGenerator->generate('company/index')],
['options' => ['class' => 'nav fs-4'], 'label' => $translator->translate('invoice.setting.company.private'), 'url' => $urlGenerator->generate('companyprivate/index')],
Expand All @@ -277,13 +277,13 @@
['label' => $translator->translate('invoice.platform'), 'options' => ['style' => 'background-color: #ffcccb'], 'visible' => $debug_mode,
'items' => [
['label' => 'WAMP'],
['label' => $translator->translate('invoice.platform.editor') . ': Apache Netbeans 12.4 64 bit'],
['label' => $translator->translate('invoice.platform.server') . ': Wampserver 3.2.9 64 bit'],
['label' => $translator->translate('invoice.platform.editor') . ': Apache Netbeans IDE 19 64 bit'],
['label' => $translator->translate('invoice.platform.server') . ': Wampserver 3.3.1 64 bit'],
['label' => 'Apache: 2.4.54 64 bit'],
['label' => $translator->translate('invoice.platform.mySqlVersion') . ': 5.7.31 || 8.0.30 '],
['label' => $translator->translate('invoice.platform.windowsVersion') . ': Windows 10 Home Edition'],
['label' => $translator->translate('invoice.platform.PhpVersion') . ': 8.1.11 (Compatable with PhpAdmin 5.2.0)'],
['label' => $translator->translate('invoice.platform.PhpMyAdmin') . ': 5.2.0 (Compatable with php 8.1.12)'],
['label' => $translator->translate('invoice.platform.mySqlVersion') . ': 5.7.31 || 8.0.31 '],
['label' => $translator->translate('invoice.platform.windowsVersion') . ': Windows 11 Pro Edition'],
['label' => $translator->translate('invoice.platform.PhpVersion') . ': 8.2.0 (Compatable with PhpAdmin 5.2.1)'],
['label' => $translator->translate('invoice.platform.PhpMyAdmin') . ': 5.2.0 (Compatable with php 8.2.0)'],
['label' => $translator->translate('invoice.platform.PhpSupport'), 'url' => 'https://php.net/supported-versions'],
['label' => $translator->translate('invoice.platform.update'), 'url' => 'https://wampserver.aviatechno.net/'],
['label' => $translator->translate('invoice.vendor.nikic.fast-route'), 'url' => 'https://github.com/nikic/FastRoute'],
Expand Down Expand Up @@ -339,12 +339,12 @@
['label' => 'Converting flattened file to php array', 'url' => 'https://wtools.io/convert-json-to-php-array'],
['label' => 'jQuery UI 1.13.2', 'url' => 'https://github.com/jquery/jquery-ui'],
['label' => 'LAMP'],
['label' => $translator->translate('invoice.platform.editor') . ': Apache Netbeans 12.4 64 bit'],
['label' => $translator->translate('invoice.platform.editor') . ': Apache Netbeans IDE 19 64 bit'],
['label' => $translator->translate('invoice.platform.server') . ': Ubuntu LTS 22.04 64 bit'],
['label' => 'Apache: 2.4.52 64 bit'],
['label' => $translator->translate('invoice.platform.mySqlVersion') . ': 5.7.31 || 8.0.29 '],
['label' => $translator->translate('invoice.platform.mySqlVersion') . ': 5.7.31 || 8.0.31 '],
['label' => $translator->translate('invoice.platform.PhpVersion') . ': 8.2.1 (Compatable with PhpAdmin 5.2.0)'],
['label' => $translator->translate('invoice.platform.PhpMyAdmin') . ': 5.2.0 (Compatable with php 8.1.2)'],
['label' => $translator->translate('invoice.platform.PhpMyAdmin') . ': 5.2.1 (Compatable with php 8.2.1)'],
['label' => $translator->translate('invoice.development.progress'), 'url' => $urlGenerator->generate('invoice/ubuntu')],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Auth\AuthService;
use App\Auth\Identity;
use App\Auth\IdentityRepository;
use App\Auth\Form\ResetForm;
use App\Auth\Form\ChangeForm;
use App\Service\WebControllerService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -19,7 +19,7 @@
use Yiisoft\User\CurrentUser;
use Yiisoft\Yii\View\ViewRenderer;

final class ResetController
final class ChangeController
{
public function __construct(
private Session $session,
Expand All @@ -34,16 +34,16 @@ public function __construct(
$this->session = $session;
$this->flash = new Flash($session);
$this->translator = $translator;
$this->viewRenderer = $viewRenderer->withControllerName('reset');
$this->viewRenderer = $viewRenderer->withControllerName('change');
}

public function reset(
public function change(
AuthService $authService,
Identity $identity,
IdentityRepository $identityRepository,
ServerRequestInterface $request,
FormHydrator $formHydrator,
ResetForm $resetForm
ChangeForm $changeForm
): ResponseInterface {
// permit an authenticated user, ie. not a guest, only and null!== current user
if (!$authService->isGuest()) {
Expand All @@ -56,8 +56,8 @@ public function reset(
// Identity and User are in a HasOne relationship so no null value
$login = $identity->getUser()?->getLogin();
if ($request->getMethod() === Method::POST
&& $formHydrator->populate($resetForm, $request->getParsedBody())
&& $resetForm->reset()
&& $formHydrator->populate($changeForm, $request->getParsedBody())
&& $changeForm->change()
) {
// Identity implements CookieLoginIdentityInterface: ensure the regeneration of the cookie auth key by means of $authService->logout();
// @see vendor\yiisoft\user\src\Login\Cookie\CookieLoginIdentityInterface
Expand All @@ -66,10 +66,10 @@ public function reset(
// PASSWORD CHANGE and other scenarios, that require forceful access revocation for old sessions.
// The authService logout function will regenerate the auth key here => overwriting any auth key
$authService->logout();
$this->flash_message('success', $this->translator->translate('validator.password.reset'));
$this->flash_message('success', $this->translator->translate('validator.password.change'));
return $this->redirectToMain();
}
return $this->viewRenderer->render('reset', ['formModel' => $resetForm, 'login' => $login]);
return $this->viewRenderer->render('change', ['formModel' => $changeForm, 'login' => $login]);
} // identity
} // identity_id
} // current user
Expand Down
38 changes: 19 additions & 19 deletions src/Auth/Form/ResetForm.php → src/Auth/Form/ChangeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Yiisoft\Validator\ValidatorInterface;
use Yiisoft\Validator\RulesProviderInterface;

final class ResetForm extends FormModel implements RulesProviderInterface
final class ChangeForm extends FormModel implements RulesProviderInterface
{
private string $login = '';
private string $password = '';
private string $password_verify = '';
private string $new_password = '';
private string $new_password_verify = '';
private string $passwordVerify = '';
private string $newPassword = '';
private string $newPasswordVerify = '';

public function __construct(
private AuthService $authService,
Expand All @@ -31,7 +31,7 @@ public function __construct(
) {
}

public function reset(): bool
public function change(): bool
{
if ($this->validator->validate($this)->isValid()) {
$user = $this->userRepository->findByLogin($this->getLogin());
Expand All @@ -49,27 +49,27 @@ public function reset(): bool
/**
* @return string[]
*
* @psalm-return array{login: string, password: string, password_verify: string, new_password: string, new_password_verify: string}
* @psalm-return array{login: string, password: string, passwordVerify: string, newPassword: string, newPasswordVerify: string}
*/
public function getAttributeLabels(): array
{
return [
'login' => $this->translator->translate('layout.login'),
'password' => $this->translator->translate('layout.password'),
'password_verify' => $this->translator->translate('layout.password-verify'),
'new_password' => $this->translator->translate('layout.password.new'),
'new_password_verify' => $this->translator->translate('layout.password-verify.new'),
'passwordVerify' => $this->translator->translate('layout.password-verify'),
'newPassword' => $this->translator->translate('layout.password.new'),
'newPasswordVerify' => $this->translator->translate('layout.password-verify.new'),
];
}

/**
* @return string
*
* @psalm-return 'Reset'
* @psalm-return 'Change'
*/
public function getFormName(): string
{
return 'Reset';
return 'Change';
}

public function getLogin(): string
Expand All @@ -84,17 +84,17 @@ public function getPassword(): string

public function getPasswordVerify(): string
{
return $this->password_verify;
return $this->passwordVerify;
}

public function getNewPassword(): string
{
return $this->new_password;
return $this->newPassword;
}

public function getNewPasswordVerify() : string
{
return $this->new_password_verify;
return $this->newPasswordVerify;
}

public function getRules(): array
Expand All @@ -112,12 +112,12 @@ function (mixed $value): Result {
},
],
'password' => $this->PasswordRules(),
'password_verify' => $this->PasswordVerifyRules(),
'new_password' => [
'passwordVerify' => $this->PasswordVerifyRules(),
'newPassword' => [
new Required(),
new Length(min: 8),
],
'new_password_verify' => $this->NewPasswordVerifyRules()
'newPasswordVerify' => $this->NewPasswordVerifyRules()
];
}

Expand Down Expand Up @@ -146,7 +146,7 @@ private function PasswordVerifyRules(): array
new Callback(
callback: function (): Result {
$result = new Result();
if (!($this->password === $this->password_verify)) {
if (!($this->password === $this->passwordVerify)) {
$result->addError($this->translator->translate('validator.password.not.match'));
}
return $result;
Expand All @@ -163,7 +163,7 @@ private function NewPasswordVerifyRules(): array
new Callback(
callback: function (): Result {
$result = new Result();
if (!($this->new_password === $this->new_password_verify)) {
if (!($this->newPassword === $this->newPasswordVerify)) {
$result->addError($this->translator->translate('validator.password.not.match.new'));
}
return $result;
Expand Down
4 changes: 3 additions & 1 deletion src/Invoice/Language/English/app_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,13 @@
'menu.signup' => 'Signup',
'menu.swagger' => 'Swagger',
'menu.users' => 'Users',
'reset'=> 'Reset Password',
'password.change' => 'Change Password',
'password.reset'=> 'Reset Password',
'signup' => 'Signup',
'validator.invalid.login.password' => 'Invalid login or password',
'validator.password.not.match' => 'Passwords do not match',
'validator.password.not.match.new' => 'Your new passwords do not match',
'validator.password.change' => 'Your Password has been changed',
'validator.password.reset' => 'Your Password has been reset',
'validator.user.exist' => 'A User with this login already exists',
'valiadator.user.exist.not' => 'A User with this login does not exist'
Expand Down

0 comments on commit 33ccf37

Please sign in to comment.