たろマーク (はてなブックマーク)
-
[ django ] view を class based で書けるようになってた。
- Colorful Bokeh Effect in Pixelmator | Abduzeedo | Graphic Design Inspiration and Photoshop Tutorials
[ pixelmator ] -
[ pixelmator ]
■ CA::Creditional::* で auto_create
ちょっと人に頼まれて、livedoor の認証 API を Catalyst で使うために Catalyst::Authentication::Credential::Livedoor を Catalyst::Plugin::Authentication::Credential::Livedoor からパクリつつ実装してたんだけど、認証 API だと元々手元の DB にはそのユーザはいないので、CA::Store::DBIx::Class とかを store に指定すると認証が通らなくなる。
そこで、auto_create を指定するらしいんだけど、ただ指定しただけだと auto_create なんてメソッド無いっていわれるので、テーブルクラスにメソッド生やしておく
package MyApp::Schema::Member;
use strict;
use warnings;
__PACKAGE__->resultset_class('MyApp::Schema::ResultSet::Member');
{
package MyApp::Schema::ResultSet::Member;
use Carp::Clan qw/^DBIx::Class/;
use base qw(DBIx::Class::ResultSet);
sub auto_create {
my ( $class, $hashref, $c ) = @_;
my $member = $class->create({
livedoor_id => $hashref->{livedoor_id} || undef,
});
return $member;
}
}
1;
んで、こんな感じ。
'Plugin::Authentication':
default_realm: members
realms:
members:
credential:
class: Livedoor
app_key: ************************
seacret: **********
get_livedoor_id : 1
store:
class: DBIx::Class
user_class: DB::Member
id_field: livedoor_id
auto_create_user: 1
こうすると my $user = $realm->find_user( $userinfo, $c ); なコードのところで、auto_create してくれる。単純に create メソッド使ってくれるとも少しうれしいんだけども。






