[Bps-public-commit] jifty-plugin-authentication-twitter branch, master, updated. daf24384fb832d547afe9151c1dea477abd61871
Shawn Moore
sartak at bestpractical.com
Fri Jun 11 16:12:22 EDT 2010
The branch, master has been updated
via daf24384fb832d547afe9151c1dea477abd61871 (commit)
from f67e29623021e466d490bba1362154cd4cab8cd8 (commit)
Summary of changes:
.../Twitter/Action/CreateTwitterUser.pm | 79 ++++++++++++++++++++
.../Plugin/Authentication/Twitter/Dispatcher.pm | 25 +++----
2 files changed, 89 insertions(+), 15 deletions(-)
create mode 100644 lib/Jifty/Plugin/Authentication/Twitter/Action/CreateTwitterUser.pm
- Log -----------------------------------------------------------------
commit daf24384fb832d547afe9151c1dea477abd61871
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Jun 11 16:13:02 2010 -0400
First cut of the CreateTwitterUser action
diff --git a/lib/Jifty/Plugin/Authentication/Twitter/Action/CreateTwitterUser.pm b/lib/Jifty/Plugin/Authentication/Twitter/Action/CreateTwitterUser.pm
new file mode 100644
index 0000000..56e9d89
--- /dev/null
+++ b/lib/Jifty/Plugin/Authentication/Twitter/Action/CreateTwitterUser.pm
@@ -0,0 +1,79 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+Jifty::Plugin::Authentication::Twitter::CreateTwitterUser
+
+=cut
+
+package Jifty::Plugin::Authentication::Twitter::Action::CreateTwitterUser;
+use base qw/Jifty::Action/;
+
+use Scalar::Defer 'defer';
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+ param name =>
+ is mandatory,
+ default is defer { Jifty->web->session->get('screen_name') };
+};
+
+=head2 take_action
+
+Creates a user account based on Twitter credentials and the provided name.
+
+=cut
+
+sub take_action {
+ my $self = shift;
+ my $twitter_id = Jifty->web->session->get('twitter_id');
+ if (!$twitter_id) {
+ # Should never get here unless someone's trying weird things
+ $self->result->error("Invalid verification result");
+ return;
+ }
+
+ my $twitter_account = Jifty::Plugin::Authentication::Twitter::Model::TwitterAccount->new(current_user => Jifty::CurrentUser->superuser);
+ my $user = Jifty->app_class('Model', 'User')->new(current_user => Jifty::CurrentUser->superuser);
+
+ my ($ok, $msg) = $user->create(
+ name => $self->argument_value('name'),
+ );
+ if (!$ok) {
+ $self->result->error("Unable to create user: $msg");
+ }
+
+ ($ok, $msg) = $twitter_account->create(
+ user_id => $user->id,
+ twitter_id => $twitter_id,
+ screen_name => Jifty->web->session->get('screen_name'),
+ access_token => Jifty->web->session->get('access_token'),
+ access_secret => Jifty->web->session->get('access_secret'),
+ );
+
+ if (!$ok) {
+ $user->delete;
+ $self->result->error("Unable to create user: $msg");
+ }
+
+ my $current_user = Jifty->app_class('CurrentUser')->new(user_object => $user);
+
+ # Actually do the signin thing.
+ Jifty->web->current_user($current_user);
+ Jifty->web->session->expires( undef );
+ Jifty->web->session->set_cookie;
+
+ $self->report_success if not $self->result->failure;
+
+ Jifty->web->session->remove($_)
+ for qw/twitter_id screen_name access_token access_secret/;
+}
+
+sub report_success {
+ my $self = shift;
+ $self->result->message( _("Welcome, ") . Jifty->web->current_user->user_object->name . "." );
+}
+
+1;
+
diff --git a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
index 589f067..0d459fb 100644
--- a/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
+++ b/lib/Jifty/Plugin/Authentication/Twitter/Dispatcher.pm
@@ -128,27 +128,22 @@ on '/twitter/callback' => run {
if ($twitter_account->id) {
$user->load($twitter_account->user_id);
$twitter_account->set_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,
- );
- }
-
- if ($user->id) {
my $current_user = Jifty->app_class('CurrentUser')->new(id => $user->id);
Jifty->web->current_user($current_user);
Jifty->web->session->expires( undef );
Jifty->web->session->set_cookie;
redirect '/';
}
+ else {
+ Jifty->web->session->set(twitter_id => $twitter_id);
+ Jifty->web->session->set(screen_name => $screen_name);
+ Jifty->web->session->set(access_token => $access_token);
+ Jifty->web->session->set(access_secret => $access_secret);
+ redirect '/twitter/create';
+ }
+};
+
+on '/twitter/create' => run {
};
1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list