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=adf66fcac83c760a9f32cba123a86104ce75bdf8;hp=21ce7e0c827043203d31d1d498f1f89575e11101;hb=7ce05098c9b1df9078e709e5a724e821a3b3b00d;hpb=512ec6d005f882e9f4502be3bfc9db2be2e7e1fd diff --git a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod index 21ce7e0..adf66fc 100644 --- a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod +++ b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod @@ -225,11 +225,11 @@ C is new): -Debug ConfigLoader Static::Simple - + StackTrace - + Authentication - + Session Session::Store::File Session::State::Cookie @@ -349,18 +349,18 @@ Then open C, and update the definition of C to match: =head2 index - + Login logic - + =cut - + sub index :Path :Args(0) { my ($self, $c) = @_; - + # Get the username and password from form my $username = $c->request->params->{username}; my $password = $c->request->params->{password}; - + # If the username and password values were found in form if ($username && $password) { # Attempt to log the user in @@ -379,7 +379,7 @@ C to match: $c->stash(error_msg => "Empty username or password.") unless ($c->user_exists); } - + # If either of above don't work out, send to the login page $c->stash(template => 'login.tt2'); } @@ -411,17 +411,17 @@ Next, update the corresponding method in C to match: =head2 index - + Logout logic - + =cut - + sub index :Path :Args(0) { my ($self, $c) = @_; - + # Clear the user's state $c->logout; - + # Send the user to the starting point $c->response->redirect($c->uri_for('/')); } @@ -432,7 +432,7 @@ C to match: Create a login form by opening C and inserting: [% META title = 'Login' %] - +
@@ -463,17 +463,17 @@ Edit the existing C class file and insert the following method: =head2 auto - + Check if there is a user and, if not, forward to login page - + =cut - + # Note that 'auto' runs after 'begin' but before your actions and that # 'auto's "chain" (all from application path to most specific class are run) # See the 'Actions' section of 'Catalyst::Manual::Intro' for more info. sub auto :Private { my ($self, $c) = @_; - + # Allow unauthenticated users to reach the login page. This # allows unauthenticated users to reach any action in the Login # controller. To lock it down to a single action, we could use: @@ -483,7 +483,7 @@ the following method: if ($c->controller eq $c->controller('Login')) { return 1; } - + # If a user doesn't exist, force login if (!$c->user_exists) { # Dump a log message to the development server debug output @@ -493,7 +493,7 @@ the following method: # Return 0 to cancel 'post-auto' processing and prevent use of application return 0; } - + # User found, so return 1 to continue with processing after this 'auto' return 1; } @@ -671,16 +671,16 @@ file C in your editor and enter the following text: #!/usr/bin/perl - + use strict; use warnings; - + use MyApp::Schema; - + my $schema = MyApp::Schema->connect('dbi:SQLite:myapp.db'); - + my @users = $schema->resultset('User')->all; - + foreach my $user (@users) { $user->password('mypass'); $user->update; @@ -772,21 +772,21 @@ match the following (everything after the model search line of code has changed): =head2 delete - + Delete a book - + =cut - + sub delete :Chained('object') :PathPart('delete') :Args(0) { my ($self, $c) = @_; - + # Use the book object saved by 'object' and delete it along # with related 'book_authors' entries $c->stash->{object}->delete; - + # Use 'flash' to save information across requests until it's read $c->flash->{status_msg} = "Book deleted"; - + # Redirect the user back to the list page $c->response->redirect($c->uri_for($self->action_for('list'))); } @@ -833,7 +833,7 @@ we used above. Consult L for additional information. -=head2 Switch To Catalyst::Plugin::StatusMessages +=head2 Switch To Catalyst::Plugin::StatusMessages Although the query parameter technique we used in L and the C @@ -863,15 +863,15 @@ C to the list of plugins: -Debug ConfigLoader Static::Simple - + StackTrace - + Authentication - + Session Session::Store::File Session::State::Cookie - + StatusMessage /; @@ -880,14 +880,14 @@ action to match the following: sub delete :Chained('object') :PathPart('delete') :Args(0) { my ($self, $c) = @_; - + # Saved the PK id for status_msg below my $id = $c->stash->{object}->id; - + # Use the book object saved by 'object' and delete it along # with related 'book_authors' entries $c->stash->{object}->delete; - + # Redirect the user back to the list page $c->response->redirect($c->uri_for($self->action_for('list'), {mid => $c->set_status_msg("Deleted book $id")})); @@ -909,13 +909,13 @@ match: sub base :Chained('/') :PathPart('books') :CaptureArgs(0) { my ($self, $c) = @_; - + # Store the ResultSet in stash so it's available for other methods $c->stash(resultset => $c->model('DB::Book')); - + # Print a message to the debug log $c->log->debug('*** INSIDE BASE METHOD ***'); - + # Load status messages $c->load_status_msgs; }