From 84bc0f1bc49e1a301854cc43471e3787946fe8f9 Mon Sep 17 00:00:00 2001 From: s-ohnishi Date: Sun, 16 Apr 2023 16:32:57 +0900 Subject: [PATCH] remove malfunctions and duplicate actions --- src/Controllers/InvoicesController.php | 2 -- src/Controllers/ProductsController.php | 5 +++-- src/Controllers/RegisterController.php | 28 ++++++-------------------- src/Forms/RegisterForm.php | 6 +++++- src/Models/Products.php | 2 +- themes/invo/companies/index.volt | 2 +- themes/invo/products/index.volt | 2 +- themes/invo/products/search.volt | 2 +- themes/invo/producttypes/index.volt | 2 +- 9 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/Controllers/InvoicesController.php b/src/Controllers/InvoicesController.php index 748e7db1..c3155b3a 100644 --- a/src/Controllers/InvoicesController.php +++ b/src/Controllers/InvoicesController.php @@ -62,8 +62,6 @@ public function profileAction(): void $data = $this->request->getPost(); if ($form->isValid($data, $user)) { - $user->assign($data); - if (!$user->save()) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); diff --git a/src/Controllers/ProductsController.php b/src/Controllers/ProductsController.php index 9d7093f0..471c76d9 100644 --- a/src/Controllers/ProductsController.php +++ b/src/Controllers/ProductsController.php @@ -55,7 +55,8 @@ public function searchAction(): void $this->request->getPost() ); - $this->persistent->searchParams = $query->getParams(); + //$this->persistent->searchParams = $query->getParams(); + $this->persistent->searchParams = array('di'=>null) + $query->getParams(); } $parameters = []; @@ -77,7 +78,7 @@ public function searchAction(): void $paginator = new Paginator([ 'model' => Products::class, - 'data' => $products, + "parameters" => $parameters, 'limit' => 10, 'page' => $this->request->getQuery('page', 'int', 1), ]); diff --git a/src/Controllers/RegisterController.php b/src/Controllers/RegisterController.php index 47dbb80a..ba9c5948 100644 --- a/src/Controllers/RegisterController.php +++ b/src/Controllers/RegisterController.php @@ -42,29 +42,13 @@ public function indexAction(): void $form = new RegisterForm(); if ($this->request->isPost()) { - if ($form->isValid($this->request->getPost(), new Users())) { - $password = $this->request->getPost('password'); - $repeatPassword = $this->request->getPost('repeatPassword'); + $newUser = new Users(); + if ($form->isValid($this->request->getPost(), $newUser)) { + $newUser->password = sha1($form->getFilteredValue('password')); + $newUser->created_at = new RawValue('now()'); + $newUser->active = Status::ACTIVE; - if ($password !== $repeatPassword) { - $this->flash->error('Passwords are different'); - - return; - } - - $user = new Users(); - $user->username = $this->request->getPost('username', 'alphanum'); - $user->password = sha1($password); - $user->name = $this->request->getPost('name', ['string', 'striptags']); - $user->email = $this->request->getPost('email', 'email'); - $user->created_at = new RawValue('now()'); - $user->active = Status::ACTIVE; - - if (!$user->save()) { - foreach ($user->getMessages() as $message) { - $this->flash->error((string) $message); - } - } else { + if ($newUser->save()) { $this->flash->success( 'Thanks for sign-up, please log-in to start generating invoices' ); diff --git a/src/Forms/RegisterForm.php b/src/Forms/RegisterForm.php index 90e7330c..d0b902b7 100644 --- a/src/Forms/RegisterForm.php +++ b/src/Forms/RegisterForm.php @@ -16,6 +16,8 @@ use Phalcon\Filter\Validation\Validator\Email; use Phalcon\Filter\Validation\Validator\PresenceOf; use Phalcon\Filter\Validation\Validator\Uniqueness as UniquenessValidator; +use Phalcon\Filter\Validation\Validator\Confirmation; +use Phalcon\Filter\Validation\Validator\StringLength\Min; use Phalcon\Forms\Element\Password; use Phalcon\Forms\Element\Text; use Phalcon\Forms\Form; @@ -45,7 +47,7 @@ public function initialize($entity = null, $options = null) */ $name = new Text('username'); $name->setLabel('Username'); - $name->setFilters(['alphanum']); + $name->setFilters(['alnum']); $name->addValidators([ new PresenceOf(['message' => 'Please enter your desired user name']), new UniquenessValidator( @@ -82,6 +84,7 @@ public function initialize($entity = null, $options = null) $password->setLabel('Password'); $password->addValidators([ new PresenceOf(['message' => 'Password is required']), + new Min(['min' => 8, 'message' => 'Password must be at least 8 characters']), ]); $this->add($password); @@ -93,6 +96,7 @@ public function initialize($entity = null, $options = null) $repeatPassword->setLabel('Repeat Password'); $repeatPassword->addValidators([ new PresenceOf(['message' => 'Confirmation password is required']), + new Confirmation(["message" => "Passwords are different", "with" => "password",]), ]); $this->add($repeatPassword); diff --git a/src/Models/Products.php b/src/Models/Products.php index ed3646fe..a1ed375e 100644 --- a/src/Models/Products.php +++ b/src/Models/Products.php @@ -58,7 +58,7 @@ public function initialize() 'id', [ 'reusable' => true, - 'alias' => 'productType' + 'alias' => 'productTypes', ] ); } diff --git a/themes/invo/companies/index.volt b/themes/invo/companies/index.volt index e74e738b..cd24dec5 100644 --- a/themes/invo/companies/index.volt +++ b/themes/invo/companies/index.volt @@ -7,7 +7,7 @@ -
+ {% for element in form %} {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} {{ element }} diff --git a/themes/invo/products/index.volt b/themes/invo/products/index.volt index 0791313a..76aedb07 100644 --- a/themes/invo/products/index.volt +++ b/themes/invo/products/index.volt @@ -7,7 +7,7 @@ - + {% for element in form %} {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %} {{ element }} diff --git a/themes/invo/products/search.volt b/themes/invo/products/search.volt index 4852da35..321795a6 100644 --- a/themes/invo/products/search.volt +++ b/themes/invo/products/search.volt @@ -23,7 +23,7 @@ {% endif %} {{ product.id }} - {{ product.productType.name }} + {{ product.productTypes.name }} {{ product.name }} ${{ "%.2f"|format(product.price) }} {{ product.getActiveDetail() }} diff --git a/themes/invo/producttypes/index.volt b/themes/invo/producttypes/index.volt index 11efc8be..3c1f53c4 100644 --- a/themes/invo/producttypes/index.volt +++ b/themes/invo/producttypes/index.volt @@ -7,7 +7,7 @@ - +
{{ numeric_field("id", "size": 10, "maxlength": 10, "class": "form-control") }}