X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2F05_Authentication.pod;h=5c727c260e21f797ee9efb2c8e1cd740591d4611;hp=23f577d0f0e62482819bf5b97a8b53cde3135438;hb=fa59770d86a18a7bb7b8a111061fb99b68c39110;hpb=f588643fa29e325f98c4be9d714ca51439989639 diff --git a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod index 23f577d..5c727c2 100644 --- a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod +++ b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod @@ -330,29 +330,29 @@ for details. =head2 Add Login and Logout Controllers -Use the Catalyst create script to create a stub controller file: +Use the Catalyst create script to create two stub controller files: - $ script/myapp_create.pl controller Authentication + $ script/myapp_create.pl controller Login + $ script/myapp_create.pl controller Logout -You could easily use multiple controller's here. For example, you could -have a C controller for both C and C actions. +You could easily use a single controller here. For example, you could +have a C controller with both C and C actions. Remember, Catalyst is designed to be very flexible, and leaves such matters up to you, the designer and programmer. -Then open C, locate the +Then open C, locate the C method (or C if you are using an older version of Catalyst) that was automatically inserted by the helpers when we created the Login controller above, -and remove the definition of C. Add the following sub: +and update the definition of C to match: - =head2 login + =head2 index Login logic =cut - # global means the path to it will be /login not /authenticaton/login - sub login :Global :Args(0) { + sub index :Path :Args(0) { my ($self, $c) = @_; # Get the username and password from form @@ -367,11 +367,13 @@ and remove the definition of C. Add the following sub: # If successful, then let them use the application $c->response->redirect($c->uri_for( $c->controller('Books')->action_for('list'))); - return 1; + return; } else { + # Set an error message $c->stash(error_msg => "Bad username or password."); } } else { + # Set an error message $c->stash(error_msg => "Empty username or password."); } @@ -379,6 +381,10 @@ and remove the definition of C. Add the following sub: $c->stash(template => 'login.tt2'); } +Be sure to remove the +C<$c-Eresponse-Ebody('Matched MyApp::Controller::Login in Login.');> +line of the C. + This controller fetches the C and C values from the login form and attempts to authenticate the user. If successful, it redirects the user to the book list page. If the login fails, the user @@ -392,11 +398,16 @@ and partly for code clarity) only to use C in C, and then mainly to generate the 404 not found page for the application. -Instead, we are using "C" here to -specifically match the URL C. C actions create URI matches -relative to the web root. We make the match even more specific with the -C<:Args(0)> action modifier -- this forces the match on I C, -not C. +Instead, we are using "C" here to +specifically match the URL C. C actions (aka, "literal +actions") create URI matches relative to the namespace of the +controller where they are defined. Although C supports +arguments that allow relative and absolute paths to be defined, here +we use an empty C definition to match on just the name of the +controller itself. The method name, C, is arbitrary. We make +the match even more specific with the C<:Args(0)> action modifier -- +this forces the match on I C, not +C. Next, update the corresponding method in C to match: