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=1b6078f9c65a01068b9c152fef709fb5743e62e7;hp=6cc0c592e4d2a4e50ba9f5394a4529fe99bafe78;hb=080bb6202ae1dc9a786bb32afcb391f542c2f0fc;hpb=bbdce044f1df0dfb5fb12f826e95d9e69726df85 diff --git a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod index 6cc0c59..1b6078f 100644 --- a/lib/Catalyst/Manual/Tutorial/05_Authentication.pod +++ b/lib/Catalyst/Manual/Tutorial/05_Authentication.pod @@ -2,7 +2,6 @@ Catalyst::Manual::Tutorial::05_Authentication - Catalyst Tutorial - Chapter 5: Authentication - =head1 OVERVIEW This is B for the Catalyst tutorial. @@ -58,15 +57,15 @@ L Now that we finally have a simple yet functional application, we can focus on providing authentication (with authorization coming next in -Chapter 6). - -This chapter of the tutorial is divided into two main sections: 1) basic, -cleartext authentication and 2) hash-based authentication. +L). -You can checkout the source code for this example from the catalyst -subversion repository as per the instructions in -L. +This chapter of the tutorial is divided into two main sections: 1) +basic, cleartext authentication and 2) hash-based authentication. +Source code for the tutorial in included in the F directory +of the Tutorial Virtual machine (one subdirectory per chapter). There +are also instructions for downloading the code in +L. =head1 BASIC AUTHENTICATION @@ -78,8 +77,8 @@ application. First, we add both user and role information to the database (we will add the role information here although it will not be used until the -authorization section, Chapter 6). Create a new SQL script file by opening -C in your editor and insert: +authorization section, Chapter 6). Create a new SQL script file by +opening F in your editor and insert: -- -- Add users and role tables, along with a many-to-many join table @@ -116,7 +115,7 @@ C in your editor and insert: INSERT INTO user_role VALUES (2, 1); INSERT INTO user_role VALUES (3, 1); -Then load this into the C database with the following command: +Then load this into the F database with the following command: $ sqlite3 myapp.db < myapp02.sql @@ -124,39 +123,39 @@ Then load this into the C database with the following command: =head2 Add User and Role Information to DBIC Schema Although we could manually edit the DBIC schema information to include -the new tables added in the previous step, let's use the C -option on the DBIC model helper to do most of the work for us: +the new tables added in the previous step, let's use the +C option on the DBIC model helper to do most of the work +for us: $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \ create=static components=TimeStamp dbi:SQLite:myapp.db \ on_connect_do="PRAGMA foreign_keys = ON" - exists "/root/dev/MyApp/script/../lib/MyApp/Model" - exists "/root/dev/MyApp/script/../t" - Dumping manual schema for MyApp::Schema to directory /root/dev/MyApp/script/../lib ... + exists "/home/catalyst/dev/MyApp/script/../lib/MyApp/Model" + exists "/home/catalyst/dev/MyApp/script/../t" + Dumping manual schema for MyApp::Schema to directory /home/catalyst/dev/MyApp/script/../lib ... Schema dump completed. - exists "/root/dev/MyApp/script/../lib/MyApp/Model/DB.pm" + exists "/home/catalyst/dev/MyApp/script/../lib/MyApp/Model/DB.pm" $ $ ls lib/MyApp/Schema/Result Author.pm BookAuthor.pm Book.pm Role.pm User.pm UserRole.pm Notice how the helper has added three new table-specific Result Source -files to the C directory. And, more +files to the F directory. And, more importantly, even if there were changes to the existing result source -files, those changes would have only been written above the C<# DO NOT -MODIFY THIS OR ANYTHING ABOVE!> comment and your hand-edited +files, those changes would have only been written above the +C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment and your hand-edited enhancements would have been preserved. -Speaking of "hand-editted enhancements," we should now add the +Speaking of "hand-edited enhancements," we should now add the C relationship information to the User Result Source file. As with the Book, BookAuthor, and Author files in L, -L has -automatically created the C and C relationships -for the new User, UserRole, and Role tables. However, as a convenience -for mapping Users to their assigned roles (see -L), we will -also manually add a C relationship. Edit -C add the following information between +L has automatically created the C +and C relationships for the new User, UserRole, and Role +tables. However, as a convenience for mapping Users to their assigned +roles (see L), +we will also manually add a C relationship. Edit +F add the following information between the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment and the closing C<1;>: @@ -166,34 +165,35 @@ C<1;>: # 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 => 'user_roles', 'role_id'); + __PACKAGE__->many_to_many(roles => 'user_roles', 'role'); The code for this update is obviously very similar to the edits we made -to the C and C classes created in Chapter 3 with one +to the C and C classes created in +L with one exception: we only defined the C relationship in one direction. Whereas we felt that we would want to map Authors to Books B Books to Authors, here we are only adding the convenience C in the Users to Roles direction. Note that we do not need to make any change to the -C schema file. It simply tells DBIC to load all -of the Result Class and ResultSet Class files it finds in below the -C directory, so it will automatically pick up our -new table information. +F schema file. It simply tells DBIC to load all of +the Result Class and ResultSet Class files it finds below the +F directory, so it will automatically pick up our new +table information. =head2 Sanity-Check of the Development Server Reload We aren't ready to try out the authentication just yet; we only want to do a quick check to be sure our model loads correctly. Assuming that you -are following along and using the "-r" option on C, +are following along and using the "-r" option on F, then the development server should automatically reload (if not, press C to break out of the server if it's running and then enter -C