X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2F06_Authorization.pod;h=456c5e57a2d19ff61f3950003f2925dc2feec20a;hp=cda2f7b2c06f76f2ca20c1251237bc07e91a5fed;hb=6c0f71ee33481d3a2793a4e4a94cb6172a4971b2;hpb=3ab6187c1a123983b6ae29e57f543328ce15755c diff --git a/lib/Catalyst/Manual/Tutorial/06_Authorization.pod b/lib/Catalyst/Manual/Tutorial/06_Authorization.pod index cda2f7b..456c5e5 100644 --- a/lib/Catalyst/Manual/Tutorial/06_Authorization.pod +++ b/lib/Catalyst/Manual/Tutorial/06_Authorization.pod @@ -78,34 +78,27 @@ Catalyst. Edit C and add C to the list: - # Load plugins - use Catalyst qw/-Debug - ConfigLoader - Static::Simple - - StackTrace - - Authentication - Authorization::Roles - - Session - Session::Store::FastMmap - Session::State::Cookie - /; + # Load plugins + use Catalyst qw/ + -Debug + ConfigLoader + Static::Simple + + StackTrace + + Authentication + Authorization::Roles + + Session + Session::Store::FastMmap + Session::State::Cookie + /; -B As discussed in MoreCatalystBasics, different versions of -C have used a variety of methods to load the plugins. -You can put the plugins in the C statement if you -prefer. +Once again, include this additional plugin as a new dependency in +the Makefile.PL file like this: -Once again (remain sharp, by now you should be getting the hang of things) -include this additional plugin as a new dependency in the Makefile.PL file -like this: + requires 'Catalyst::Plugin::Authorization::Roles'; - requires ( - ... - 'Catalyst::Plugin::Authorization::Roles' => '0', - ); =head2 Add Role-Specific Logic to the "Book List" Template @@ -117,7 +110,7 @@ lines to the bottom of the file:
    [% # Dump list of roles -%] - [% FOR role = c.user.role %]
  • [% role %]
  • [% END %] + [% FOR role = c.user.roles %]
  • [% role %]
  • [% END %]

@@ -136,7 +129,7 @@ lines to the bottom of the file:

This code displays a different combination of links depending on the -roles assigned to the user. +roles assigned to the user. =head2 Limit Books::add to 'admin' Users @@ -175,15 +168,13 @@ updating C to match the following code: # Add a record to the join table for this book, mapping to # appropriate author - $book->add_to_book_author({author_id => $author_id}); + $book->add_to_book_authors({author_id => $author_id}); # Note: Above is a shortcut for this: - # $book->create_related('book_author', {author_id => $author_id}); + # $book->create_related('book_authors', {author_id => $author_id}); - # Assign the Book object to the stash for display in the view - $c->stash->{book} = $book; - - # Set the TT template to use - $c->stash->{template} = 'books/create_done.tt2'; + # Assign the Book object to the stash and set template + $c->stash(book => $book, + template => 'books/create_done.tt2'); } else { # Provide very simple feedback to the user. $c->response->body('Unauthorized!'); @@ -209,10 +200,9 @@ C and C<=end> after the closing C<}>. =head2 Try Out Authentication And Authorization -Press C to kill the previous server instance (if it's still -running) and restart it: +Make sure the development server is running: - $ script/myapp_server.pl + $ script/myapp_server.pl -r Now trying going to L and you should be taken to the login page (you might have to C or @@ -305,7 +295,7 @@ match the following code: # Redirect the user back to the list page $c->response->redirect($c->uri_for($self->action_for('list'))); - } + } Here, we C to an error page if the user is lacking the appropriate permissions. For this to work, we need to make @@ -318,10 +308,10 @@ C and add this method: =cut - sub error_noperms :Chained('/') :PathPath('error_noperms') :Args(0) { + sub error_noperms :Chained('/') :PathPart('error_noperms') :Args(0) { my ($self, $c) = @_; - $c->stash->{template} = 'error_noperms.tt2'; + $c->stash(template => 'error_noperms.tt2'); } And also add the template file by putting the following text into @@ -329,10 +319,6 @@ C: Permission Denied -Then run the Catalyst development server script: - - $ script/myapp_server.pl - Log in as C and create several new books using the C feature: @@ -355,7 +341,7 @@ Kennedy Clark, C Please report any errors, issues or suggestions to the author. The most recent version of the Catalyst Tutorial can be found at -L. +L. Copyright 2006-2008, Kennedy Clark, under Creative Commons License (L).