paypal_permissions 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/autospec +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/ldiff +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/rdoc +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/bin/tt +16 -0
- data/config/locales/en.yml +13 -0
- data/lib/active_merchant.rb +17 -0
- data/lib/active_merchant/billing.rb +1 -0
- data/lib/active_merchant/billing/gateways.rb +17 -0
- data/lib/active_merchant/billing/gateways/paypal_permissions.rb +246 -0
- data/lib/generators/active_record/paypal_permissions_generator.rb +50 -0
- data/lib/generators/active_record/templates/migration.rb +15 -0
- data/lib/generators/active_record/templates/migration_existing.rb +23 -0
- data/lib/generators/paypal_permissions/install_generator.rb +69 -0
- data/lib/generators/paypal_permissions/orm_helpers.rb +27 -0
- data/lib/generators/paypal_permissions/paypal_permissions_generator.rb +18 -0
- data/lib/generators/templates/README +12 -0
- data/lib/generators/templates/README.rdoc +353 -0
- data/lib/generators/templates/paypal_permissions.rb +2 -0
- data/lib/paypal_permissions.rb +6 -0
- data/lib/paypal_permissions/version.rb +3 -0
- data/paypal_permissions.gemspec +31 -0
- data/spec/gateway_spec.rb +147 -0
- data/spec/generators/paypal_permissions/install_generator_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -0
- metadata +205 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/paypal_permissions/orm_helpers'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class PaypalPermissionsGenerator < ActiveRecord::Generators::Base
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
8
|
+
|
9
|
+
include PaypalPermissions::Generators::OrmHelpers
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
def copy_paypal_permissions_migration
|
13
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
14
|
+
migration_template "migration_existing.rb", "db/migrate/add_paypal_permissions_to_#{table_name}"
|
15
|
+
else
|
16
|
+
migration_template "migration.rb", "db/migrate/paypal_permissions_create_#{table_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_model
|
21
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
def inject_paypal_permissions_content
|
25
|
+
inject_into_class(model_path, class_name, model_contents + <<ACCESSIBLE_FIELDS) if model_exists?
|
26
|
+
attr_accessible :ack, :correlation_id, :request_token, :verifier, :envelope_timestamp, :errors, :raw_response
|
27
|
+
ACCESSIBLE_FIELDS
|
28
|
+
end
|
29
|
+
|
30
|
+
def migration_data
|
31
|
+
<<MIGRATION_FIELDS
|
32
|
+
# Paypal Permissions response fields
|
33
|
+
t.string :ack
|
34
|
+
t.string :correlation_id
|
35
|
+
t.string :request_token
|
36
|
+
t.string :verifier
|
37
|
+
t.datetime :envelope_timestamp
|
38
|
+
t.text :errors
|
39
|
+
t.text :raw_response
|
40
|
+
MIGRATION_FIELDS
|
41
|
+
end
|
42
|
+
|
43
|
+
def indexes
|
44
|
+
<<INDEXES
|
45
|
+
add_index :#{table_name}, :request_token
|
46
|
+
INDEXES
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class PaypalPermissionsCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
<%= migration_data -%>
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
<%= indexes -%>
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class AddPaypalPermissionsTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
<%= migration_data -%>
|
9
|
+
|
10
|
+
# Uncomment below if timestamps were not included in your original model.
|
11
|
+
# t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
<%= indexes -%>
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
# We won't make assumptions about how to roll back a migration to a previously existing model.
|
19
|
+
# If you'd like to be able to roll back, remove the ActiveRecord::IrreversibleMigration line
|
20
|
+
# and make your edits below.
|
21
|
+
raise ActiveRecord::IrreversibleMigration
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module PaypalPermissions
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates a PaypalPermissions initializer and copies locale files to your application."
|
7
|
+
class_option :orm
|
8
|
+
|
9
|
+
def update_configuration
|
10
|
+
dev_test_config = <<-DEV_TEST_CONFIG
|
11
|
+
#{Rails.application.class.name.split('::').first}::Application.configure do
|
12
|
+
config.after_initialize do
|
13
|
+
permissions_options = {
|
14
|
+
:login => "TODO: your PayPal sandbox caller login",
|
15
|
+
:password => "TODO: your PayPal sandbox caller login",
|
16
|
+
:signature => "TODO: your PayPal sandbox caller login",
|
17
|
+
:app_id => "APP-80W284485P519543T", # This is the app_id for all PayPal Permissions Service sandbox test apps
|
18
|
+
}
|
19
|
+
::PAYPAL_PERMISSIONS_GATEWAY = ActiveMerchant::Billing::PaypalPermissionsGateway.new(permissions_options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
DEV_TEST_CONFIG
|
23
|
+
|
24
|
+
prod_config = <<-PROD_CONFIG
|
25
|
+
#{Rails.application.class.name.split('::').first}::Application.configure do
|
26
|
+
config.after_initialize do
|
27
|
+
permissions_options = {
|
28
|
+
:login => "TODO: your PayPal live caller login",
|
29
|
+
:password => "TODO: your PayPal live caller login",
|
30
|
+
:signature => "TODO: your PayPal live caller login",
|
31
|
+
:app_id => "TODO: your PayPal live app id",
|
32
|
+
}
|
33
|
+
::PAYPAL_PERMISSIONS_GATEWAY = ActiveMerchant::Billing::PaypalPermissionsGateway.new(permissions_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
PROD_CONFIG
|
37
|
+
|
38
|
+
# Don't use... "application(nil, :env => "development") do" here.
|
39
|
+
# Somewhere along the line, in the case where the :env parameter is supplied,
|
40
|
+
# railties went from using append_file to using inject_into_file after an env_file_sentinel,
|
41
|
+
# which changes the semantics drastically.
|
42
|
+
#
|
43
|
+
append_file("config/environments/development.rb") do
|
44
|
+
"\n#{dev_test_config}"
|
45
|
+
end
|
46
|
+
|
47
|
+
append_file("config/environments/test.rb") do
|
48
|
+
"\n#{dev_test_config}"
|
49
|
+
end
|
50
|
+
|
51
|
+
append_file("config/environments/production.rb") do
|
52
|
+
"\n#{prod_config}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def copy_initializer
|
57
|
+
template "paypal_permissions.rb", "config/initializers/paypal_permissions.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
def copy_locale
|
61
|
+
copy_file "../../../config/locales/en.yml", "config/locales/paypal_permissions.en.yml"
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_readme
|
65
|
+
readme "README" if behavior == :invoke
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PaypalPermissions
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
def model_contents
|
5
|
+
<<-CONTENT
|
6
|
+
validates :ack, :presence => true
|
7
|
+
CONTENT
|
8
|
+
end
|
9
|
+
|
10
|
+
def model_exists?
|
11
|
+
File.exists?(File.join(destination_root, model_path))
|
12
|
+
end
|
13
|
+
|
14
|
+
def migration_exists?(table_name)
|
15
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
16
|
+
end
|
17
|
+
|
18
|
+
def migration_path
|
19
|
+
@migration_path ||= File.join("db", "migrate")
|
20
|
+
end
|
21
|
+
|
22
|
+
def model_path
|
23
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PaypalPermissions
|
2
|
+
module Generators
|
3
|
+
class PaypalPermissionsGenerator < Rails::Generators::NamedBase
|
4
|
+
namespace "paypal_permissions"
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
|
7
|
+
desc "Generates a paypal_permissions resource with NAME along with a database migration."
|
8
|
+
|
9
|
+
hook_for :orm
|
10
|
+
|
11
|
+
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
|
12
|
+
|
13
|
+
def insert_paypal_permissions_routes
|
14
|
+
route "resources :#{plural_name}" if options.routes?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
Now that you've installed PaypalPermissions, the first thing you'll need
|
3
|
+
to do is add your PayPal login, password, signature, and app_id to the
|
4
|
+
config/environments/*.rb files.
|
5
|
+
|
6
|
+
Then, you can create a new model with routes, or a migration to modify
|
7
|
+
an existing model to support your application's interactions with the
|
8
|
+
PayPal Permissions API.
|
9
|
+
|
10
|
+
Try:
|
11
|
+
rails generate paypal_permissions <model> [field_name:field_type ...]
|
12
|
+
|
@@ -0,0 +1,353 @@
|
|
1
|
+
== Paypal Permissions
|
2
|
+
|
3
|
+
{<img src="https://secure.travis-ci.org/moshbit/devise.png" />}[http://travis-ci.org/moshbit/devise]
|
4
|
+
|
5
|
+
Paypal Permissions provides a gateway to the PayPal Permissions Service for Rails applications based on ActiveMerchant. It:
|
6
|
+
|
7
|
+
* leverages ActiveMerchant;
|
8
|
+
* does other good things.
|
9
|
+
|
10
|
+
It's comprised of stuff:
|
11
|
+
|
12
|
+
* Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
|
13
|
+
* Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
|
14
|
+
* Omniauthable: adds Omniauth (github.com/intridea/omniauth) support;
|
15
|
+
* Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
|
16
|
+
* Recoverable: resets the user password and sends reset instructions.
|
17
|
+
|
18
|
+
== Information
|
19
|
+
|
20
|
+
=== The Paypal Permissions wiki
|
21
|
+
|
22
|
+
The Paypal Permissions Wiki has lots of additional information, including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
|
23
|
+
|
24
|
+
https://wiki.github.com/moshbit/paypal_permissions
|
25
|
+
|
26
|
+
=== Bug reports
|
27
|
+
|
28
|
+
If you discover a problem with Paypal Permissions, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
|
29
|
+
|
30
|
+
https://github.com/moshbit/paypal_permissions/wiki/Bug-reports
|
31
|
+
|
32
|
+
If you found a security bug, do *NOT* use the GitHub issue tracker. Send email or a private GitHub message to the maintainers listed at the bottom of the README.
|
33
|
+
|
34
|
+
=== Mailing list
|
35
|
+
|
36
|
+
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
|
37
|
+
|
38
|
+
https://groups.google.com/group/moshbit-paypal_permissions
|
39
|
+
|
40
|
+
=== RDocs
|
41
|
+
|
42
|
+
You can view the Devise documentation in RDoc format here:
|
43
|
+
|
44
|
+
http://rubydoc.info/github/moshbit/paypal_permissions/master/frames
|
45
|
+
|
46
|
+
=== Example applications
|
47
|
+
|
48
|
+
There are a few example applications available on GitHub that demonstrate various features of Paypal Permissions. You can view them here:
|
49
|
+
|
50
|
+
https://github.com/moshbit/paypal_permissions/wiki/Example-Applications
|
51
|
+
|
52
|
+
=== Extensions
|
53
|
+
|
54
|
+
Our community has created a number of extensions that add functionality above and beyond what is included with Paypal Permissions. You can view a list of available extensions and add your own here:
|
55
|
+
|
56
|
+
https://github.com/moshbit/paypal_permissions/wiki/Extensions
|
57
|
+
|
58
|
+
=== Contributing
|
59
|
+
|
60
|
+
We hope that you will consider contributing to Paypal_Permissions. Please read this short overview for some information about how to get started:
|
61
|
+
|
62
|
+
https://github.com/moshbit/paypal_permissions/wiki/Contributing
|
63
|
+
|
64
|
+
You will usually want to write tests for your changes. To run the test suite, `cd` into Paypal_Permissions's top-level directory and run `bundle install` and `rake`. For the tests to pass, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
|
65
|
+
|
66
|
+
== Installation
|
67
|
+
|
68
|
+
You can use the latest Rails 3 gem with the latest Paypal_Permissions gem:
|
69
|
+
|
70
|
+
gem install paypal_permissions
|
71
|
+
|
72
|
+
After you install Paypal_Permissions and add it to your Gemfile, you need to run the generator:
|
73
|
+
|
74
|
+
rails generate paypal_permissions:install
|
75
|
+
|
76
|
+
The generator will install an initializer which describes ALL Paypal_Permissions's configuration options and you MUST take a look at it. When you are done, you are ready to add Paypal_Permissions to any of your models using the generator:
|
77
|
+
|
78
|
+
rails generate paypal_permissions MODEL
|
79
|
+
|
80
|
+
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Paypal_Permissions modules. Next, you'll usually run db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file, continue reading this file to understand exactly what the generator produces and how to use it. Finally, if your server was already running, then restart it as Rails doesn't automatically load methods from a new gem.
|
81
|
+
|
82
|
+
Support for Rails 2.3.x can be found by installing Paypal_Permissions 1.0.x from the v1.0 branch.
|
83
|
+
|
84
|
+
== Starting with Rails?
|
85
|
+
|
86
|
+
If you are building your first Rails application, we recommend you to *not* use Paypal_Permissions. Paypal_Permissions requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources:
|
87
|
+
|
88
|
+
* Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
|
89
|
+
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
|
90
|
+
|
91
|
+
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Paypal_Permissions will be very pleasant to work with. :)
|
92
|
+
|
93
|
+
== Getting started
|
94
|
+
|
95
|
+
This is a walkthrough with all steps you need to setup a paypal_permissions resource, including model, migration, route files, and optional configuration.
|
96
|
+
|
97
|
+
Paypal_Permissions must be set up within the model (or models) you want to use. Paypal_Permissions routes must be created inside your config/routes.rb file.
|
98
|
+
|
99
|
+
We're assuming here you want a User model with some Paypal_Permissions modules, as outlined below:
|
100
|
+
|
101
|
+
class User < ActiveRecord::Base
|
102
|
+
paypal_permissions :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
|
103
|
+
end
|
104
|
+
|
105
|
+
After you choose which modules to use, you need to set up your migrations. Luckily, Paypal_Permissions has some helpers to save you from this boring work:
|
106
|
+
|
107
|
+
create_table :users do |t|
|
108
|
+
t.database_authenticatable
|
109
|
+
t.confirmable
|
110
|
+
t.recoverable
|
111
|
+
t.rememberable
|
112
|
+
t.trackable
|
113
|
+
t.timestamps
|
114
|
+
end
|
115
|
+
|
116
|
+
Paypal_Permissions doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
|
117
|
+
|
118
|
+
Configure your routes after setting up your model. Open your config/routes.rb file and add:
|
119
|
+
|
120
|
+
paypal_permissions_for :users
|
121
|
+
|
122
|
+
This will use your User model to create a set of needed routes (you can see them by running `rake routes`). If you invoked the paypal_permissions generator, you noticed that this is exactly what the generator produces for us: model, routes and migrations.
|
123
|
+
|
124
|
+
Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
|
125
|
+
|
126
|
+
=== Controller filters and helpers
|
127
|
+
|
128
|
+
Paypal_Permissions will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
|
129
|
+
|
130
|
+
before_filter :authenticate_user!
|
131
|
+
|
132
|
+
To verify if a user is signed in, use the following helper:
|
133
|
+
|
134
|
+
user_signed_in?
|
135
|
+
|
136
|
+
For the current signed-in user, this helper is available:
|
137
|
+
|
138
|
+
current_user
|
139
|
+
|
140
|
+
You can access the session for this scope:
|
141
|
+
|
142
|
+
user_session
|
143
|
+
|
144
|
+
After signing in a user, confirming the account or updating the password, Paypal_Permissions will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
|
145
|
+
|
146
|
+
root :to => "home#index"
|
147
|
+
|
148
|
+
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
|
149
|
+
|
150
|
+
Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
|
151
|
+
|
152
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
153
|
+
|
154
|
+
Notice that if your paypal_permissions model is not called "user" but "member", then the helpers you should use are:
|
155
|
+
|
156
|
+
before_filter :authenticate_member!
|
157
|
+
|
158
|
+
member_signed_in?
|
159
|
+
|
160
|
+
current_member
|
161
|
+
|
162
|
+
member_session
|
163
|
+
|
164
|
+
=== Configuring Models
|
165
|
+
|
166
|
+
The paypal_permissions method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
|
167
|
+
|
168
|
+
paypal_permissions :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
|
169
|
+
|
170
|
+
Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "paypal_permissions:install" generator described above.
|
171
|
+
|
172
|
+
=== Configuring multiple models
|
173
|
+
|
174
|
+
Paypal_Permissions allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication, trackable, lockable and timeoutable features and no confirmation or password-recovery features. Just follow these steps:
|
175
|
+
|
176
|
+
# Create a migration with the required fields
|
177
|
+
create_table :admins do |t|
|
178
|
+
t.database_authenticatable
|
179
|
+
t.lockable
|
180
|
+
t.trackable
|
181
|
+
t.timestamps
|
182
|
+
end
|
183
|
+
|
184
|
+
# Inside your Admin model
|
185
|
+
paypal_permissions :database_authenticatable, :trackable, :timeoutable, :lockable
|
186
|
+
|
187
|
+
# Inside your routes
|
188
|
+
paypal_permissions_for :admins
|
189
|
+
|
190
|
+
# Inside your protected controller
|
191
|
+
before_filter :authenticate_admin!
|
192
|
+
|
193
|
+
# Inside your controllers and views
|
194
|
+
admin_signed_in?
|
195
|
+
current_admin
|
196
|
+
admin_session
|
197
|
+
|
198
|
+
=== Configuring views
|
199
|
+
|
200
|
+
We built Paypal_Permissions to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
|
201
|
+
|
202
|
+
Since Paypal_Permissions is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
|
203
|
+
|
204
|
+
rails generate paypal_permissions:views
|
205
|
+
|
206
|
+
If you have more than one role in your application (such as "User" and "Admin"), you will notice that Paypal_Permissions uses the same views for all roles. Fortunately, Paypal_Permissions offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/paypal_permissions.rb".
|
207
|
+
|
208
|
+
After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Paypal_Permissions will use the default view at "paypal_permissions/sessions/new". You can also use the generator to generate scoped views:
|
209
|
+
|
210
|
+
rails generate paypal_permissions:views users
|
211
|
+
|
212
|
+
=== Configuring controllers
|
213
|
+
|
214
|
+
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
215
|
+
|
216
|
+
1) Create your custom controller, for example a Admins::SessionsController:
|
217
|
+
|
218
|
+
class Admins::SessionsController < Paypal_Permissions::SessionsController
|
219
|
+
end
|
220
|
+
|
221
|
+
2) Tell the router to use this controller:
|
222
|
+
|
223
|
+
paypal_permissions_for :admins, :controllers => { :sessions => "admins/sessions" }
|
224
|
+
|
225
|
+
3) And since we changed the controller, it won't use the "paypal_permissions/sessions" views, so remember to copy "paypal_permissions/sessions" to "admin/sessions".
|
226
|
+
|
227
|
+
Remember that Paypal_Permissions uses flash messages to let users know if sign in was successful or failed. Paypal_Permissions expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
|
228
|
+
|
229
|
+
=== Configuring routes
|
230
|
+
|
231
|
+
Paypal_Permissions also ships with default routes. If you need to customize them, you should probably be able to do it through the paypal_permissions_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
|
232
|
+
|
233
|
+
paypal_permissions_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
|
234
|
+
|
235
|
+
Be sure to check paypal_permissions_for documentation for details.
|
236
|
+
|
237
|
+
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is to create your routes normally and wrap them in a +paypal_permissions_scope+ block in the router:
|
238
|
+
|
239
|
+
paypal_permissions_scope :user do
|
240
|
+
get "sign_in", :to => "paypal_permissions/sessions#new"
|
241
|
+
end
|
242
|
+
|
243
|
+
This way you tell paypal_permissions to use the scope :user when "/sign_in" is accessed. Notice +paypal_permissions_scope+ is also aliased as +as+ and you can also give a block to +paypal_permissions_for+, resulting in the same behavior:
|
244
|
+
|
245
|
+
paypal_permissions_for :users do
|
246
|
+
get "sign_in", :to => "paypal_permissions/sessions#new"
|
247
|
+
end
|
248
|
+
|
249
|
+
Feel free to choose the one you prefer!
|
250
|
+
|
251
|
+
=== I18n
|
252
|
+
|
253
|
+
Paypal_Permissions uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
254
|
+
|
255
|
+
en:
|
256
|
+
paypal_permissions:
|
257
|
+
sessions:
|
258
|
+
signed_in: 'Signed in successfully.'
|
259
|
+
|
260
|
+
You can also create distinct messages based on the resource you've configured using the singular name given in routes:
|
261
|
+
|
262
|
+
en:
|
263
|
+
paypal_permissions:
|
264
|
+
sessions:
|
265
|
+
user:
|
266
|
+
signed_in: 'Welcome user, you are signed in.'
|
267
|
+
admin:
|
268
|
+
signed_in: 'Hello admin!'
|
269
|
+
|
270
|
+
The Paypal_Permissions mailer uses a similar pattern to create subject messages:
|
271
|
+
|
272
|
+
en:
|
273
|
+
paypal_permissions:
|
274
|
+
mailer:
|
275
|
+
confirmation_instructions:
|
276
|
+
subject: 'Hello everybody!'
|
277
|
+
user_subject: 'Hello User! Please confirm your email'
|
278
|
+
reset_password_instructions:
|
279
|
+
subject: 'Reset instructions'
|
280
|
+
|
281
|
+
Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
|
282
|
+
|
283
|
+
https://github.com/moshbit/paypal_permissions/wiki/I18n
|
284
|
+
|
285
|
+
=== Test helpers
|
286
|
+
|
287
|
+
Paypal_Permissions includes some tests helpers for functional specs. To use them, you just need to include Paypal_Permissions::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
|
288
|
+
|
289
|
+
sign_in :user, @user # sign_in(scope, resource)
|
290
|
+
sign_in @user # sign_in(resource)
|
291
|
+
|
292
|
+
sign_out :user # sign_out(scope)
|
293
|
+
sign_out @user # sign_out(resource)
|
294
|
+
|
295
|
+
You can include the Paypal_Permissions Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
|
296
|
+
|
297
|
+
class ActionController::TestCase
|
298
|
+
include Paypal_Permissions::TestHelpers
|
299
|
+
end
|
300
|
+
|
301
|
+
If you're using RSpec and want the helpers automatically included within all +describe+ blocks, add a file called spec/support/paypal_permissions.rb with the following contents:
|
302
|
+
|
303
|
+
RSpec.configure do |config|
|
304
|
+
config.include Paypal_Permissions::TestHelpers, :type => :controller
|
305
|
+
end
|
306
|
+
|
307
|
+
Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (https://wiki.github.com/moshbit/paypal_permissions).
|
308
|
+
|
309
|
+
=== Omniauth
|
310
|
+
|
311
|
+
Paypal_Permissions comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
|
312
|
+
|
313
|
+
* https://github.com/moshbit/paypal_permissions/wiki/OmniAuth:-Overview
|
314
|
+
|
315
|
+
=== Other ORMs
|
316
|
+
|
317
|
+
Paypal_Permissions supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
|
318
|
+
|
319
|
+
=== Migrating from other solutions
|
320
|
+
|
321
|
+
Paypal_Permissions implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, you need set the desired encryptor in the encryptor initializer config option and add :encryptable to your model. You might also need to rename your encrypted password and salt columns to match Paypal_Permissions's fields (encrypted_password and password_salt).
|
322
|
+
|
323
|
+
== Troubleshooting
|
324
|
+
|
325
|
+
=== Heroku
|
326
|
+
|
327
|
+
Using paypal_permissions on Heroku with Ruby on Rails 3.1 requires setting:
|
328
|
+
|
329
|
+
config.assets.initialize_on_precompile = false
|
330
|
+
|
331
|
+
Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
|
332
|
+
|
333
|
+
== Additional information
|
334
|
+
|
335
|
+
=== Warden
|
336
|
+
|
337
|
+
Paypal_Permissions is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
|
338
|
+
|
339
|
+
https://github.com/hassox/warden
|
340
|
+
|
341
|
+
=== Contributors
|
342
|
+
|
343
|
+
We have a long list of valued contributors. Check them all at:
|
344
|
+
|
345
|
+
https://github.com/moshbit/paypal_permissions/contributors
|
346
|
+
|
347
|
+
=== Maintainers
|
348
|
+
|
349
|
+
* Mark Paine (https://github.com/moshbit)
|
350
|
+
|
351
|
+
== License
|
352
|
+
|
353
|
+
MIT License. Copyright 2012 Moshbit. http://blog.moshbit.com
|