devise 1.1.3 → 1.2.0

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.
Files changed (157) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.rdoc +94 -0
  4. data/Gemfile +24 -13
  5. data/Gemfile.lock +119 -75
  6. data/MIT-LICENSE +1 -1
  7. data/README.rdoc +144 -101
  8. data/Rakefile +3 -24
  9. data/app/controllers/devise/confirmations_controller.rb +1 -1
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
  11. data/app/controllers/devise/passwords_controller.rb +1 -1
  12. data/app/controllers/devise/registrations_controller.rb +60 -7
  13. data/app/controllers/devise/sessions_controller.rb +6 -4
  14. data/app/controllers/devise/unlocks_controller.rb +1 -1
  15. data/app/helpers/devise_helper.rb +10 -2
  16. data/app/mailers/devise/mailer.rb +27 -10
  17. data/app/views/devise/confirmations/new.html.erb +1 -1
  18. data/app/views/devise/passwords/edit.html.erb +2 -2
  19. data/app/views/devise/passwords/new.html.erb +1 -1
  20. data/app/views/devise/registrations/edit.html.erb +1 -1
  21. data/app/views/devise/registrations/new.html.erb +1 -1
  22. data/app/views/devise/sessions/new.html.erb +1 -1
  23. data/app/views/devise/shared/_links.erb +6 -0
  24. data/app/views/devise/unlocks/new.html.erb +1 -1
  25. data/config/locales/en.yml +11 -2
  26. data/devise.gemspec +25 -0
  27. data/lib/devise/controllers/helpers.rb +119 -116
  28. data/lib/devise/controllers/internal_helpers.rb +29 -8
  29. data/lib/devise/controllers/rememberable.rb +52 -0
  30. data/lib/devise/controllers/scoped_views.rb +4 -6
  31. data/lib/devise/controllers/url_helpers.rb +3 -5
  32. data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
  33. data/lib/devise/encryptors/base.rb +1 -1
  34. data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
  35. data/lib/devise/failure_app.rb +46 -10
  36. data/lib/devise/hooks/activatable.rb +2 -2
  37. data/lib/devise/hooks/forgetable.rb +1 -3
  38. data/lib/devise/hooks/rememberable.rb +5 -42
  39. data/lib/devise/hooks/timeoutable.rb +1 -1
  40. data/lib/devise/mapping.rb +18 -7
  41. data/lib/devise/models/authenticatable.rb +73 -31
  42. data/lib/devise/models/confirmable.rb +16 -20
  43. data/lib/devise/models/database_authenticatable.rb +27 -37
  44. data/lib/devise/models/encryptable.rb +72 -0
  45. data/lib/devise/models/lockable.rb +27 -21
  46. data/lib/devise/models/omniauthable.rb +23 -0
  47. data/lib/devise/models/recoverable.rb +13 -3
  48. data/lib/devise/models/registerable.rb +13 -0
  49. data/lib/devise/models/rememberable.rb +39 -34
  50. data/lib/devise/models/timeoutable.rb +20 -3
  51. data/lib/devise/models/token_authenticatable.rb +22 -10
  52. data/lib/devise/models/validatable.rb +16 -4
  53. data/lib/devise/models.rb +4 -16
  54. data/lib/devise/modules.rb +15 -8
  55. data/lib/devise/omniauth/config.rb +18 -0
  56. data/lib/devise/omniauth/url_helpers.rb +33 -0
  57. data/lib/devise/omniauth.rb +32 -0
  58. data/lib/devise/orm/active_record.rb +2 -0
  59. data/lib/devise/orm/mongoid.rb +4 -2
  60. data/lib/devise/rails/routes.rb +67 -20
  61. data/lib/devise/rails/warden_compat.rb +101 -15
  62. data/lib/devise/rails.rb +33 -44
  63. data/lib/devise/schema.rb +16 -16
  64. data/lib/devise/strategies/authenticatable.rb +48 -7
  65. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  66. data/lib/devise/strategies/rememberable.rb +6 -5
  67. data/lib/devise/strategies/token_authenticatable.rb +6 -2
  68. data/lib/devise/test_helpers.rb +13 -3
  69. data/lib/devise/version.rb +1 -1
  70. data/lib/devise.rb +162 -50
  71. data/lib/generators/active_record/devise_generator.rb +2 -2
  72. data/lib/generators/active_record/templates/migration.rb +2 -0
  73. data/lib/generators/devise/devise_generator.rb +3 -1
  74. data/lib/generators/devise/orm_helpers.rb +1 -1
  75. data/lib/generators/devise/views_generator.rb +8 -45
  76. data/lib/generators/mongoid/devise_generator.rb +2 -2
  77. data/lib/generators/templates/devise.rb +82 -39
  78. data/test/controllers/helpers_test.rb +78 -72
  79. data/test/controllers/internal_helpers_test.rb +29 -8
  80. data/test/controllers/url_helpers_test.rb +2 -1
  81. data/test/devise_test.rb +10 -0
  82. data/test/failure_app_test.rb +86 -22
  83. data/test/generators/active_record_generator_test.rb +24 -0
  84. data/test/generators/devise_generator_test.rb +33 -0
  85. data/test/generators/install_generator_test.rb +13 -0
  86. data/test/generators/mongoid_generator_test.rb +22 -0
  87. data/test/generators/views_generator_test.rb +35 -0
  88. data/test/indifferent_hash.rb +33 -0
  89. data/test/integration/authenticatable_test.rb +165 -62
  90. data/test/integration/database_authenticatable_test.rb +22 -0
  91. data/test/integration/http_authenticatable_test.rb +12 -2
  92. data/test/integration/omniauthable_test.rb +138 -0
  93. data/test/integration/recoverable_test.rb +39 -20
  94. data/test/integration/registerable_test.rb +60 -4
  95. data/test/integration/rememberable_test.rb +72 -29
  96. data/test/integration/timeoutable_test.rb +10 -1
  97. data/test/integration/token_authenticatable_test.rb +55 -6
  98. data/test/mailers/confirmation_instructions_test.rb +4 -0
  99. data/test/mailers/reset_password_instructions_test.rb +4 -0
  100. data/test/mailers/unlock_instructions_test.rb +4 -0
  101. data/test/mapping_test.rb +37 -3
  102. data/test/models/confirmable_test.rb +32 -15
  103. data/test/models/database_authenticatable_test.rb +14 -71
  104. data/test/models/encryptable_test.rb +65 -0
  105. data/test/models/lockable_test.rb +48 -11
  106. data/test/models/recoverable_test.rb +28 -2
  107. data/test/models/rememberable_test.rb +186 -125
  108. data/test/models/token_authenticatable_test.rb +19 -1
  109. data/test/models_test.rb +12 -5
  110. data/test/omniauth/url_helpers_test.rb +54 -0
  111. data/test/orm/mongoid.rb +3 -2
  112. data/test/rails_app/Rakefile +10 -0
  113. data/test/rails_app/app/active_record/admin.rb +4 -1
  114. data/test/rails_app/app/active_record/user.rb +5 -4
  115. data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
  116. data/test/rails_app/app/controllers/application_controller.rb +0 -1
  117. data/test/rails_app/app/controllers/home_controller.rb +9 -0
  118. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  119. data/test/rails_app/app/mongoid/admin.rb +4 -1
  120. data/test/rails_app/app/mongoid/shim.rb +16 -3
  121. data/test/rails_app/app/mongoid/user.rb +5 -5
  122. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  123. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  124. data/test/rails_app/app/views/home/index.html.erb +1 -0
  125. data/test/rails_app/app/views/home/private.html.erb +1 -0
  126. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  127. data/test/rails_app/app/views/users/index.html.erb +1 -0
  128. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  129. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  130. data/test/rails_app/config/application.rb +5 -0
  131. data/test/rails_app/config/boot.rb +2 -2
  132. data/test/rails_app/config/database.yml +18 -0
  133. data/test/rails_app/config/initializers/devise.rb +71 -31
  134. data/test/rails_app/config/routes.rb +14 -6
  135. data/test/rails_app/config.ru +4 -0
  136. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
  137. data/test/rails_app/db/schema.rb +17 -51
  138. data/test/rails_app/lib/shared_admin.rb +9 -0
  139. data/test/rails_app/lib/shared_user.rb +23 -0
  140. data/test/rails_app/public/404.html +26 -0
  141. data/test/rails_app/public/422.html +26 -0
  142. data/test/rails_app/public/500.html +26 -0
  143. data/test/rails_app/public/favicon.ico +0 -0
  144. data/test/rails_app/script/rails +10 -0
  145. data/test/routes_test.rb +42 -9
  146. data/test/schema_test.rb +33 -0
  147. data/test/support/integration.rb +4 -4
  148. data/test/support/locale/en.yml +4 -0
  149. data/test/support/webrat/integrations/rails.rb +11 -19
  150. data/test/test_helper.rb +8 -2
  151. data/test/test_helpers_test.rb +64 -2
  152. metadata +106 -30
  153. data/TODO +0 -3
  154. data/lib/devise/encryptors/bcrypt.rb +0 -19
  155. data/lib/generators/devise_install_generator.rb +0 -4
  156. data/lib/generators/devise_views_generator.rb +0 -4
  157. data/test/support/test_silencer.rb +0 -5
