shingara-devise 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +119 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +253 -0
- data/Rakefile +45 -0
- data/TODO +5 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +41 -0
- data/app/controllers/sessions_controller.rb +33 -0
- data/app/models/devise_mailer.rb +53 -0
- data/app/views/confirmations/new.html.erb +16 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/passwords/edit.html.erb +20 -0
- data/app/views/passwords/new.html.erb +16 -0
- data/app/views/sessions/new.html.erb +23 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +25 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/README +22 -0
- data/generators/devise/templates/migration.rb +20 -0
- data/generators/devise/templates/model.rb +5 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +9 -0
- data/generators/devise_install/templates/devise.rb +47 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +24 -0
- data/init.rb +2 -0
- data/lib/devise/controllers/filters.rb +111 -0
- data/lib/devise/controllers/helpers.rb +130 -0
- data/lib/devise/controllers/url_helpers.rb +49 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +28 -0
- data/lib/devise/encryptors/clearance_sha1.rb +26 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +29 -0
- data/lib/devise/encryptors/sha1.rb +34 -0
- data/lib/devise/encryptors/sha512.rb +34 -0
- data/lib/devise/failure.rb +36 -0
- data/lib/devise/hooks/confirmable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +27 -0
- data/lib/devise/locales/en.yml +18 -0
- data/lib/devise/mapping.rb +120 -0
- data/lib/devise/migrations.rb +57 -0
- data/lib/devise/models/authenticatable.rb +87 -0
- data/lib/devise/models/confirmable.rb +156 -0
- data/lib/devise/models/recoverable.rb +88 -0
- data/lib/devise/models/rememberable.rb +95 -0
- data/lib/devise/models/validatable.rb +36 -0
- data/lib/devise/models.rb +110 -0
- data/lib/devise/orm/mongo_mapper.rb +26 -0
- data/lib/devise/rails/routes.rb +109 -0
- data/lib/devise/rails/warden_compat.rb +26 -0
- data/lib/devise/rails.rb +17 -0
- data/lib/devise/strategies/authenticatable.rb +46 -0
- data/lib/devise/strategies/base.rb +24 -0
- data/lib/devise/strategies/rememberable.rb +35 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise/warden.rb +20 -0
- data/lib/devise.rb +130 -0
- data/test/controllers/filters_test.rb +103 -0
- data/test/controllers/helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +72 -0
- data/test/encryptors_test.rb +28 -0
- data/test/failure_test.rb +34 -0
- data/test/integration/authenticatable_test.rb +195 -0
- data/test/integration/confirmable_test.rb +89 -0
- data/test/integration/recoverable_test.rb +131 -0
- data/test/integration/rememberable_test.rb +65 -0
- data/test/mailers/confirmation_instructions_test.rb +59 -0
- data/test/mailers/reset_password_instructions_test.rb +62 -0
- data/test/mapping_test.rb +101 -0
- data/test/models/authenticatable_test.rb +130 -0
- data/test/models/confirmable_test.rb +237 -0
- data/test/models/recoverable_test.rb +141 -0
- data/test/models/rememberable_test.rb +130 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +111 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/models/account.rb +3 -0
- data/test/rails_app/app/models/admin.rb +3 -0
- data/test/rails_app/app/models/organizer.rb +3 -0
- data/test/rails_app/app/models/user.rb +3 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +41 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +18 -0
- data/test/routes_test.rb +79 -0
- data/test/support/assertions_helper.rb +22 -0
- data/test/support/integration_tests_helper.rb +66 -0
- data/test/support/model_tests_helper.rb +51 -0
- data/test/test_helper.rb +40 -0
- metadata +161 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
* enhancements
|
2
|
+
* Moved encryption strategy into the Encryptors module to allow several algorithms (by github.com/mhfs)
|
3
|
+
* Implemented encryptors for Clearance, Authlogic and Restful-Authentication (by github.com/mhfs)
|
4
|
+
|
5
|
+
== 0.4.3
|
6
|
+
|
7
|
+
* bug fix
|
8
|
+
* [#29] Authentication fail if user cannot be serialized from session;
|
9
|
+
* Default configuration values should not overwrite user values;
|
10
|
+
|
11
|
+
== 0.4.2
|
12
|
+
|
13
|
+
* deprecations
|
14
|
+
* Renamed mail_sender to mailer_sender
|
15
|
+
|
16
|
+
* enhancements
|
17
|
+
* skip_before_filter added in Devise controllers
|
18
|
+
* Use home_or_root_path on require_no_authentication as well
|
19
|
+
* Added devise_controller?, useful to select or reject filters in ApplicationController
|
20
|
+
* Allow :path_prefix to be given to devise_for
|
21
|
+
* Allow default_url_options to be configured through devise (:path_prefix => "/:locale" is now supported)
|
22
|
+
|
23
|
+
== 0.4.1
|
24
|
+
|
25
|
+
* bug fix
|
26
|
+
* [#21] Ensure options can be set even if models were not loaded
|
27
|
+
|
28
|
+
== 0.4.0
|
29
|
+
|
30
|
+
* deprecations
|
31
|
+
* Notifier is deprecated, use DeviseMailer instead. Remember to rename
|
32
|
+
app/views/notifier to app/views/devise_mailer and I18n key from
|
33
|
+
devise.notifier to devise.mailer
|
34
|
+
* :authenticable calls are deprecated, use :authenticatable instead
|
35
|
+
|
36
|
+
* enhancements
|
37
|
+
* [#16] Allow devise to be more agnostic and do not require ActiveRecord to be loaded
|
38
|
+
* Allow Warden::Manager to be configured through Devise
|
39
|
+
* Created a generator which creates an initializer
|
40
|
+
|
41
|
+
== 0.3.0
|
42
|
+
|
43
|
+
* bug fix
|
44
|
+
* [#15] Allow yml messages to be configured by not using engine locales
|
45
|
+
|
46
|
+
* deprecations
|
47
|
+
* Renamed confirm_in to confirm_within
|
48
|
+
* [#14] Do not send confirmation messages when user changes his e-mail
|
49
|
+
* [#13] Renamed authenticable to authenticatable and added deprecation warnings
|
50
|
+
|
51
|
+
== 0.2.3
|
52
|
+
|
53
|
+
* enhancements
|
54
|
+
* Ensure fail! works inside strategies
|
55
|
+
* [#12] Make unauthenticated message (when you haven't signed in) different from invalid message
|
56
|
+
|
57
|
+
* bug fix
|
58
|
+
* Do not redirect on invalid authenticate
|
59
|
+
* Allow model configuration to be set to nil
|
60
|
+
|
61
|
+
== 0.2.2
|
62
|
+
|
63
|
+
* bug fix
|
64
|
+
* [#9] Fix a bug when using customized resources
|
65
|
+
|
66
|
+
== 0.2.1
|
67
|
+
|
68
|
+
* refactor
|
69
|
+
* Clean devise_views generator to use devise existing views
|
70
|
+
|
71
|
+
* enhancements
|
72
|
+
* [#7] Create instance variables (like @user) for each devise controller
|
73
|
+
* Use Devise::Controller::Helpers only internally
|
74
|
+
|
75
|
+
* bug fix
|
76
|
+
* [#6] Fix a bug with Mongrel and Ruby 1.8.6
|
77
|
+
|
78
|
+
== 0.2.0
|
79
|
+
|
80
|
+
* enhancements
|
81
|
+
* [#4] Allow option :null => true in authenticable migration
|
82
|
+
* [#3] Remove attr_accessible calls from devise modules
|
83
|
+
* Customizable time frame for rememberable with :remember_for config
|
84
|
+
* Customizable time frame for confirmable with :confirm_in config
|
85
|
+
* Generators for creating a resource and copy views
|
86
|
+
|
87
|
+
* optimize
|
88
|
+
* Do not load hooks or strategies if they are not used
|
89
|
+
|
90
|
+
* bug fixes
|
91
|
+
* [#2] Fixed requiring devise strategies
|
92
|
+
|
93
|
+
== 0.1.1
|
94
|
+
|
95
|
+
* bug fixes
|
96
|
+
* [#1] Fixed requiring devise mapping
|
97
|
+
|
98
|
+
== 0.1.0
|
99
|
+
|
100
|
+
* Devise::Authenticable
|
101
|
+
* Devise::Confirmable
|
102
|
+
* Devise::Recoverable
|
103
|
+
* Devise::Validatable
|
104
|
+
* Devise::Migratable
|
105
|
+
* Devise::Rememberable
|
106
|
+
|
107
|
+
* SessionsController
|
108
|
+
* PasswordsController
|
109
|
+
* ConfirmationsController
|
110
|
+
|
111
|
+
* Create an example app
|
112
|
+
* devise :all, :except => :rememberable
|
113
|
+
* Use sign_in and sign_out in SessionsController
|
114
|
+
|
115
|
+
* Mailer subjects namespaced by model
|
116
|
+
* Allow stretches and pepper per model
|
117
|
+
|
118
|
+
* Store session[:return_to] in session
|
119
|
+
* Sign user in automatically after confirming or changing it's password
|
data/MIT-LICENSE
ADDED
@@ -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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,253 @@
|
|
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.2 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
|
+
== Migrating from other solutions
|
232
|
+
|
233
|
+
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
|
234
|
+
|
235
|
+
== TODO
|
236
|
+
|
237
|
+
Please refer to TODO file.
|
238
|
+
|
239
|
+
== Contributors
|
240
|
+
|
241
|
+
* José Valim (http://github.com/josevalim)
|
242
|
+
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
|
243
|
+
* Marcelo Silveira (http://github.com/mhfs)
|
244
|
+
|
245
|
+
== Bugs and Feedback
|
246
|
+
|
247
|
+
If you discover any bugs or want to drop a line, feel free to create an issue on
|
248
|
+
GitHub or send an e-mail to the mailing list.
|
249
|
+
|
250
|
+
http://github.com/plataformatec/devise/issues
|
251
|
+
http://groups.google.com/group/plataformatec-devise
|
252
|
+
|
253
|
+
MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
data/Rakefile
ADDED
@@ -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 = "shingara-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.2")
|
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,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?confirmation_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
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class PasswordsController < ApplicationController
|
2
|
+
include Devise::Controllers::Helpers
|
3
|
+
|
4
|
+
before_filter :require_no_authentication
|
5
|
+
|
6
|
+
# GET /resource/password/new
|
7
|
+
def new
|
8
|
+
build_resource
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /resource/password
|
12
|
+
def create
|
13
|
+
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
14
|
+
|
15
|
+
if resource.errors.empty?
|
16
|
+
set_flash_message :success, :send_instructions
|
17
|
+
redirect_to new_session_path(resource_name)
|
18
|
+
else
|
19
|
+
render :new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /resource/password/edit?reset_password_token=abcdef
|
24
|
+
def edit
|
25
|
+
self.resource = resource_class.new
|
26
|
+
resource.reset_password_token = params[:reset_password_token]
|
27
|
+
end
|
28
|
+
|
29
|
+
# PUT /resource/password
|
30
|
+
def update
|
31
|
+
self.resource = resource_class.reset_password!(params[resource_name])
|
32
|
+
|
33
|
+
if resource.errors.empty?
|
34
|
+
sign_in(resource_name, resource)
|
35
|
+
set_flash_message :success, :updated
|
36
|
+
redirect_to home_or_root_path
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
include Devise::Controllers::Helpers
|
3
|
+
|
4
|
+
before_filter :require_no_authentication, :only => [ :new, :create ]
|
5
|
+
|
6
|
+
# GET /resource/sign_in
|
7
|
+
def new
|
8
|
+
Devise::FLASH_MESSAGES.each do |message, type|
|
9
|
+
set_now_flash_message type, message if params.key?(message)
|
10
|
+
end
|
11
|
+
build_resource
|
12
|
+
end
|
13
|
+
|
14
|
+
# POST /resource/sign_in
|
15
|
+
def create
|
16
|
+
if authenticate(resource_name)
|
17
|
+
set_flash_message :success, :signed_in
|
18
|
+
redirect_back_or_to home_or_root_path
|
19
|
+
else
|
20
|
+
set_now_flash_message :failure, :invalid
|
21
|
+
build_resource
|
22
|
+
render :new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /resource/sign_out
|
27
|
+
def destroy
|
28
|
+
set_flash_message :success, :signed_out if signed_in?(resource_name)
|
29
|
+
sign_out(resource_name)
|
30
|
+
redirect_to root_path
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class DeviseMailer < ::ActionMailer::Base
|
2
|
+
|
3
|
+
# Sets who is sending the e-mail
|
4
|
+
def self.sender=(value)
|
5
|
+
@@sender = value
|
6
|
+
end
|
7
|
+
|
8
|
+
# Reads who is sending the e-mail
|
9
|
+
def self.sender
|
10
|
+
@@sender
|
11
|
+
end
|
12
|
+
self.sender = nil
|
13
|
+
|
14
|
+
# Deliver confirmation instructions when the user is created or its email is
|
15
|
+
# updated, and also when confirmation is manually requested
|
16
|
+
def confirmation_instructions(record)
|
17
|
+
setup_mail(record, :confirmation_instructions)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Deliver reset password instructions when manually requested
|
21
|
+
def reset_password_instructions(record)
|
22
|
+
setup_mail(record, :reset_password_instructions)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Configure default email options
|
28
|
+
def setup_mail(record, key)
|
29
|
+
mapping = Devise.mappings.values.find { |m| m.to == record.class }
|
30
|
+
raise "Invalid devise resource #{record}" unless mapping
|
31
|
+
|
32
|
+
subject translate(mapping, key)
|
33
|
+
from self.class.sender
|
34
|
+
recipients record.email
|
35
|
+
sent_on Time.now
|
36
|
+
content_type 'text/html'
|
37
|
+
body mapping.name => record, :resource => record
|
38
|
+
end
|
39
|
+
|
40
|
+
# Setup subject namespaced by model. It means you're able to setup your
|
41
|
+
# messages using specific resource scope, or provide a default one.
|
42
|
+
# Example (i18n locale file):
|
43
|
+
#
|
44
|
+
# en:
|
45
|
+
# devise:
|
46
|
+
# mailer:
|
47
|
+
# confirmation_instructions: '...'
|
48
|
+
# user:
|
49
|
+
# confirmation_instructions: '...'
|
50
|
+
def translate(mapping, key)
|
51
|
+
I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h2>Resend confirmation instructions</h2>
|
2
|
+
|
3
|
+
<% form_for resource_name, resource, :url => confirmation_path(resource_name) do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %></p>
|
7
|
+
<p><%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Resend confirmation instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
13
|
+
|
14
|
+
<%- if devise_mapping.recoverable? %>
|
15
|
+
<%= link_to "Forgot password?", new_password_path(resource_name) %><br />
|
16
|
+
<% end -%>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Someone has requested a link to change your password, and you can do this through the link below.
|
4
|
+
|
5
|
+
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
|
6
|
+
|
7
|
+
If you didn't request this, please ignore this email.
|
8
|
+
Your password won't change until you access the link above and create a new one.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<% form_for resource_name, resource, :url => password_path(resource_name), :html => { :method => :put } do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
<%= f.hidden_field :reset_password_token %>
|
6
|
+
|
7
|
+
<p><%= f.label :password %></p>
|
8
|
+
<p><%= f.password_field :password %></p>
|
9
|
+
|
10
|
+
<p><%= f.label :password_confirmation %></p>
|
11
|
+
<p><%= f.password_field :password_confirmation %></p>
|
12
|
+
|
13
|
+
<p><%= f.submit "Change my password" %></p>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
17
|
+
|
18
|
+
<%- if devise_mapping.confirmable? %>
|
19
|
+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
20
|
+
<% end -%>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h2>Forgot your password?</h2>
|
2
|
+
|
3
|
+
<% form_for resource_name, resource, :url => password_path(resource_name) do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
|
6
|
+
<p><%= f.label :email %></p>
|
7
|
+
<p><%= f.text_field :email %></p>
|
8
|
+
|
9
|
+
<p><%= f.submit "Send me reset password instructions" %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
13
|
+
|
14
|
+
<%- if devise_mapping.confirmable? %>
|
15
|
+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
16
|
+
<% end -%>
|