X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAuthentication%2FStore%2FDBIx%2FClass.pm;fp=lib%2FCatalyst%2FAuthentication%2FStore%2FDBIx%2FClass.pm;h=1e87db81117b0a3b5612daf0172b6065f09ce841;hb=f23f0b3139cd323019a7b1494e7e245b3600e817;hp=a1742cec9d755b17f6b9f7370d42c8f823b33770;hpb=31183256bf1ebcbe77652ddf42fd211eb98930d9;p=catagits%2FCatalyst-Authentication-Store-DBIx-Class.git diff --git a/lib/Catalyst/Authentication/Store/DBIx/Class.pm b/lib/Catalyst/Authentication/Store/DBIx/Class.pm index a1742ce..1e87db8 100644 --- a/lib/Catalyst/Authentication/Store/DBIx/Class.pm +++ b/lib/Catalyst/Authentication/Store/DBIx/Class.pm @@ -100,41 +100,40 @@ This documentation refers to version 0.1502. Authentication Authorization::Roles/; - __PACKAGE__->config->{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', - } - } - } - }; + __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, $c ) = @_; + my ( $self, $ctx ) = @_; - $c->authenticate({ - screen_name => $c->req->params->{username}, - password => $c->req->params->{password}, + $ctx->authenticate({ + screen_name => $ctx->req->params->{username}, + password => $ctx->req->params->{password}, status => [ 'registered', 'loggedin', 'active'] })) } # verify a role - if ( $c->check_user_roles( 'editor' ) ) { + if ( $ctx->check_user_roles( 'editor' ) ) { # do editor stuff } @@ -154,25 +153,24 @@ L for a simplified setup. The DBIx::Class storage module has several configuration options - __PACKAGE__->config->{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, - } - } - } - }; + __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, + } + } + } + }); =over 4 @@ -183,7 +181,7 @@ contains the class name of the store to be used. =item user_model -Contains the model name (as passed to $c->model()) of the DBIx::Class schema +Contains the model name (as passed to C<< $ctx->model() >>) of the DBIx::Class schema to use as the source for user information. This config item is B. (Note that this option used to be called C<< user_class >>. C<< user_class >> is @@ -215,7 +213,7 @@ identifying the role. =item ignore_fields_in_find This item is an array containing fields that may be passed to the -$c->authenticate() routine (and therefore find_user in the storage class), but +C<< $ctx->authenticate() >> routine (and therefore find_user in the storage class), but which should be ignored when creating the DBIx::Class search to retrieve a user. This makes it possible to avoid problems when a credential requires an authinfo element whose name overlaps with a column name in your users table. @@ -232,11 +230,11 @@ is retrieved from the session and used as-is. B: Since the user object's column data is only stored in the session during the initial authentication of the user, turning this on can potentially lead to a situation where the data -in $c->user is different from what is stored the database. You can force -a reload of the data from the database at any time by calling $c->user->get_object(1); -Note that this will update $c->user for the remainder of this request. +in C<< $ctx->user >> is different from what is stored the database. You can force +a reload of the data from the database at any time by calling C<< $ctx->user->get_object(1); >> +Note that this will update C<< $ctx->user >> for the remainder of this request. It will NOT update the session. If you need to update the session -you should call $c->update_user_in_session() as well. +you should call C<< $ctx->update_user_in_session() >> as well. =item store_user_class @@ -267,7 +265,7 @@ is not used at all. The L storage module is not called directly from application code. You interface with it -through the $c->authenticate() call. +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 @@ -280,9 +278,9 @@ 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 ($c->authenticate({ - screen_name => $c->req->params->{'username'}, - password => $c->req->params->{'password'}, + if ($ctx->authenticate({ + screen_name => $ctx->req->params->{'username'}, + password => $ctx->req->params->{'password'}, status => [ 'registered', 'active', 'loggedin'] })) { @@ -344,7 +342,7 @@ the two arguments to the search() method from L. If pro all other args are ignored, and the search args provided are used directly to locate the user. An example will probably make more sense: - if ($c->authenticate( + if ($ctx->authenticate( { password => $password, 'dbix_class' => @@ -388,10 +386,10 @@ The B method of retrieval allows you to directly specify a resultset to be used for user retrieval. This allows you to create a resultset within your login action and use it for retrieving the user. A simple example: - my $rs = $c->model('MyApp::User')->search({ email => $c->request->params->{'email'} }); + my $rs = $ctx->model('MyApp::User')->search({ email => $ctx->request->params->{'email'} }); ... # further $rs adjustments - if ($c->authenticate({ + if ($ctx->authenticate({ password => $password, 'dbix_class' => { resultset => $rs } })) {