Permalink
Browse files

Modified gem in preperation for new release

  • Loading branch information...
1 parent 2f9300c commit 8ca83c66fd7737a2ef556ebe652dbd15713ba226 @dwilkie committed Jan 23, 2011
@@ -1,24 +0,0 @@
-class Devise::PaypalAuthableController < ApplicationController
- prepend_before_filter :require_no_authentication, :only => :new
- include Devise::Controllers::InternalHelpers
- include DevisePaypal::Controllers::InternalHelpers
- include Paypal::Authentication
-
- # GET /resource/paypal_authorize_without_permissions
- def new
- callback_url = paypal_authable_callback_uri
- redirect_to authenticate_with_paypal_url(callback_url)
- end
-
- # GET /resource/paypal_authable/callback
- def callback_action
- paypal_user_details = get_auth_details(params[:token]) if params[:token]
- handle_callback_action(paypal_user_details, params)
- end
-
- private
- def paypal_authable_callback_uri(*args) #:nodoc:
- paypal_authable_callback_url(resource_name, *args)
- end
-end
-
@@ -0,0 +1,33 @@
+class Devise::PaypalAuthenticationsController < ApplicationController
+ include Devise::Controllers::InternalHelpers
+ include DevisePaypal::Controllers::InternalHelpers
+
+ # GET /resource/paypal_authentications/new
+ def new
+ end
+
+ # POST /resource/paypal_authentications
+ def create
+ create_and_redirect_to_resource params
+ end
+
+ # GET /resource/paypal_authentications/:id
+ def show
+
+ end
+
+ private
+ def create_and_redirect_to_resource(params)
+ paypal_authentication = Devise::PaypalAuthentication.create(
+ :params => params
+ )
+ paypal_authentication.callback_url = paypal_authentication_url(
+ resource_name, paypal_authentication
+ )
+ paypal_authentication.get_authentication_token
+ redirect_to paypal_authentication_path(
+ resource_name, paypal_authentication
+ )
+ end
+end
+
@@ -1,25 +0,0 @@
-class Devise::PaypalPermissionsAuthableController < ApplicationController
- prepend_before_filter :require_no_authentication, :only => :new
- include Devise::Controllers::InternalHelpers
- include DevisePaypal::Controllers::InternalHelpers
- include Paypal::Permissions
-
- # GET /resource/paypal_authorize_with_permissions
- def new
- @permissions ||= {}
- callback_url = paypal_permissions_authable_callback_uri
- redirect_to set_paypal_permissions_url(callback_url, @permissions)
- end
-
- # GET /resource/paypal_permissions_authable/callback
- def callback_action
- paypal_user_details = get_paypal_permissions(params[:token]) if params[:token]
- handle_callback_action(paypal_user_details, params)
- end
-
- private
- def paypal_permissions_authable_callback_uri(*args) #:nodoc:
- paypal_permissions_authable_callback_url(resource_name, *args)
- end
-end
-
@@ -0,0 +1,22 @@
+class Devise::PaypalAuthentication < ActiveRecord::Base
+ class GetPaypalAuthenticationTokenJob < Struct.new(:id, :callback_url)
+ include Paypal::Authentication
+ def perform
+ authenticate_with_paypal_url(callback_url)
+ end
+ end
+
+ attr_accessor :callback_url
+
+ serialize :params
+
+ validates :token,
+ :uniqueness => true
+
+ def get_authentication_token
+ Delayed::Job.enqueue(
+ GetPaypalAuthenticationTokenJob.new(id, callback_url), :priority => 5
+ )
+ end
+end
+
@@ -0,0 +1,2 @@
+<%= t("devise.paypal_authable.paypal_redirect") %> <%= link_to(t("devise.paypal_authable.paypal_redirect_link"), paypal_authentication_path(resource_name, @paypal_authentication)) %>
+
View
@@ -1,9 +1,8 @@
en:
devise:
paypal_authable:
- success: "Successfully authorized from Paypal account."
- failure: "Unable to authorize you from Paypal account."
- paypal_permissions_authable:
+ paypal_redirect: "Please wait while we"
+ paypal_redirect_link: "redirect you to Paypal..."
success: "Successfully authorized from Paypal account."
failure: "Unable to authorize you from Paypal account."
View
@@ -1,18 +1,14 @@
require "devise"
require "paypal"
-Devise.add_module :paypal_authable,
- :controller => :paypal_authable,
- :model => 'devise_paypal/models/paypal_authable',
- :route => { :paypal_authable => [nil, :new] }
+routes = [:new, nil]
-Devise.add_module :paypal_permissions_authable,
- :controller => :paypal_permissions_authable,
- :model => 'devise_paypal/models/paypal_permissions_authable',
- :route => { :paypal_permissions_authable => [nil, :new] }
+Devise.add_module :paypal_authable,
+ :controller => "paypal_authentications",
+ :route => { :paypal_authentication => routes }
require 'devise_paypal/rails/routes'
require 'devise_paypal/rails'
-require 'devise_paypal/controllers/url_helpers'
+require 'devise_paypal/models/paypal_authable'
require 'devise_paypal/controllers/internal_helpers'
@@ -1,16 +0,0 @@
-module DevisePaypal
- module Controllers
- module UrlHelpers
- def paypal_authable_callback_url(resource_or_scope, *args)
- scope = Devise::Mapping.find_scope!(resource_or_scope)
- send("#{scope}_paypal_authable_callback_url", *args)
- end
-
- def paypal_permissions_authable_callback_url(resource_or_scope, *args)
- scope = Devise::Mapping.find_scope!(resource_or_scope)
- send("#{scope}_paypal_permissions_authable_callback_url", *args)
- end
- end
- end
-end
-
@@ -1,21 +1,6 @@
module Devise
module Models
- # Registerable is responsible for everything related to registering a new
- # resource (ie user sign up).
module PaypalAuthable
- extend ActiveSupport::Concern
-
- module ClassMethods
- # A convenience method that receives both parameters and session to
- # initialize an user. This can be used by OAuth, for example, to send
- # in the user token and be stored on initialization.
- #
- # By default discards all information sent by the session by calling
- # new with params.
- def new_with_session(params, session)
- new(params)
- end
- end
end
end
end
@@ -1,22 +0,0 @@
-module Devise
- module Models
- # Registerable is responsible for everything related to registering a new
- # resource (ie user sign up).
- module PaypalPermissionsAuthable
- extend ActiveSupport::Concern
-
- module ClassMethods
- # A convenience method that receives both parameters and session to
- # initialize an user. This can be used by OAuth, for example, to send
- # in the user token and be stored on initialization.
- #
- # By default discards all information sent by the session by calling
- # new with params.
- def new_with_session(params, session)
- new(params)
- end
- end
- end
- end
-end
-
View
@@ -1,21 +1,5 @@
module DevisePaypal
class Engine < ::Rails::Engine
- ActiveSupport.on_load(:action_controller) {
- include DevisePaypal::Controllers::UrlHelpers
- }
-
- def eager_load!
- mappings = Devise.mappings.values.map(&:modules).flatten.uniq
- controllers = Devise::CONTROLLERS.values_at(*mappings)
- path = paths.app.controllers.to_a.first
- matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
-
- Dir.glob("#{path}/devise/{#{controllers.join(',')}}_controller.rb").sort.each do |file|
- require_dependency file.sub(matcher, '\1')
- end
-
- super
- end
end
end
@@ -1,38 +1,12 @@
module ActionDispatch::Routing
class Mapper
protected
- def devise_paypal_authable(mapping, controllers) #:nodoc:
- path_names = {
- :new => mapping.path_names[:paypal_authorize_without_permissions],
- }
+ def devise_paypal_authentication(mapping, controllers) #:nodoc:
- resource :paypal_authable,
- :only => :new,
- :path => mapping.path_names[:registration],
- :path_names => path_names,
- :controller => controllers[:paypal_authable]
-
- get "/paypal_authable/callback",
- :to => controllers[:paypal_authable],
- :action => :callback_action,
- :as => :paypal_authable_callback
- end
-
- def devise_paypal_permissions_authable(mapping, controllers) #:nodoc:
- path_names = {
- :new => mapping.path_names[:paypal_authorize_with_permissions],
- }
-
- resource :paypal_permissions_authable,
- :only => :new,
- :path => mapping.path_names[:registration],
- :path_names => path_names,
- :controller => controllers[:paypal_permissions_authable]
-
- get "/paypal_permissions_authable/callback",
- :to => controllers[:paypal_permissions_authable],
- :action => :callback_action,
- :as => :paypal_permissions_authable_callback
+ resources :paypal_authentications,
+ :only => [:new, :create, :show],
+ :controller => controllers[:paypal_authable],
+ :module => controllers[:paypal_authable] ? nil : 'devise'
end
end
end
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe PaypalAuthentication do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
13 todo
@@ -0,0 +1,13 @@
+Finish new version of this gem
+Use ideas from Delayed::Job
+i.e. DevisePaypal::Authentication
+Add validation to this model i.e. uniqueness of token
+
+In the DevisePaypal::AuthenticationsController
+ create action
+ create a new Authentication
+ after create it will send it to Paypal to get a token
+ show action
+ find the Authentication by token or id
+ Logic goes in here
+

0 comments on commit 8ca83c6

Please sign in to comment.