namxam-devise 1.1.0.win

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG.rdoc +455 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +118 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +311 -0
  6. data/Rakefile +55 -0
  7. data/TODO +3 -0
  8. data/app/controllers/devise/confirmations_controller.rb +33 -0
  9. data/app/controllers/devise/passwords_controller.rb +41 -0
  10. data/app/controllers/devise/registrations_controller.rb +57 -0
  11. data/app/controllers/devise/sessions_controller.rb +23 -0
  12. data/app/controllers/devise/unlocks_controller.rb +34 -0
  13. data/app/helpers/devise_helper.rb +17 -0
  14. data/app/mailers/devise/mailer.rb +71 -0
  15. data/app/views/devise/confirmations/new.html.erb +12 -0
  16. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  17. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  18. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  19. data/app/views/devise/passwords/edit.html.erb +16 -0
  20. data/app/views/devise/passwords/new.html.erb +12 -0
  21. data/app/views/devise/registrations/edit.html.erb +25 -0
  22. data/app/views/devise/registrations/new.html.erb +18 -0
  23. data/app/views/devise/sessions/new.html.erb +17 -0
  24. data/app/views/devise/shared/_links.erb +19 -0
  25. data/app/views/devise/unlocks/new.html.erb +12 -0
  26. data/config/locales/en.yml +39 -0
  27. data/lib/devise.rb +290 -0
  28. data/lib/devise/controllers/helpers.rb +231 -0
  29. data/lib/devise/controllers/internal_helpers.rb +98 -0
  30. data/lib/devise/controllers/scoped_views.rb +35 -0
  31. data/lib/devise/controllers/url_helpers.rb +41 -0
  32. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  33. data/lib/devise/encryptors/base.rb +20 -0
  34. data/lib/devise/encryptors/bcrypt.rb +19 -0
  35. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  36. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  37. data/lib/devise/encryptors/sha1.rb +25 -0
  38. data/lib/devise/encryptors/sha512.rb +25 -0
  39. data/lib/devise/failure_app.rb +107 -0
  40. data/lib/devise/hooks/activatable.rb +11 -0
  41. data/lib/devise/hooks/forgetable.rb +11 -0
  42. data/lib/devise/hooks/rememberable.rb +35 -0
  43. data/lib/devise/hooks/timeoutable.rb +22 -0
  44. data/lib/devise/hooks/trackable.rb +9 -0
  45. data/lib/devise/mapping.rb +103 -0
  46. data/lib/devise/models.rb +80 -0
  47. data/lib/devise/models/authenticatable.rb +126 -0
  48. data/lib/devise/models/confirmable.rb +164 -0
  49. data/lib/devise/models/database_authenticatable.rb +110 -0
  50. data/lib/devise/models/lockable.rb +165 -0
  51. data/lib/devise/models/recoverable.rb +81 -0
  52. data/lib/devise/models/registerable.rb +8 -0
  53. data/lib/devise/models/rememberable.rb +104 -0
  54. data/lib/devise/models/timeoutable.rb +26 -0
  55. data/lib/devise/models/token_authenticatable.rb +60 -0
  56. data/lib/devise/models/trackable.rb +30 -0
  57. data/lib/devise/models/validatable.rb +53 -0
  58. data/lib/devise/modules.rb +23 -0
  59. data/lib/devise/orm/active_record.rb +36 -0
  60. data/lib/devise/orm/mongoid.rb +29 -0
  61. data/lib/devise/path_checker.rb +18 -0
  62. data/lib/devise/rails.rb +69 -0
  63. data/lib/devise/rails/routes.rb +248 -0
  64. data/lib/devise/rails/warden_compat.rb +39 -0
  65. data/lib/devise/schema.rb +97 -0
  66. data/lib/devise/strategies/authenticatable.rb +111 -0
  67. data/lib/devise/strategies/base.rb +33 -0
  68. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  69. data/lib/devise/strategies/rememberable.rb +43 -0
  70. data/lib/devise/strategies/token_authenticatable.rb +49 -0
  71. data/lib/devise/test_helpers.rb +90 -0
  72. data/lib/devise/version.rb +3 -0
  73. data/lib/generators/active_record/devise_generator.rb +28 -0
  74. data/lib/generators/active_record/templates/migration.rb +29 -0
  75. data/lib/generators/devise/devise_generator.rb +17 -0
  76. data/lib/generators/devise/install_generator.rb +24 -0
  77. data/lib/generators/devise/orm_helpers.rb +23 -0
  78. data/lib/generators/devise/templates/README +25 -0
  79. data/lib/generators/devise/templates/devise.rb +139 -0
  80. data/lib/generators/devise/views_generator.rb +63 -0
  81. data/lib/generators/devise_install_generator.rb +4 -0
  82. data/lib/generators/devise_views_generator.rb +4 -0
  83. data/lib/generators/mongoid/devise_generator.rb +17 -0
  84. data/test/controllers/helpers_test.rb +213 -0
  85. data/test/controllers/internal_helpers_test.rb +51 -0
  86. data/test/controllers/url_helpers_test.rb +58 -0
  87. data/test/devise_test.rb +65 -0
  88. data/test/encryptors_test.rb +30 -0
  89. data/test/failure_app_test.rb +123 -0
  90. data/test/integration/authenticatable_test.rb +344 -0
  91. data/test/integration/confirmable_test.rb +104 -0
  92. data/test/integration/database_authenticatable_test.rb +38 -0
  93. data/test/integration/http_authenticatable_test.rb +49 -0
  94. data/test/integration/lockable_test.rb +109 -0
  95. data/test/integration/recoverable_test.rb +141 -0
  96. data/test/integration/registerable_test.rb +153 -0
  97. data/test/integration/rememberable_test.rb +91 -0
  98. data/test/integration/timeoutable_test.rb +80 -0
  99. data/test/integration/token_authenticatable_test.rb +88 -0
  100. data/test/integration/trackable_test.rb +64 -0
  101. data/test/mailers/confirmation_instructions_test.rb +80 -0
  102. data/test/mailers/reset_password_instructions_test.rb +68 -0
  103. data/test/mailers/unlock_instructions_test.rb +62 -0
  104. data/test/mapping_test.rb +85 -0
  105. data/test/models/confirmable_test.rb +221 -0
  106. data/test/models/database_authenticatable_test.rb +148 -0
  107. data/test/models/lockable_test.rb +188 -0
  108. data/test/models/recoverable_test.rb +138 -0
  109. data/test/models/rememberable_test.rb +176 -0
  110. data/test/models/timeoutable_test.rb +28 -0
  111. data/test/models/token_authenticatable_test.rb +37 -0
  112. data/test/models/trackable_test.rb +5 -0
  113. data/test/models/validatable_test.rb +99 -0
  114. data/test/models_test.rb +77 -0
  115. data/test/orm/active_record.rb +9 -0
  116. data/test/orm/mongoid.rb +10 -0
  117. data/test/rails_app/app/active_record/admin.rb +3 -0
  118. data/test/rails_app/app/active_record/shim.rb +2 -0
  119. data/test/rails_app/app/active_record/user.rb +7 -0
  120. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  121. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  122. data/test/rails_app/app/controllers/home_controller.rb +7 -0
  123. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  124. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  125. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  126. data/test/rails_app/app/controllers/users_controller.rb +18 -0
  127. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  128. data/test/rails_app/app/mongoid/admin.rb +6 -0
  129. data/test/rails_app/app/mongoid/shim.rb +16 -0
  130. data/test/rails_app/app/mongoid/user.rb +10 -0
  131. data/test/rails_app/config/application.rb +35 -0
  132. data/test/rails_app/config/boot.rb +13 -0
  133. data/test/rails_app/config/environment.rb +5 -0
  134. data/test/rails_app/config/environments/development.rb +19 -0
  135. data/test/rails_app/config/environments/production.rb +33 -0
  136. data/test/rails_app/config/environments/test.rb +33 -0
  137. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  138. data/test/rails_app/config/initializers/devise.rb +136 -0
  139. data/test/rails_app/config/initializers/inflections.rb +2 -0
  140. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  141. data/test/rails_app/config/routes.rb +47 -0
  142. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  143. data/test/rails_app/db/schema.rb +86 -0
  144. data/test/routes_test.rb +146 -0
  145. data/test/support/assertions.rb +24 -0
  146. data/test/support/helpers.rb +54 -0
  147. data/test/support/integration.rb +88 -0
  148. data/test/support/test_silencer.rb +5 -0
  149. data/test/support/webrat/integrations/rails.rb +32 -0
  150. data/test/test_helper.rb +21 -0
  151. data/test/test_helpers_test.rb +72 -0
  152. metadata +230 -0
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+
3
+ if File.exist? File.expand_path('../../rails', __FILE__)
4
+ gem "rails", :path => "../rails"
5
+ else
6
+ gem "rails", :git => "git://github.com/rails/rails.git"
7
+ end
8
+
9
+ gem "warden", "0.10.7"
10
+ gem "sqlite3-ruby"
11
+ gem "webrat", "0.7.0"
12
+ gem "mocha", :require => false
13
+ #gem "bcrypt-ruby", :require => "bcrypt"
14
+
15
+ if RUBY_VERSION < '1.9'
16
+ gem "ruby-debug", ">= 0.10.3"
17
+ end
18
+
19
+ group :mongoid do
20
+ gem "mongo"
21
+ gem "mongoid", :git => "git://github.com/durran/mongoid.git"
22
+ gem "bson_ext"
23
+ end
@@ -0,0 +1,118 @@
1
+ GIT
2
+ remote: git://github.com/durran/mongoid.git
3
+ revision: a5abe21
4
+ specs:
5
+ mongoid (2.0.0.beta9)
6
+ activemodel (~> 3.0.0.beta)
7
+ bson (~> 1.0.3)
8
+ mongo (~> 1.0.3)
9
+ tzinfo (~> 0.3.22)
10
+ will_paginate (~> 3.0.pre)
11
+
12
+ PATH
13
+ remote: /Users/jose/Work/github/rails
14
+ specs:
15
+ actionmailer (3.0.0.beta4)
16
+ actionpack (= 3.0.0.beta4)
17
+ mail (~> 2.2.5)
18
+ actionpack (3.0.0.beta4)
19
+ activemodel (= 3.0.0.beta4)
20
+ activesupport (= 3.0.0.beta4)
21
+ builder (~> 2.1.2)
22
+ erubis (~> 2.6.6)
23
+ i18n (~> 0.4.1)
24
+ rack (~> 1.2.1)
25
+ rack-mount (~> 0.6.9)
26
+ rack-test (~> 0.5.4)
27
+ tzinfo (~> 0.3.22)
28
+ activemodel (3.0.0.beta4)
29
+ activesupport (= 3.0.0.beta4)
30
+ builder (~> 2.1.2)
31
+ i18n (~> 0.4.1)
32
+ activerecord (3.0.0.beta4)
33
+ activemodel (= 3.0.0.beta4)
34
+ activesupport (= 3.0.0.beta4)
35
+ arel (~> 0.4.0)
36
+ tzinfo (~> 0.3.22)
37
+ activeresource (3.0.0.beta4)
38
+ activemodel (= 3.0.0.beta4)
39
+ activesupport (= 3.0.0.beta4)
40
+ activesupport (3.0.0.beta4)
41
+ rails (3.0.0.beta4)
42
+ actionmailer (= 3.0.0.beta4)
43
+ actionpack (= 3.0.0.beta4)
44
+ activerecord (= 3.0.0.beta4)
45
+ activeresource (= 3.0.0.beta4)
46
+ activesupport (= 3.0.0.beta4)
47
+ bundler (>= 1.0.0.beta.5)
48
+ railties (= 3.0.0.beta4)
49
+ railties (3.0.0.beta4)
50
+ actionpack (= 3.0.0.beta4)
51
+ activesupport (= 3.0.0.beta4)
52
+ rake (>= 0.8.3)
53
+ thor (~> 0.13.7)
54
+
55
+ GEM
56
+ remote: http://rubygems.org/
57
+ specs:
58
+ abstract (1.0.0)
59
+ arel (0.4.0)
60
+ activesupport (>= 3.0.0.beta)
61
+ bcrypt-ruby (2.1.2)
62
+ bson (1.0.4)
63
+ bson_ext (1.0.4)
64
+ builder (2.1.2)
65
+ columnize (0.3.1)
66
+ erubis (2.6.6)
67
+ abstract (>= 1.0.0)
68
+ i18n (0.4.1)
69
+ linecache (0.43)
70
+ mail (2.2.5)
71
+ activesupport (>= 2.3.6)
72
+ mime-types
73
+ treetop (>= 1.4.5)
74
+ mime-types (1.16)
75
+ mocha (0.9.8)
76
+ rake
77
+ mongo (1.0.5)
78
+ bson (>= 1.0.4)
79
+ nokogiri (1.4.2)
80
+ polyglot (0.3.1)
81
+ rack (1.2.1)
82
+ rack-mount (0.6.9)
83
+ rack (>= 1.0.0)
84
+ rack-test (0.5.4)
85
+ rack (>= 1.0)
86
+ rake (0.8.7)
87
+ ruby-debug (0.10.3)
88
+ columnize (>= 0.1)
89
+ ruby-debug-base (~> 0.10.3.0)
90
+ ruby-debug-base (0.10.3)
91
+ linecache (>= 0.3)
92
+ sqlite3-ruby (1.3.1)
93
+ thor (0.13.8)
94
+ treetop (1.4.8)
95
+ polyglot (>= 0.3.1)
96
+ tzinfo (0.3.22)
97
+ warden (0.10.7)
98
+ rack (>= 1.0.0)
99
+ webrat (0.7.0)
100
+ nokogiri (>= 1.2.0)
101
+ rack (>= 1.0)
102
+ rack-test (>= 0.5.3)
103
+ will_paginate (3.0.pre)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ bcrypt-ruby
110
+ bson_ext
111
+ mocha
112
+ mongo
113
+ mongoid!
114
+ rails!
115
+ ruby-debug (>= 0.10.3)
116
+ sqlite3-ruby
117
+ warden (= 0.10.7)
118
+ webrat (= 0.7.0)
@@ -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,311 @@
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 11 modules:
11
+
12
+ * Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
13
+ * Token Authenticatable: signs in an 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
+ * Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
15
+ * Recoverable: resets the user password and sends reset instructions.
16
+ * Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
17
+ * Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
18
+ * Trackable: tracks sign in count, timestamps and IP address.
19
+ * Timeoutable: expires sessions that have no activity in a specified period of time.
20
+ * Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
21
+ * Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
22
+
23
+ == Installation
24
+
25
+ Devise 1.1 supports Rails 3 and is NOT backward compatible. You can use the latest Rails 3 beta gem with Devise latest gem:
26
+
27
+ gem install devise --version=1.1.rc2
28
+
29
+ If you want to use Rails master (from git repository) you need to use Devise from git repository and vice-versa.
30
+
31
+ After you install Devise and add it to your Gemfile, you need to run the generator:
32
+
33
+ rails generate devise:install
34
+
35
+ The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
36
+
37
+ rails generate devise MODEL
38
+
39
+ Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
40
+
41
+ == Rails 2.3
42
+
43
+ If you want to use the Rails 2.3.x version, you should do:
44
+
45
+ gem install devise --version=1.0.8
46
+
47
+ And please check the README at the v1.0 branch since this one is based on Rails 3:
48
+
49
+ http://github.com/plataformatec/devise/tree/v1.0
50
+
51
+ == Ecosystem
52
+
53
+ Devise ecosystem is growing solid day after day. If you just need a walkthrough about setting up Devise, this README will work great. But if you need more documentation and resources, please check both the wiki and rdoc:
54
+
55
+ * http://rdoc.info/projects/plataformatec/devise
56
+ * http://wiki.github.com/plataformatec/devise
57
+
58
+ Both links above are for Devise with Rails 3. If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
59
+
60
+ Another great way to learn Devise are Ryan Bates' screencasts:
61
+
62
+ * http://railscasts.com/episodes/209-introducing-devise
63
+ * http://railscasts.com/episodes/210-customizing-devise
64
+
65
+ And a few example applications:
66
+
67
+ * Rails 2.3 app using Devise at http://github.com/plataformatec/devise_example
68
+ * Rails 2.3 app using Devise with subdomains at http://github.com/fortuity/subdomain-authentication
69
+ * Rails 3.0 app with Mongoid at http://github.com/fortuity/rails3-mongoid-devise
70
+
71
+ Finally, Devise also has several extensions built by the community. Don't forget to check them at the end of this README. If you want to write an extension on your own, you should also check Warden (http://github.com/hassox/warden), a Rack Authentication Framework which Devise depends on.
72
+
73
+ == Basic Usage
74
+
75
+ This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
76
+
77
+ Devise must be set up within the model (or models) you want to use. Devise routes must be created inside your config/routes.rb file.
78
+
79
+ We're assuming here you want a User model with some Devise modules, as outlined below:
80
+
81
+ class User < ActiveRecord::Base
82
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
83
+ end
84
+
85
+ After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
86
+
87
+ create_table :users do |t|
88
+ t.database_authenticatable
89
+ t.confirmable
90
+ t.recoverable
91
+ t.rememberable
92
+ t.trackable
93
+ t.timestamps
94
+ end
95
+
96
+ Devise doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
97
+
98
+ Configure your routes after setting up your model. Open your config/routes.rb file and add:
99
+
100
+ devise_for :users
101
+
102
+ This will use your User model to create a set of needed routes (you can see them by running `rake routes`).
103
+
104
+ Options for configuring your routes include :class_name (to set the class for that route), :path_prefix, :path and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
105
+
106
+ devise_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' }
107
+
108
+ Be sure to check devise_for documentation for details.
109
+
110
+ This exactly what the devise generator produces for you: model, routes and migrations. 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.
111
+
112
+ == Controller filters and helpers
113
+
114
+ Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
115
+
116
+ before_filter :authenticate_user!
117
+
118
+ To verify if a user is signed in, use the following helper:
119
+
120
+ user_signed_in?
121
+
122
+ For the current signed-in user, this helper is available:
123
+
124
+ current_user
125
+
126
+ You can access the session for this scope:
127
+
128
+ user_session
129
+
130
+ After signing in a user, confirming the account or updating the 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. This means that you need to set the root inside your routes:
131
+
132
+ root :to => "home"
133
+
134
+ You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
135
+
136
+ Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
137
+
138
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
139
+
140
+ == Tidying up
141
+
142
+ Devise 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:
143
+
144
+ # Create a migration with the required fields
145
+ create_table :admins do |t|
146
+ t.database_authenticatable
147
+ t.lockable
148
+ t.trackable
149
+ t.timestamps
150
+ end
151
+
152
+ # Inside your Admin model
153
+ devise :database_authenticatable, :trackable, :timeoutable, :lockable
154
+
155
+ # Inside your routes
156
+ devise_for :admins
157
+
158
+ # Inside your protected controller
159
+ before_filter :authenticate_admin!
160
+
161
+ # Inside your controllers and views
162
+ admin_signed_in?
163
+ current_admin
164
+ admin_session
165
+
166
+ == Model configuration
167
+
168
+ The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
169
+
170
+ devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
171
+
172
+ Besides :encryptor, you can define :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
173
+
174
+ == Configuring views
175
+
176
+ We built Devise 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.
177
+
178
+ Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after sometime 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:
179
+
180
+ rails generate devise:views
181
+
182
+ However, if you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
183
+
184
+ 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, Devise will use the default view at "devise/sessions/new".
185
+
186
+ == Configuring controllers
187
+
188
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
189
+
190
+ 1) Create your custom controller, for example a Admins::SessionsController:
191
+
192
+ class Admins::SessionsController < Devise::SessionsController
193
+ end
194
+
195
+ 2) Tell the router to use this controller:
196
+
197
+ devise_for :admins, :controllers => { :sessions => "admin/sessions" }
198
+
199
+ 3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
200
+
201
+ Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
202
+
203
+ == I18n
204
+
205
+ Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
206
+
207
+ en:
208
+ devise:
209
+ sessions:
210
+ signed_in: 'Signed in successfully.'
211
+
212
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
213
+
214
+ en:
215
+ devise:
216
+ sessions:
217
+ user:
218
+ signed_in: 'Welcome user, you are signed in.'
219
+ admin:
220
+ signed_in: 'Hello admin!'
221
+
222
+ The Devise mailer uses the same pattern to create subject messages:
223
+
224
+ en:
225
+ devise:
226
+ mailer:
227
+ confirmation_instructions: 'Hello everybody!'
228
+ user:
229
+ confirmation_instructions: 'Hello User! Please confirm your email'
230
+ reset_password_instructions: 'Reset instructions'
231
+
232
+ Take a look at our locale file to check all available messages.
233
+
234
+ == Test helpers
235
+
236
+ Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
237
+
238
+ sign_in :user, @user # sign_in(scope, resource)
239
+ sign_in @user # sign_in(resource)
240
+
241
+ sign_out :user # sign_out(scope)
242
+ sign_out @user # sign_out(resource)
243
+
244
+ You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
245
+
246
+ class ActionController::TestCase
247
+ include Devise::TestHelpers
248
+ end
249
+
250
+ 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 (http://wiki.github.com/plataformatec/devise).
251
+
252
+ == Migrating from other solutions
253
+
254
+ Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
255
+
256
+ == Other ORMs
257
+
258
+ Devise supports ActiveRecord (by default) and Mongoid. We offer experimental Datamapper support (with the limitation that the Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
259
+
260
+ == Extensions
261
+
262
+ Devise also has extensions created by the community:
263
+
264
+ * http://github.com/scambra/devise_invitable adds support to Devise for sending invitations by email.
265
+
266
+ * http://github.com/grimen/devise_facebook_connectable adds support for Facebook Connect authentication, and optionally fetching user info from Facebook in the same step.
267
+
268
+ * http://github.com/joshk/devise_imapable adds support for imap based authentication, excellent for internal apps when an LDAP server isn't available.
269
+
270
+ * http://github.com/cschiewek/devise_ldap_authenticatable adds support for LDAP authentication via simple bind.
271
+
272
+ Please consult their respective documentation for more information and requirements.
273
+
274
+ == TODO
275
+
276
+ Please refer to TODO file.
277
+
278
+ == Security
279
+
280
+ Needless to say, security is extremely important to Devise. If you find yourself in a possible security issue with Devise, please go through the following steps, trying to reproduce the bug:
281
+
282
+ 1) Look at the source code a bit to find out whether your assumptions are correct;
283
+ 2) If possible, provide a way to reproduce the bug: a small app on Github or a step-by-step to reproduce;
284
+ 3) E-mail us or send a Github private message instead of using the normal issues;
285
+
286
+ Being able to reproduce the bug is the first step to fix it. Thanks for your understanding.
287
+
288
+ == Maintainers
289
+
290
+ * José Valim (http://github.com/josevalim)
291
+ * Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
292
+
293
+ == Contributors
294
+
295
+ We have a long list of valued contributors. Check them all at:
296
+
297
+ http://github.com/plataformatec/devise/contributors
298
+
299
+ == Bugs and Feedback
300
+
301
+ If you discover any bugs, please create an issue on GitHub.
302
+
303
+ http://github.com/plataformatec/devise/issues
304
+
305
+ For support, send an e-mail to the mailing list.
306
+
307
+ http://groups.google.com/group/plataformatec-devise
308
+
309
+ == License
310
+
311
+ MIT License. Copyright 2010 Plataforma Tecnologia. http://blog.plataformatec.com.br