From: Kennedy Clark Date: Tue, 26 May 2009 02:45:27 +0000 (+0000) Subject: Finish review for depluralization and related updates X-Git-Tag: v5.8005~140 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=commitdiff_plain;h=2a6eb5f9e3b1b3a8dacd724bb8ab87ba18f733a5;hp=fce83e5f2a2da9f9117562d05aec1e161cc3c109 Finish review for depluralization and related updates --- diff --git a/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod index 3e7e02e..e63500d 100644 --- a/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod @@ -1066,9 +1066,9 @@ time entered for it (see the last line in the listing below): Notice in the debug log that the SQL DBIC generated has changed to incorporate the datetime logic: - INSERT INTO book ( created, rating, title, updated) VALUES ( ?, ?, ?, ? ): + INSERT INTO book ( created, rating, title, updated ) VALUES ( ?, ?, ?, ? ): '2009-05-25 20:39:41', '5', 'TCPIP_Illustrated_Vol-2', '2009-05-25 20:39:41' - INSERT INTO book_author ( author_id, book_id) VALUES ( ?, ? ): '4', '10' + INSERT INTO book_author ( author_id, book_id ) VALUES ( ?, ? ): '4', '10' =head2 Create a ResultSet Class diff --git a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod index 6c41ec7..40fd38f 100644 --- a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod +++ b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod @@ -159,7 +159,7 @@ C: # 1) Name of relationship, DBIC will create accessor with this name # 2) Name of the model class referenced by this relationship # 3) Column name in *foreign* table (aka, foreign key in peer table) - __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'user_id'); + __PACKAGE__->has_many(map_user_roles => 'MyApp::Schema::Result::UserRole', 'user_id'); # many_to_many(): # args: @@ -167,7 +167,7 @@ C: # 2) Name of has_many() relationship this many_to_many() is shortcut for # 3) Name of belongs_to() relationship in model class of has_many() above # You must already have the has_many() defined to use a many_to_many(). - __PACKAGE__->many_to_many(roles => 'map_user_role', 'role'); + __PACKAGE__->many_to_many(roles => 'map_user_roles', 'role'); C: @@ -181,7 +181,7 @@ C: # 1) Name of relationship, DBIC will create accessor with this name # 2) Name of the model class referenced by this relationship # 3) Column name in *foreign* table (aka, foreign key in peer table) - __PACKAGE__->has_many(map_user_role => 'MyApp::Schema::Result::UserRole', 'role_id'); + __PACKAGE__->has_many(map_user_roles => 'MyApp::Schema::Result::UserRole', 'role_id'); C: @@ -253,7 +253,8 @@ Edit C and update it as follows (everything below C is new): # Load plugins - use Catalyst qw/-Debug + use Catalyst qw/ + -Debug ConfigLoader Static::Simple @@ -745,12 +746,20 @@ password stored for this user. Then run the following command: - $ perl -Ilib set_hashed_passwords.pl + $ DBIC_TRACE=1 perl -Ilib set_hashed_passwords.pl We had to use the C<-Ilib> arguement to tell perl to look under the C directory for our C model. -Then dump the users table to verify that it worked: +The DBIC_TRACE output should show that the update worked: + + $ DBIC_TRACE=1 perl -Ilib set_hashed_passwords.pl + SELECT me.id, me.username, me.password, me.email_address, me.first_name, me.last_name, me.active FROM user me: + UPDATE user SET password = ? WHERE ( id = ? ): 'oXiyAcGOjowz7ISUhpIm1IrS8AxSZ9r4jNjpX9VnVeQmN6GRtRKTz', '1' + UPDATE user SET password = ? WHERE ( id = ? ): 'PmyEPrkB8EGwvaF/DvJm7LIfxoZARjv8ygFIR7pc1gEA1OfwHGNzs', '2' + UPDATE user SET password = ? WHERE ( id = ? ): 'h7CS1Fm9UCs4hjcbu2im0HumaHCJUq4Uriac+SQgdUMUfFSoOrz3c', '3' + +But we can further confirm our actions by dumping the users table: $ sqlite3 myapp.db "select * from user" 1|test01|38d3974fa9e9263099f7bc2574284b2f55473a9bM=fwpX2NR8|t01@na.com|Joe|Blow|1 diff --git a/lib/Catalyst/Manual/Tutorial/06_Authorization.pod b/lib/Catalyst/Manual/Tutorial/06_Authorization.pod index cda2f7b..61248a4 100644 --- a/lib/Catalyst/Manual/Tutorial/06_Authorization.pod +++ b/lib/Catalyst/Manual/Tutorial/06_Authorization.pod @@ -79,7 +79,8 @@ Catalyst. Edit C and add C to the list: # Load plugins - use Catalyst qw/-Debug + use Catalyst qw/ + -Debug ConfigLoader Static::Simple @@ -107,6 +108,7 @@ like this: 'Catalyst::Plugin::Authorization::Roles' => '0', ); + =head2 Add Role-Specific Logic to the "Book List" Template Open C in your editor and add the following @@ -117,7 +119,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 %]

@@ -175,9 +177,9 @@ 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; @@ -305,7 +307,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 diff --git a/lib/Catalyst/Manual/Tutorial/08_Testing.pod b/lib/Catalyst/Manual/Tutorial/08_Testing.pod index c8671c0..71045a6 100644 --- a/lib/Catalyst/Manual/Tutorial/08_Testing.pod +++ b/lib/Catalyst/Manual/Tutorial/08_Testing.pod @@ -237,7 +237,12 @@ editor and enter the following: # Log in as each user # Specify username and password on the URL $ua1->get_ok("http://localhost/login?username=test01&password=mypass", "Login 'test01'"); - $ua1->get_ok("http://localhost/login?username=test02&password=mypass", "Login 'test02'"); + # Could make user2 like user1 above, but use the form to show another way + $ua2->submit_form( + fields => { + username => 'test02', + password => 'mypass', + }); # Go back to the login page and it should show that we are already logged in $_->get_ok("http://localhost/login", "Return to '/login'") for $ua1, $ua2;