@@ -1,10 +1,10 @@
1
+ require 'shared_user'
2
+
1
3
  class User
2
4
  include Mongoid::Document
3
5
  include Shim
6
+ include SharedUser
4
7
 
5
- field :created_at, :type => DateTime
6
-
7
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
8
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
9
- :trackable, :validatable
8
+ field :username, :type => String
9
+ field :facebook_token, :type => String
10
10
  end
@@ -0,0 +1 @@
1
+ Welcome Admin!
@@ -0,0 +1,2 @@
1
+ Welcome to "sessions/new" view!
2
+ <%= render :file => "devise/sessions/new" %>
@@ -0,0 +1 @@
1
+ Home!
@@ -0,0 +1 @@
1
+ Private!
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Devise Test App</title>
6
+ </head>
7
+ <body>
8
+ <div id="container">
9
+ <%- flash.each do |name, msg| -%>
10
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
11
+ <%- end -%>
12
+
13
+ <% if user_signed_in? -%>
14
+ <p>Hello User <%= current_user.email %>! You are signed in!</p>
15
+ <% end -%>
16
+
17
+ <% if admin_signed_in? -%>
18
+ <p>Hello Admin <%= current_admin.email %>! You are signed in!</p>
19
+ <% end -%>
20
+
21
+ <%= yield %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1 @@
1
+ Welcome User #<%= current_user.id %>!
@@ -0,0 +1 @@
1
+ <%= @resource.email %>
@@ -0,0 +1 @@
1
+ Special user view
@@ -31,5 +31,10 @@ module RailsApp
31
31
  config.filter_parameters << :password
