|
NAMECatalyst::Authentication::Store::DBIx::Class - A storage class for Catalyst Authentication using DBIx::ClassVERSIONThis documentation refers to version 0.1506.SYNOPSISuse Catalyst qw/ Authentication Authorization::Roles/; __PACKAGE__->config('Plugin::Authentication' => { default_realm => 'members', realms => { members => { credential => { class => 'Password', password_field => 'password', password_type => 'clear' }, store => { class => 'DBIx::Class', user_model => 'MyApp::User', role_relation => 'roles', role_field => 'rolename', } } } }); # Log a user in: sub login : Global { my ( $self, $ctx ) = @_; $ctx->authenticate({ screen_name => $ctx->req->params->{username}, password => $ctx->req->params->{password}, status => [ 'registered', 'loggedin', 'active'] })) } # verify a role if ( $ctx->check_user_roles( 'editor' ) ) { # do editor stuff } DESCRIPTIONThe Catalyst::Authentication::Store::DBIx::Class class provides access to authentication information stored in a database via DBIx::Class.CONFIGURATIONThe DBIx::Class authentication store is activated by setting the store config's class element to DBIx::Class as shown above. See the Catalyst::Plugin::Authentication documentation for more details on configuring the store. You can also use Catalyst::Authentication::Realm::SimpleDB for a simplified setup.The DBIx::Class storage module has several configuration options __PACKAGE__->config('Plugin::Authentication' => { default_realm => 'members', realms => { members => { credential => { # ... }, store => { class => 'DBIx::Class', user_model => 'MyApp::User', role_relation => 'roles', role_field => 'rolename', ignore_fields_in_find => [ 'remote_name' ], use_userdata_from_session => 1, } } } });
USAGEThe Catalyst::Authentication::Store::DBIx::Class storage module is not called directly from application code. You interface with it through the $ctx->authenticate() call.There are three methods you can use to retrieve information from the DBIx::Class storage module. They are Simple retrieval, and the advanced retrieval methods Searchargs and Resultset. Simple RetrievalThe first, and most common, method is simple retrieval. As its name implies simple retrieval allows you to simply to provide the column => value pairs that should be used to locate the user in question. An example of this usage is below:if ($ctx->authenticate({ screen_name => $ctx->req->params->{'username'}, password => $ctx->req->params->{'password'}, status => [ 'registered', 'active', 'loggedin'] })) { # ... authenticated user code here } The above example would attempt to retrieve a user whose username column (here, screen_name) matched the username provided, and whose status column matched one of the values provided. These name => value pairs are used more or less directly in the DBIx::Class search() routine, so in most cases, you can use DBIx::Class syntax to retrieve the user according to whatever rules you have. NOTE: Because the password in most cases is encrypted - it is not used directly but its encryption and comparison with the value provided is usually handled by the Password Credential. Part of the Password Credential's behavior is to remove the password argument from the authinfo that is passed to the storage module. See Catalyst::Authentication::Credential::Password. One thing you need to know about this retrieval method is that the name portion of the pair is checked against the user class's column list. Pairs are only used if a matching column is found. Other pairs will be ignored. This means that you can only provide simple name-value pairs, and that some more advanced DBIx::Class constructs, such as '-or', '-and', etc. are in most cases not possible using this method. For queries that require this level of functionality, see the 'searchargs' method below. Advanced RetrievalThe Searchargs and Resultset retrieval methods are used when more advanced features of the underlying DBIx::Class schema are required. These methods provide a direct interface with the DBIx::Class schema and therefore require a better understanding of the DBIx::Class module.The dbix_class key Since the format of these arguments are often complex, they are not keys in the base authinfo hash. Instead, both of these arguments are placed within a hash attached to the store-specific 'dbix_class' key in the base $authinfo hash. When the DBIx::Class authentication store sees the 'dbix_class' key in the passed authinfo hash, all the other information in the authinfo hash is ignored and only the values within the 'dbix_class' hash are used as though they were passed directly within the authinfo hash. In other words, if 'dbix_class' is present, it replaces the authinfo hash for processing purposes. The 'dbix_class' hash can be used to directly pass arguments to the DBIx::Class authentication store. Reasons to do this are to avoid credential modification of the authinfo hash, or to avoid overlap between credential and store key names. It's a good idea to avoid using it in this way unless you are sure you have an overlap/modification issue. However, the two advanced retrieval methods, searchargs, result and resultset, require its use, as they are only processed as part of the 'dbix_class' hash.
METHODSThere are no publicly exported routines in the DBIx::Class authentication store (or indeed in most authentication stores). However, below is a description of the routines required by Catalyst::Plugin::Authentication for all authentication stores. Please see the documentation for Catalyst::Plugin::Authentication::Internals for more information.new ( $config, $app )Constructs a new store object.find_user ( $authinfo, $c )Finds a user using the information provided in the $authinfo hashref and returns the user, or undef on failure. This is usually called from the Credential. This translates directly to a call to Catalyst::Authentication::Store::DBIx::Class::User's load() method.for_session ( $c, $user )Prepares a user to be stored in the session. Currently returns the value of the user's id field (as indicated by the 'id_field' config element)from_session ( $c, $frozenuser)Revives a user from the session based on the info provided in $frozenuser. Currently treats $frozenuser as an id and retrieves a user with a matching id.user_supportsProvides information about what the user object supports.auto_update_user( $authinfo, $c, $res )This method is called if the realm's auto_update_user setting is true. It will delegate to the user object's "auto_update" method.auto_create_user( $authinfo, $c )This method is called if the realm's auto_create_user setting is true. It will delegate to the user class's (resultset) "auto_create" method.NOTESAs of the current release, session storage consists of simply storing the user's id in the session, and then using that same id to re-retrieve the user's information from the database upon restoration from the session. More dynamic storage of user information in the session is intended for a future release.BUGS AND LIMITATIONSNone known currently; please email the author if you find any.SEE ALSOCatalyst::Plugin::Authentication, Catalyst::Plugin::Authentication::Internals, and Catalyst::Plugin::Authorization::RolesAUTHORJason Kuri (jayk@cpan.org)LICENSECopyright (c) 2007 the aforementioned authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |