Skip to content

Commit

Permalink
Validacao de formularios 2 aula 24
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Pessanha da Silva committed Sep 17, 2021
1 parent 32bd142 commit 271393b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Models\User;
use App\Models\UserPermission;
use Respect\Validation\Validator as v;
use DateTime;

Class AuthController extends Controller
Expand All @@ -19,7 +20,17 @@ public function login($request, $response)
public function register($request, $response)
{
if($request->isGet())
return $this->container->view->render($response, 'register.twig');
return $this->container->view->render($response, 'register.twig');

$validation = $this->container->validator->validate($request,[
'name' => v::notEmpty()->alpha()->length(10), // Validação para não vim vazio, tem que ser alfanumérico e ter no minimo 10 Caracteres
'email' => v::notEmpty()->noWhitespace()->email(), // Validação de email
'password' => v::notEmpty()->noWhitespace()
]);

if($validation->failed())
return $response->withRedirect($this->container->router->pathFor('auth.register'));


// ajustando data
$now = new \DateTime();
Expand Down
2 changes: 1 addition & 1 deletion app/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Respect\Validation\Exceptions\NestedValidationException;

class Validation
class Validator
{
private $errors;

Expand Down
4 changes: 4 additions & 0 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
$capsule->setAsGlobal();
$capsule->bootEloquent();

$container['validator'] = function($container){
return new App\Validation\Validator;
};

//configurando o Twig template
$container['view'] = function($container){
$view = new Slim\Views\Twig(__DIR__ . '/../resources/views', [
Expand Down

0 comments on commit 271393b

Please sign in to comment.