32
32
 
33
33
  config.action_mailer.default_url_options = { :host => "localhost:3000" }
34
+
35
+ # This was used to break devise in some situations
36
+ config.to_prepare do
37
+ Devise::SessionsController.layout "application"
38
+ end
34
39
  end
35
40
  end
@@ -7,7 +7,7 @@ begin
7
7
  rescue LoadError
8
8
  require 'rubygems'
9
9
  require 'bundler'
10
- Bundler.setup :default, DEVISE_ORM
10
+ Bundler.setup :default, :test, DEVISE_ORM
11
11
  end
12
12
 
13
- $:.unshift File.expand_path('../../../../lib', __FILE__)
13
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,18 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: ":memory:"
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: ":memory:"
@@ -15,20 +15,37 @@ Devise.setup do |config|
15
15
  require "devise/orm/#{DEVISE_ORM}"
16
16
 
17
17
  # ==> Configuration for any authentication mechanism
18
- # Configure which keys are used when authenticating an user. By default is
18
+ # Configure which keys are used when authenticating a user. By default is
19
19
  # just :email. You can configure it to use [:username, :subdomain], so for
20
- # authenticating an user, both parameters are required. Remember that those
20
+ # authenticating a user, both parameters are required. Remember that those
21
21
  # parameters are used only when authenticating and not when retrieving from
22
22
  # session. If you need permissions, you should implement that in a before filter.
