ramon-devise 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/CHANGELOG.rdoc +109 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +243 -0
  4. data/Rakefile +45 -0
  5. data/TODO +8 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/sessions_controller.rb +33 -0
  9. data/app/models/devise_mailer.rb +53 -0
  10. data/app/views/confirmations/new.html.erb +16 -0
  11. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  12. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  13. data/app/views/passwords/edit.html.erb +20 -0
  14. data/app/views/passwords/new.html.erb +16 -0
  15. data/app/views/sessions/new.html.erb +23 -0
  16. data/generators/devise/USAGE +5 -0
  17. data/generators/devise/devise_generator.rb +25 -0
  18. data/generators/devise/lib/route_devise.rb +32 -0
  19. data/generators/devise/templates/README +22 -0
  20. data/generators/devise/templates/migration.rb +20 -0
  21. data/generators/devise/templates/model.rb +5 -0
  22. data/generators/devise_install/USAGE +3 -0
  23. data/generators/devise_install/devise_install_generator.rb +9 -0
  24. data/generators/devise_install/templates/devise.rb +40 -0
  25. data/generators/devise_views/USAGE +3 -0
  26. data/generators/devise_views/devise_views_generator.rb +24 -0
  27. data/init.rb +2 -0
  28. data/lib/devise.rb +79 -0
  29. data/lib/devise/controllers/filters.rb +111 -0
  30. data/lib/devise/controllers/helpers.rb +130 -0
  31. data/lib/devise/controllers/url_helpers.rb +49 -0
  32. data/lib/devise/failure.rb +38 -0
  33. data/lib/devise/hooks/confirmable.rb +11 -0
  34. data/lib/devise/hooks/rememberable.rb +27 -0
  35. data/lib/devise/locales/en.yml +18 -0
  36. data/lib/devise/mapping.rb +120 -0
  37. data/lib/devise/migrations.rb +51 -0
  38. data/lib/devise/models.rb +105 -0
  39. data/lib/devise/models/authenticatable.rb +97 -0
  40. data/lib/devise/models/confirmable.rb +156 -0
  41. data/lib/devise/models/recoverable.rb +88 -0
  42. data/lib/devise/models/rememberable.rb +95 -0
  43. data/lib/devise/models/validatable.rb +36 -0
  44. data/lib/devise/rails.rb +17 -0
  45. data/lib/devise/rails/routes.rb +109 -0
  46. data/lib/devise/rails/warden_compat.rb +26 -0
  47. data/lib/devise/strategies/authenticatable.rb +46 -0
  48. data/lib/devise/strategies/base.rb +24 -0
  49. data/lib/devise/strategies/rememberable.rb +35 -0
  50. data/lib/devise/version.rb +3 -0
  51. data/lib/devise/warden.rb +24 -0
  52. data/test/controllers/filters_test.rb +103 -0
  53. data/test/controllers/helpers_test.rb +55 -0
  54. data/test/controllers/url_helpers_test.rb +47 -0
  55. data/test/devise_test.rb +72 -0
  56. data/test/failure_test.rb +34 -0
  57. data/test/integration/authenticatable_test.rb +187 -0
  58. data/test/integration/confirmable_test.rb +89 -0
  59. data/test/integration/recoverable_test.rb +131 -0
  60. data/test/integration/rememberable_test.rb +65 -0
  61. data/test/mailers/confirmation_instructions_test.rb +59 -0
  62. data/test/mailers/reset_password_instructions_test.rb +62 -0
  63. data/test/mapping_test.rb +101 -0
  64. data/test/models/authenticatable_test.rb +118 -0
  65. data/test/models/confirmable_test.rb +237 -0
  66. data/test/models/recoverable_test.rb +141 -0
  67. data/test/models/rememberable_test.rb +130 -0
  68. data/test/models/validatable_test.rb +99 -0
  69. data/test/models_test.rb +111 -0
  70. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  71. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  72. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  73. data/test/rails_app/app/controllers/users_controller.rb +7 -0
  74. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  75. data/test/rails_app/app/models/account.rb +3 -0
  76. data/test/rails_app/app/models/admin.rb +3 -0
  77. data/test/rails_app/app/models/organizer.rb +3 -0
  78. data/test/rails_app/app/models/user.rb +3 -0
  79. data/test/rails_app/config/boot.rb +110 -0
  80. data/test/rails_app/config/environment.rb +41 -0
  81. data/test/rails_app/config/environments/development.rb +17 -0
  82. data/test/rails_app/config/environments/production.rb +28 -0
  83. data/test/rails_app/config/environments/test.rb +28 -0
  84. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  85. data/test/rails_app/config/initializers/session_store.rb +15 -0
  86. data/test/rails_app/config/routes.rb +18 -0
  87. data/test/routes_test.rb +79 -0
  88. data/test/support/assertions_helper.rb +22 -0
  89. data/test/support/integration_tests_helper.rb +66 -0
  90. data/test/support/model_tests_helper.rb +51 -0
  91. data/test/test_helper.rb +40 -0
  92. metadata +154 -0
