Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Authorization no Laravel 5.1

799efab30a6db8436e6941dfd372c66f?s=47 Zizaco
September 30, 2015

Authorization no Laravel 5.1

Authorization no Laravel 5.1

Vídeo da Apresentação (2015/09/30): https://www.youtube.com/watch?v=hJRt0BDF0Do

Luiz Fernando / Zizaco
http://zizaco.net
Leroy Merlin

ACL

308 mil
Instalações do Entrust
449 mil
Instalações do Sentry
12%
Do total de instalações do Laravel

Taylor Otwell

O que é Laravel?
"A framework is a set of classes (code) that embodies an abstract design for solutions to a family of related problems."
- Brian Foote

O que é Laravel?

Laravel's (5.1.11)
Authorization
https://laravel-news.com/2015/08/laravel-5-1-11-released-now-with-authorization/

Gate
(Portão)

Gate::allows('edit-post', $post);
// true | false

@can('edit-post', $post)
...
@else
...
@endcan

Gate::forUser($user)->denies('edit-post', $post);
// true | false

$gate->allows('edit-post', $post);
// true | false

$user->can('edit-post', $post);
// true | false

Ability (Capacidade)
Gate (Portão)
Polices (Política)

( Live Coding )

Roles & Permissions ?

An Ability that check the Database

Role (Papel)
Permission (Permissão)

( Live Coding )

Ability
Gate
Polices
Role (custom)
Permission (custom)

Role (package)
Permission (package)
Entrust v2.0?

Perguntas?

799efab30a6db8436e6941dfd372c66f?s=128

Zizaco

September 30, 2015
Tweet

Transcript

  1. Authorization no Laravel 5.1

  2. Hello! Programador Desenvolvedor web WebDesigner wannabe Leroy Merlin (Laravel) Sempre

    mais http://zizaco.net Luiz Fernando / Zizaco
  3. ACL

  4. 308 mil Instalações do Entrust

  5. 308 mil Instalações do Entrust 449 mil Instalações do Sentry

    12% Do total de instalações do Laravel
  6. Taylor Otwell

  7. O que é Laravel? "A framework is a set of

    classes (code) that embodies an abstract design for solutions to a family of related problems." - Brian Foote
  8. O que é Laravel? A B C

  9. O que é Laravel? A B C

  10. https://laravel-news.com/2015/08/laravel-5-1-11-released-now-with-authorization/

  11. Laravel's (5.1.11) Authorization

  12. Gate (Portão)

  13. Gate::allows('edit-post', $post); // true | false @can('edit-post', $post) ... @else

    ... @endcan Gate::forUser($user)->denies('edit-post', $post); // true | false
  14. $gate->allows('edit-post', $post); // true | false @can('edit-post', $post) ... @else

    ... @endcan $user->can('edit-post', $post); // true | false
  15. Ability Gate Polices (Capacidade) (Política) (Portão)

  16. ( Live Coding )

  17. Ability Gate Polices

  18. ( Live Coding )

  19. ... protected $abilities = []; protected $policies = []; function

    ($user, ...$params) { } Ability Gate class FooBarPolicy { public function ability($user, ...$params) Polices
  20. Ability Gate Polices $gate->define('edit-post', function ($user, $post) { return $post->user_id

    === $user->id; }); $gate->policy('App\Post', 'App\Policies\PostPolicy'); class PostPolicy { public function edit($user, $post) { return $post->user_id === $user->id;
  21. Gate Gate::allows('edit-post', $post); // true | false Gate::allows('edit', $post); //

    true | false @can('edit', $post); ... @can('edit-post', $post) ... @else ... @endcan
  22. Mr. John Doe { Super Admin } johndoe@foobar.com

  23. Mr. John Doe { Super Admin } johndoe@foobar.com Roles &

    Permissions ?
  24. Mr. John Doe { Super Admin } johndoe@foobar.com An Ability

    that check the Database
  25. Ability Gate Polices Role (custom) Permission (custom) (Papel) (Permissão)

  26. ( Live Coding )

  27. Ability Gate Polices Role (custom) Permission (custom)

  28. Ability Gate Polices Role (package) Permission (package) Entrust v2.0?

  29. Mr. John Doe { Super Admin } johndoe@foobar.com Perguntas?