23
+ # You can also supply hash where the value is a boolean expliciting if authentication
24
+ # should be aborted or not if the value is not present. By default is empty.
23
25
  # config.authentication_keys = [ :email ]
24
26
 
27
+ # Configure parameters from the request object used for authentication. Each entry
28
+ # given should be a request method and it will automatically be passed to
29
+ # find_for_authentication method and considered in your model lookup. For instance,
30
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
31
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
32
+ # config.request_keys = []
33
+
34
+ # Configure which authentication keys should be case-insensitive.
35
+ # These keys will be downcased upon creating or modifying a user and when used
36
+ # to authenticate or find a user. Default is :email.
37
+ config.case_insensitive_keys = [ :email ]
38
+
25
39
  # Tell if authentication through request.params is enabled. True by default.
26
40
  # config.params_authenticatable = true
27
41
 
28
- # Tell if authentication through HTTP Basic Auth is enabled. True by default.
29
- # config.http_authenticatable = true
42
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
43
+ config.http_authenticatable = true
44
+
45
+ # If http headers should be returned for AJAX requests. True by default.
46
+ # config.http_authenticatable_on_xhr = true
30
47
 
31
- # The realm used in Http Basic Authentication
48
+ # The realm used in Http Basic Authentication. "Application" by default.
32
49
  # config.http_authentication_realm = "Application"
33
50
 
34
51
  # ==> Configuration for :database_authenticatable
@@ -36,15 +53,6 @@ Devise.setup do |config|
36
53
  # using other encryptors, it sets how many times you want the password re-encrypted.
37
54
  config.stretches = 10
38
55
 
39
- # Define which will be the encryption algorithm. Devise also supports encryptors
40
- # from others authentication tools as :clearance_sha1, :authlogic_sha512 (then
41
- # you should set stretches above to 20 for default behavior) and :restful_authentication_sha1
42
- # (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
43
- config.encryptor = :bcrypt
44
-
45
- # Setup a pepper to generate the encrypted password.
46
- config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
47
-
48
56
  # ==> Configuration for :confirmable
49
57
  # The time you want to give your user to confirm his account. During this time
50
58
  # he will be able to access your application without confirming. Default is nil.
@@ -54,6 +62,9 @@ Devise.setup do |config|
54
62
  # (ie 2 days).
55
63
  # config.confirm_within = 2.days
56
64
 
65
+ # Defines which key will be used when confirming an account
66
+ # config.confirmation_keys = [ :email ]
67
+
57
68
  # ==> Configuration for :rememberable
58
69
  # The time the user will be remembered without asking for credentials again.
59
70
  # config.remember_for = 2.weeks
@@ -64,8 +75,12 @@ Devise.setup do |config|
64
75
  # If true, extends the user's remember period when remembered via cookie.
65
76
  # config.extend_remember_period = false
66
77
 
78
+ # If true, uses the password salt as remember token. This should be turned
79
+ # to false if you are not using database authenticatable.
80
+ config.use_salt_as_remember_token = true
81
+
67
82
  # ==> Configuration for :validatable
68
- # Range for password length
83
+ # Range for password length. Default is 6..20.
69
84
  # config.password_length = 6..20
70
85
 
71
86
  # Regex to use to validate the email address
@@ -73,8 +88,8 @@ Devise.setup do |config|
73
88
 
74
89
  # ==> Configuration for :timeoutable
75
90
  # The time you want to timeout the user session without activity. After this
76
- # time the user will be asked for credentials again.
77
- # config.timeout_in = 10.minutes
91
+ # time the user will be asked for credentials again. Default is 30 minutes.
92
+ # config.timeout_in = 30.minutes
78
93
 
79
94
  # ==> Configuration for :lockable
80
95
  # Defines which strategy will be used to lock an account.
@@ -82,6 +97,9 @@ Devise.setup do |config|
82
97
  # :none = No lock strategy. You should handle locking by yourself.
83
98
  # config.lock_strategy = :failed_attempts
84
99
 
100
+ # Defines which key will be used when locking and unlocking an account
101
+ # config.unlock_keys = [ :email ]
102
+
85
103
  # Defines which strategy will be used to unlock an account.
86
104
  # :email = Sends an unlock link to the user email
