[Bps-public-commit] jifty-plugin-authentication-twitter branch, master, updated. 78074cb64d973f89420b56a4d074952a9c4dd457
Shawn Moore
sartak at bestpractical.com
Thu Jun 10 16:35:34 EDT 2010
The branch, master has been updated
via 78074cb64d973f89420b56a4d074952a9c4dd457 (commit)
from 0e21bcaa162b34310d9fd5d2871de4f5a97271da (commit)
Summary of changes:
.../Plugin/Authentication/Twitter/Dispatcher.pm | 32 +++++++++++++++++--
1 files changed, 28 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 78074cb64d973f89420b56a4d074952a9c4dd457
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Thu Jun 10 16:29:49 2010 -0400
Load or create a User and TwitterUser based on Twitter's response
diff --git a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
index a61ee4a..ef94a73 100644
--- a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
+++ b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
@@ -98,10 +98,34 @@ on '/twitter/callback' => run {
my $response = Net::OAuth::AccessTokenResponse->from_post_body($res->content);
- # access_token => $response->token,
- # access_secret => $response->token_secret,
- # user_id => $response->extra_params->{user_id},
- # screen_name => $response->extra_params->{screen_name},
+ my $access_token = $response->token;
+ my $access_secret = $response->token_secret;
+ my $twitter_id = $response->extra_params->{user_id};
+ my $screen_name = $response->extra_params->{screen_name};
+
+ my $twitter_account = Jifty::Plugin::Authentication::Twitter::Model::TwitterAccount->new(current_user => Jifty::CurrentUser->superuser);
+ $twitter_account->load(
+ twitter_id => $twitter_id,
+ );
+ my $user = Jifty->app_class('Model', 'User')->new;
+
+ if ($twitter_account->id) {
+ $user->load($twitter_account->user_id);
+ $user->screen_name($screen_name);
+ }
+ else {
+ $user->create(
+ name => $screen_name,
+ );
+ $twitter_account->create(
+ user_id => $user->id,
+ twitter_id => $twitter_id,
+ screen_name => $screen_name,
+ access_token => $access_token,
+ access_secret => $access_secret,
+ );
+ }
+
};
1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list