@@ -0,0 +1,109 @@
1
+ == 0.4.2
2
+
3
+ * deprecations
4
+ * Renamed mail_sender to mailer_sender
5
+
6
+ * enhancements
7
+ * skip_before_filter added in Devise controllers
8
+ * Use home_or_root_path on require_no_authentication as well
9
+ * Added devise_controller?, useful to select or reject filters in ApplicationController
10
+ * Allow :path_prefix to be given to devise_for
11
+ * Allow default_url_options to be configured through devise (:path_prefix => "/:locale" is now supported)
12
+
13
+ == 0.4.1
14
+
15
+ * bug fix
16
+ * [#21] Ensure options can be set even if models were not loaded
17
+
18
+ == 0.4.0
19
+
20
+ * deprecations
21
+ * Notifier is deprecated, use DeviseMailer instead. Remember to rename
22
+ app/views/notifier to app/views/devise_mailer and I18n key from
23
+ devise.notifier to devise.mailer
24
+ * :authenticable calls are deprecated, use :authenticatable instead
25
+
26
+ * enhancements
27
+ * [#16] Allow devise to be more agnostic and do not require ActiveRecord to be loaded
28
+ * Allow Warden::Manager to be configured through Devise
29
+ * Created a generator which creates an initializer
30
+
31
+ == 0.3.0
32
+
33
+ * bug fix
34
+ * [#15] Allow yml messages to be configured by not using engine locales
35
+
36
+ * deprecations
37
+ * Renamed confirm_in to confirm_within
38
+ * [#14] Do not send confirmation messages when user changes his e-mail
39
+ * [#13] Renamed authenticable to authenticatable and added deprecation warnings
40
+
41
+ == 0.2.3
42
+
43
+ * enhancements
44
+ * Ensure fail! works inside strategies
45
+ * [#12] Make unauthenticated message (when you haven't signed in) different from invalid message
46
+
47
+ * bug fix
48
+ * Do not redirect on invalid authenticate
49
+ * Allow model configuration to be set to nil
50
+
51
+ == 0.2.2
52
+
53
+ * bug fix
54
+ * [#9] Fix a bug when using customized resources
55
+
56
+ == 0.2.1
57
+
58
+ * refactor
59
+ * Clean devise_views generator to use devise existing views
60
+
61
+ * enhancements
62
+ * [#7] Create instance variables (like @user) for each devise controller
63
+ * Use Devise::Controller::Helpers only internally
64
+
65
+ * bug fix
66
+ * [#6] Fix a bug with Mongrel and Ruby 1.8.6
67
+
68
+ == 0.2.0
69
+
70
+ * enhancements
71
+ * [#4] Allow option :null => true in authenticable migration
72
+ * [#3] Remove attr_accessible calls from devise modules
73
+ * Customizable time frame for rememberable with :remember_for config
74
+ * Customizable time frame for confirmable with :confirm_in config
75
+ * Generators for creating a resource and copy views
76
+
77
+ * optimize
78
+ * Do not load hooks or strategies if they are not used
79
+
80
+ * bug fixes
81
+ * [#2] Fixed requiring devise strategies
82
+
83
+ == 0.1.1
84
+
85
+ * bug fixes
86
+ * [#1] Fixed requiring devise mapping
87
+
88
+ == 0.1.0
89
+
90
+ * Devise::Authenticable
91
+ * Devise::Confirmable
92
+ * Devise::Recoverable
93
+ * Devise::Validatable
94
+ * Devise::Migratable
95
+ * Devise::Rememberable
96
+
97
+ * SessionsController
98
+ * PasswordsController
99
+ * ConfirmationsController
100
+
101
+ * Create an example app
102
+ * devise :all, :except => :rememberable
103
+ * Use sign_in and sign_out in SessionsController
104
+
105
+ * Mailer subjects namespaced by model
106
+ * Allow stretches and pepper per model
107
+
108
+ * Store session[:return_to] in session
109
+ * Sign user in automatically after confirming or changing it's password
@@ -0,0 +1,20 @@
1
+ Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,243 @@
1
+ == Devise
2
+
3
+ Devise is a flexible authentication solution for Rails based on Warden. It:
4
+
5
+ * Is Rack based;
6
+ * Is a complete MVC solution based on Rails engines;
7
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
8
+ * Is based on a modularity concept: use just what you really need.
9
+
10
+ Right now it's composed of five mainly modules:
11
+
12
+ * Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
13
+ * Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
14
+ * Recoverable: takes care of reseting the user password and send reset instructions.
15
+ * Rememberable: manages generating and clearing token for remember the user from a saved cookie.
16
+ * Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
17
+
18
+ There's an example application using Devise at http://github.com/plataformatec/devise_example .
19
+
20
+ == Dependencies
21
+
22
+ Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see instalation below).
23
+
24
+ == Installation
25
+
26
+ All gems are on gemcutter, so you need to add gemcutter to your sources if you haven't yet:
27
+
28
+ sudo gem sources -a http://gemcutter.org/
29
+
30
+ Install warden gem if you don't have it installed (requires 0.5.1 or higher):
31
+
32
+ sudo gem install warden
33
+
34
+ Install devise gem:
35
+
36
+ sudo gem install devise
37
+
38
+ Configure warden and devise gems inside your app:
39
+
40
+ config.gem 'warden'
41
+ config.gem 'devise'
42
+
43
+ And you're ready to go.
44
+
45
+ == Basic Usage
46
+
47
+ This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You can also check out the *Generators* section below to help you start.
48
+
49
+ Devise must be setted up within the model (or models) you want to use, and devise routes must be created inside your routes.rb file.
50
+
51
+ We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
52
+
53
+ create_table :users do
54
+ t.authenticatable
55
+ t.confirmable
56
+ t.recoverable
57
+ t.rememberable
58
+ t.timestamps
59
+ end
60
+
61
+ You may also want to add some indexes to improve performance:
62
+
63
+ add_index :your_table, :email
64
+ add_index :your_table, :confirmation_token # for confirmable
65
+ add_index :your_table, :reset_password_token # for recoverable
66
+
67
+ Now let's setup a User model adding the devise line to have your authentication working:
68
+
69
+ class User < ActiveRecord::Base
70
+ devise
71
+ end
72
+
73
+ This line adds devise authenticatable automatically for you inside your User class. Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
74
+
75
+ You could also include the other devise modules as below:
76
+
77
+ # Same as using only devise, authenticatable is activated by default
78
+ devise :authenticatable
79
+
80
+ # Include authenticatable + confirmable
81
+ devise :confirmable
82
+
83
+ # Include authenticatable + recoverable + rememberable
84
+ devise :recoverable, :rememberable
85
+
86
+ # Include all of them
87
+ devise :all
88
+
89
+ # Include all except recoverable
90
+ devise :all, :except => :recoverable
91
+
92
+ Note that validations aren't added by default, so you're able to customize it. In order to have automatic validations working just include :validatable.
93
+
94
+ == Model configuration
95
+
96
+ In addition to :except, you can provide :pepper, :stretches, :confirm_within and :remember_for as options to devise method.
97
+
98
+ All those options are described in "config/initializers/devise.rb", which is generated when you invoke `ruby script/generate devise_install` in your application root.
99
+
100
+ == Routes
101
+
102
+ The next step after setting up your model is to configure your routes for devise. You do this by opening up your config/routes.rb and adding:
103
+
104
+ map.devise_for :users
105
+
106
+ This is going to look inside you User model and create the needed routes:
107
+
108
+ # Session routes for Authenticatable (default)
109
+ new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
110
+ user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
111
+ destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
112
+
113
+ # Password routes for Recoverable, if User model has :recoverable configured
114
+ new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
115
+ edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
116
+ user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
117
+ POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
118
+
119
+ # Confirmation routes for Confirmable, if User model has :confirmable configured
120
+ new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
121
+ user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
122
+ POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
123
+
124
+ You can run the routes rake task to verify what routes are being created by devise.
125
+
126
+ There are also some options available for configuring your routes, as :class_name (to set the class for that route), :as and :path_names, where the last two have the same meaning as in routes. The available :path_names are:
127
+
128
+ map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
129
+
130
+ Be sure to check devise_for documentation for detailed description.
131
+
132
+ == Controller filters
133
+
134
+ Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
135
+
136
+ before_filter :authenticate_user!
137
+
138
+ To verify if a user is signed in, you have the following helper:
139
+
140
+ user_signed_in?
141
+
142
+ And to get the current signed in user this helper is available:
143
+
144
+ current_user
145
+
146
+ You have also access to the session for this scope:
147
+
148
+ user_session
149
+
150
+ After signing in a user, confirming it's account or updating it's password, devise 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. To do it so, you need to create e default root inside your routes for your application:
151
+
152
+ map.root :controller => 'home'
153
+
154
+ You also need to setup default url options for the mailer, if you are using confirmable or recoverable. Here's is the configuration for development:
155
+
156
+ DeviseMailer.sender = "no-reply@yourapp.com"
157
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
158
+
159
+ == Tidying up
160
+
161
+ Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
162
+
163
+ # Create a migration with the required fields
164
+ create_table :admins do |t|
165
+ t.authenticatable
166
+ end
167
+
168
+ # Inside your Admin model
169
+ devise :validatable
170
+
171
+ # Inside your routes
172
+ map.devise_for :admin
173
+
174
+ # Inside your protected controller
175
+ before_filter :authenticate_admin!
176
+
177
+ # Inside your controllers and views
178
+ admin_signed_in?
179
+ current_admin
180
+ admin_session
181
+
182
+ == Generators
183
+
184
+ Devise comes with some generators to help you start:
185
+
186
+ ruby script/generate devise_install
187
+
188
+ This will generate an initializer, with a description of all configuration values. You can also generate models through:
189
+
190
+ ruby script/generate devise Model
191
+
192
+ A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
193
+
194
+ You can also copy devise views to your application, being able to modify them based on your needs. To do it so, run the following command:
195
+
196
+ ruby script/generate devise_views
197
+
198
+ This is gonna copy all session, password, confirmation and mailer views to your app/views folder.
199
+
200
+ == I18n
201
+
202
+ Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can setup your locale file this way:
203
+
204
+ en:
205
+ devise:
206
+ sessions:
207
+ signed_in: 'Signed in successfully.'
208
+
209
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
210
+
211
+ en:
212
+ devise:
213
+ sessions:
214
+ user:
215
+ signed_in: 'Welcome user, you are signed in.'
216
+ admin:
217
+ signed_in: 'Hello admin!'
218
+
219
+ Devise mailer uses the same pattern to create subject messages:
220
+
221
+ en:
222
+ devise:
223
+ mailer:
224
+ confirmation_instructions: 'Hello everybody!'
225
+ user:
226
+ confirmation_instructions: 'Hello User! Please confirm your email'
227
+ reset_password_instructions: 'Reset instructions'
228
+
229
+ Take a look at our locale file to check all available messages.
230
+
231
+ == TODO
232
+
233
+ Please refer to TODO file.
234
+
235
+ == Bugs and Feedback
236
+
237
+ If you discover any bugs or want to drop a line, feel free to create an issue on
238
+ GitHub or send an e-mail to the mailing list.
239
+
240
+ http://github.com/plataformatec/devise/issues
241
+ http://groups.google.com/group/plataformatec-devise
242
+
243
+ MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+ require File.join(File.dirname(__FILE__), 'lib', 'devise', 'version')
7
+
8
+ desc 'Default: run unit tests.'
9
+ task :default => :test
10
+
11
+ desc 'Test Devise.'
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'lib'
14
+ t.libs << 'test'
15
+ t.pattern = 'test/**/*_test.rb'
16
+ t.verbose = true
17
+ end
18
+
19
+ desc 'Generate documentation for Devise.'
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'Devise'
23
+ rdoc.options << '--line-numbers' << '--inline-source'
24
+ rdoc.rdoc_files.include('README.rdoc')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ begin
29
+ require 'jeweler'
30
+ Jeweler::Tasks.new do |s|
31
+ s.name = "ramon-devise"
32
+ s.version = Devise::VERSION
33
+ s.summary = "Flexible authentication solution for Rails with Warden"
34
+ s.email = "contact@plataformatec.com.br"
35
+ s.homepage = "http://github.com/plataformatec/devise"
36
+ s.description = "Flexible authentication solution for Rails with Warden"
37
+ s.authors = ['José Valim', 'Carlos Antônio']
38
+ s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
39
+ s.add_dependency("warden", "~> 0.5.1")
40
+ end
41
+
42
+ Jeweler::GemcutterTasks.new
43
+ rescue LoadError
44
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
45
+ end
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ * Devise::Timeoutable
2
+ * Devise::TestHelper
3
+ * Use request_ip in session cookies
4
+ * Devise::BruteForceProtection
5
+ * Devise::MagicColumns
6
+ * Improve Generators to pass modules as arguments
7
+ * Different cryptography providers
8
+ * Devise::Invitable
@@ -0,0 +1,33 @@
1
+ class ConfirmationsController < ApplicationController
2
+ include Devise::Controllers::Helpers
3
+
4
+ # GET /resource/confirmation/new
5
+ def new
6
+ build_resource
7
+ end
8
+
9
+ # POST /resource/confirmation
10
+ def create
11
+ self.resource = resource_class.send_confirmation_instructions(params[resource_name])
12
+
13
+ if resource.errors.empty?
14
+ set_flash_message :success, :send_instructions
15
+ redirect_to new_session_path(resource_name)
16
+ else
17
+ render :new
18
+ end
19
+ end
20
+
21
+ # GET /resource/confirmation?perishable_token=abcdef
22
+ def show
23
+ self.resource = resource_class.confirm!(:confirmation_token => params[:confirmation_token])
24
+
25
+ if resource.errors.empty?
26
+ sign_in(resource_name, resource)
27
+ set_flash_message :success, :confirmed
28
+ redirect_to home_or_root_path
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+ end