87
105
  # :time = Re-enables login after a certain amount of time (see :unlock_in below)
@@ -96,24 +114,44 @@ Devise.setup do |config|
96
114
  # Time interval to unlock the account if :time is enabled as unlock_strategy.
97
115
  # config.unlock_in = 1.hour
98
116
 
117
+ # ==> Configuration for :recoverable
118
+ #
119
+ # Defines which key will be used when recovering the password for an account
120
+ # config.reset_password_keys = [ :email ]
121
+
122
+ # ==> Configuration for :encryptable
123
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
124
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
125
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
126
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
127
+ # REST_AUTH_SITE_KEY to pepper)
128
+ config.encryptor = :sha512
129
+
130
+ # Setup a pepper to generate the encrypted password.
131
+ config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
132
+
99
133
  # ==> Configuration for :token_authenticatable
100
134
  # Defines name of the authentication token params key
101
135
  # config.token_authentication_key = :auth_token
102
136
 
137
+ # If true, authentication through token does not store user in session and needs
138
+ # to be supplied on each request. Useful if you are using the token as API token.
139
+ # config.stateless_token = false
140
+
103
141
  # ==> Scopes configuration
104
142
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
105
143
  # "users/sessions/new". It's turned off by default because it's slower if you
106
144
  # are using only default views.
107
- # config.scoped_views = true
145
+ # config.scoped_views = false
108
146
 
109
147
  # Configure the default scope given to Warden. By default it's the first
110
- # devise role declared in your routes.
148
+ # devise role declared in your routes (usually :user).
111
149
  # config.default_scope = :user
112
150
 
113
151
  # Configure sign_out behavior.
114
- # By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
115
- # In case of sign_out_all_scopes set to true any logout action will sign out all active scopes.
116
- # config.sign_out_all_scopes = false
152
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
153
+ # The default is true, which means any logout action will sign out all active scopes.
154
+ # config.sign_out_all_scopes = true
117
155
 
118
156
  # ==> Navigation configuration
119
157
  # Lists the formats that should be treated as navigational. Formats like
@@ -123,17 +161,19 @@ Devise.setup do |config|
123
161
  # should add them to the navigational formats lists. Default is [:html]
124
162
  # config.navigational_formats = [:html, :iphone]
125
163
 
164
+ # The default HTTP method used to sign out a resource. Default is :get.
165
+ # config.sign_out_via = :get
166
+
167
+ # ==> OmniAuth
168
+ config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access'
169
+ config.omniauth :open_id
170
+
126
171
  # ==> Warden configuration
127
- # If you want to use other strategies, that are not (yet) supported by Devise,
128
- # you can configure them inside the config.warden block. The example below
129
- # allows you to setup OAuth, using http://github.com/roman/warden_oauth
172
+ # If you want to use other strategies, that are not supported by Devise, or
173
+ # change the failure app, you can configure them inside the config.warden block.
130
174
  #
131
175
  # config.warden do |manager|
132
- # manager.oauth(:twitter) do |twitter|
133
- # twitter.consumer_secret = <YOUR CONSUMER SECRET>
134
- # twitter.consumer_key = <YOUR CONSUMER KEY>
135
- # twitter.options :site => 'http://twitter.com'
136
- # end
137
- # manager.default_strategies(:scope => :user).unshift :twitter_oauth
176
+ # manager.failure_app = AnotherApp
177
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
138
178
  # end
139
179
  end
@@ -8,7 +8,7 @@ Rails.application.routes.draw do
8
8
  resources :admins, :only => [:index]
9
9
 
10
10
  # Users scope
11
- devise_for :users do
11
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
12
12
  match "/devise_for/sign_in", :to => "devise/sessions#new"
13
13
  end
14
14
 
@@ -19,7 +19,7 @@ Rails.application.routes.draw do
19
19
  match "/sign_in", :to => "devise/sessions#new"
20
20
 
21
21
  # Admin scope
22
- devise_for :admin, :path => "admin_area", :controllers => { :sessions => "sessions" }, :skip => :passwords
22
+ devise_for :admin, :path => "admin_area", :controllers => { :sessions => "admins/sessions" }, :skip => :passwords
23
23
 
