Skip to content

Commit

Permalink
Merge pull request #110 from s-ohnishi/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson authored Jul 19, 2023
2 parents 552d325 + 84bc0f1 commit 28b66fd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 32 deletions.
2 changes: 0 additions & 2 deletions src/Controllers/InvoicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Controllers/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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),
]);
Expand Down
28 changes: 6 additions & 22 deletions src/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
6 changes: 5 additions & 1 deletion src/Forms/RegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function initialize()
'id',
[
'reusable' => true,
'alias' => 'productType'
'alias' => 'productTypes',
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion themes/invo/companies/index.volt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</div>

<form action="/companies/search" role="form" method="get">
<form action="/companies/search" role="form" method="post">
{% for element in form %}
{% if is_a(element, 'Phalcon\Forms\Element\Hidden') %}
{{ element }}
Expand Down
2 changes: 1 addition & 1 deletion themes/invo/products/index.volt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</div>

<form action="/products/search" role="form" method="get">
<form action="/products/search" role="form" method="post">
{% for element in form %}
{% if is_a(element, 'Phalcon\Forms\Element\Hidden') %}
{{ element }}
Expand Down
2 changes: 1 addition & 1 deletion themes/invo/products/search.volt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% endif %}
<tr>
<td>{{ product.id }}</td>
<td>{{ product.productType.name }}</td>
<td>{{ product.productTypes.name }}</td>
<td>{{ product.name }}</td>
<td>${{ "%.2f"|format(product.price) }}</td>
<td>{{ product.getActiveDetail() }}</td>
Expand Down
2 changes: 1 addition & 1 deletion themes/invo/producttypes/index.volt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</div>

<form action="/producttypes/search" role="form" method="get">
<form action="/producttypes/search" role="form" method="post">
<div class="form-group">
<label for="id">Id</label>
{{ numeric_field("id", "size": 10, "maxlength": 10, "class": "form-control") }}
Expand Down

0 comments on commit 28b66fd

Please sign in to comment.