24
24
  match "/admin_area/home", :to => "admins#index", :as => :admin_root
25
25
  match "/anywhere", :to => "foo#bar", :as => :new_admin_password
@@ -29,19 +29,27 @@ Rails.application.routes.draw do
29
29
  end
30
30
 
31
31
  # Other routes for routing_test.rb
32
- namespace :publisher, :path_names => { :sign_in => "i_don_care", :sign_out => "get_out" } do
33
- devise_for :accounts, :class_name => "User", :path_names => { :sign_in => "get_in" }
32
+ namespace :publisher, :path_names => { :sign_in => "i_dont_care", :sign_out => "get_out" } do
33
+ devise_for :accounts, :class_name => "Admin", :path_names => { :sign_in => "get_in" }
34
34
  end
35
35
 
36
36
  scope ":locale" do
37
- devise_for :accounts, :singular => "manager", :class_name => "User",
37
+ devise_for :accounts, :singular => "manager", :class_name => "Admin",
38
38
  :path_names => {
39
39
  :sign_in => "login", :sign_out => "logout",
40
40
  :password => "secret", :confirmation => "verification",
41
41
  :unlock => "unblock", :sign_up => "register",
42
- :registration => "management"
42
+ :registration => "management", :cancel => "giveup"
43
43
  }
44
44
  end
45
45
 
46
+ namespace :sign_out_via, :module => "devise" do
47
+ devise_for :deletes, :sign_out_via => :delete, :class_name => "Admin"
48
+ devise_for :posts, :sign_out_via => :post, :class_name => "Admin"
49
+ devise_for :delete_or_posts, :sign_out_via => [:delete, :post], :class_name => "Admin"
50
+ end
51
+
52
+ match "/set", :to => "home#set"
53
+ match "/unauthenticated", :to => "home#unauthenticated"
46
54
  root :to => "home#index"
47
55
  end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -1,27 +1,31 @@
1
1
  class CreateTables < ActiveRecord::Migration
2
2
  def self.up
3
- [:users, :admins, :accounts].each do |table|
4
- create_table table do |t|
5
- t.database_authenticatable :null => (table == :admins)
3
+ create_table :users do |t|
4
+ t.string :username
5
+ t.string :facebook_token
6
6
 
7
- if table != :admin
8
- t.string :username
9
- t.confirmable
10
- t.recoverable
11
- t.rememberable
12
- t.trackable
13
- t.lockable
14
- t.token_authenticatable
15
- end
7
+ t.database_authenticatable :null => false
8
+ t.confirmable
9
+ t.recoverable
10
+ t.rememberable
11
+ t.trackable
12
+ t.lockable
13
+ t.token_authenticatable
14
+ t.timestamps
15
+ end
16
16
 
17
- t.timestamps
18
- end
17
+ create_table :admins do |t|
18
+ t.database_authenticatable :null => true
19
+ t.encryptable
20
+ t.rememberable :use_salt => false
21
+ t.recoverable
22
+ t.lockable
23
+ t.timestamps
19
24
  end
20
25
  end
21
26
 
22
27
  def self.down
23
- [:users, :admins, :accounts].each do |table|
24
- drop_table table
25
- end
28
+ drop_table :users
29
+ drop_table :admins
26
30
  end
27
31
  end
@@ -1,81 +1,47 @@
1
- # This file is auto-generated from the current state of the database. Instead of editing this file,
2
- # please use the migrations feature of Active Record to incrementally modify your database, and
3
- # then regenerate this schema definition.
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
- # to create the application database on another system, you should be using db:schema:load, not running
7
- # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
9
  # you'll amass, the slower it'll run and the greater likelihood for issues).
9
10
  #
10
11
  # It's strongly recommended to check this file into your version control system.
11
12
 
12
13
  ActiveRecord::Schema.define(:version => 20100401102949) do
13
14
 
14
- create_table "accounts", :force => true do |t|
15
- t.string "email", :default => "", :null => false
16
- t.string "encrypted_password", :default => "", :null => false
17
- t.string "password_salt", :default => "", :null => false
18
- t.string "username"
19
- t.string "confirmation_token"
20
- t.datetime "confirmed_at"
21
- t.datetime "confirmation_sent_at"
22
- t.string "reset_password_token"
23
- t.string "remember_token"
24
- t.datetime "remember_created_at"
25
- t.integer "sign_in_count", :default => 0
26
- t.datetime "current_sign_in_at"
27
- t.datetime "last_sign_in_at"
28
- t.string "current_sign_in_ip"
29
- t.string "last_sign_in_ip"
30
- t.integer "failed_attempts", :default => 0
31
- t.string "unlock_token"
32
- t.datetime "locked_at"
33
- t.string "authentication_token"
34
- t.datetime "created_at"
35
- t.datetime "updated_at"
36
- end
37
-
38
15
  create_table "admins", :force => true do |t|
39
- t.string "email", :default => ""
40
- t.string "encrypted_password", :default => ""
41
- t.string "password_salt", :default => ""
42
- t.string "username"
43
- t.string "confirmation_token"
44
- t.datetime "confirmed_at"
45
- t.datetime "confirmation_sent_at"
46
- t.string "reset_password_token"
16
+ t.string "email"
17
+ t.string "encrypted_password", :limit => 128
18
+ t.string "password_salt"
47
19
  t.string "remember_token"
48
20
  t.datetime "remember_created_at"
49
- t.integer "sign_in_count", :default => 0
50
- t.datetime "current_sign_in_at"
51
- t.datetime "last_sign_in_at"
52
- t.string "current_sign_in_ip"
53
- t.string "last_sign_in_ip"
54
- t.integer "failed_attempts", :default => 0
21
+ t.string "reset_password_token"
22
+ t.integer "failed_attempts", :default => 0
55
23
  t.string "unlock_token"
56
24
  t.datetime "locked_at"
57
- t.string "authentication_token"
58
25
  t.datetime "created_at"
59
26
  t.datetime "updated_at"
60
27
  end
61
28
 
62
29
  create_table "users", :force => true do |t|
63
- t.string "email", :default => "", :null => false
64
- t.string "encrypted_password", :default => "", :null => false
65
- t.string "password_salt", :default => "", :null => false
66
30
  t.string "username"
31
+ t.string "facebook_token"
32
+ t.string "email", :default => "", :null => false
33
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
67
34
  t.string "confirmation_token"
68
35
  t.datetime "confirmed_at"
69
36
  t.datetime "confirmation_sent_at"
70
37
  t.string "reset_password_token"
71
- t.string "remember_token"
72
38
  t.datetime "remember_created_at"
73
- t.integer "sign_in_count", :default => 0
39
+ t.integer "sign_in_count", :default => 0
74
40
  t.datetime "current_sign_in_at"
75
41
  t.datetime "last_sign_in_at"
76
42
  t.string "current_sign_in_ip"
77
43
  t.string "last_sign_in_ip"
78
- t.integer "failed_attempts", :default => 0
44
+ t.integer "failed_attempts", :default => 0
79
45
  t.string "unlock_token"
80
46
  t.datetime "locked_at"
81
47
  t.string "authentication_token"
@@ -0,0 +1,9 @@
1
+ module SharedAdmin
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ devise :database_authenticatable, :encryptable, :registerable,
6
+ :timeoutable, :recoverable, :rememberable, :lockable,
7
+ :unlock_strategy => :time
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module SharedUser
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ devise :database_authenticatable, :confirmable, :lockable, :recoverable,
6
+ :registerable, :rememberable, :timeoutable, :token_authenticatable,
7
+ :trackable, :validatable, :omniauthable
8
+
9
+ # They need to be included after Devise is called.
10
+ extend ExtendMethods
11
+ end
12
+
13
+ module ExtendMethods
14
+ def new_with_session(params, session)
15
+ super.tap do |user|
16
+ if data = session["devise.facebook_data"]
17
+ user.email = data["email"]
18
+ user.confirmed_at = Time.now
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENV_PATH = File.expand_path('../../config/environment', __FILE__)
5
+ BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
6
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
7
+ ROOT_PATH = File.expand_path('../..', __FILE__)
8
+
9
+ require BOOT_PATH
10
+ require 'rails/commands'