devise 1.1.9 → 1.2.rc

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/CHANGELOG.rdoc +34 -26
  2. data/README.rdoc +134 -100
  3. data/app/controllers/devise/confirmations_controller.rb +1 -1
  4. data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
  5. data/app/controllers/devise/passwords_controller.rb +1 -1
  6. data/app/controllers/devise/registrations_controller.rb +59 -6
  7. data/app/controllers/devise/sessions_controller.rb +3 -2
  8. data/app/controllers/devise/unlocks_controller.rb +1 -1
  9. data/app/helpers/devise_helper.rb +4 -2
  10. data/app/mailers/devise/mailer.rb +27 -10
  11. data/app/views/devise/confirmations/new.html.erb +1 -1
  12. data/app/views/devise/passwords/edit.html.erb +2 -2
  13. data/app/views/devise/passwords/new.html.erb +1 -1
  14. data/app/views/devise/registrations/edit.html.erb +1 -1
  15. data/app/views/devise/registrations/new.html.erb +1 -1
  16. data/app/views/devise/sessions/new.html.erb +1 -1
  17. data/app/views/devise/shared/_links.erb +6 -0
  18. data/app/views/devise/unlocks/new.html.erb +1 -1
  19. data/config/locales/en.yml +9 -2
  20. data/lib/devise.rb +116 -58
  21. data/lib/devise/controllers/helpers.rb +103 -107
  22. data/lib/devise/controllers/internal_helpers.rb +23 -7
  23. data/lib/devise/controllers/scoped_views.rb +4 -6
  24. data/lib/devise/controllers/url_helpers.rb +3 -5
  25. data/lib/devise/encryptors/base.rb +1 -1
  26. data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
  27. data/lib/devise/failure_app.rb +29 -21
  28. data/lib/devise/hooks/forgetable.rb +2 -1
  29. data/lib/devise/hooks/rememberable.rb +11 -9
  30. data/lib/devise/mapping.rb +12 -5
  31. data/lib/devise/models.rb +0 -14
  32. data/lib/devise/models/authenticatable.rb +40 -30
  33. data/lib/devise/models/confirmable.rb +11 -15
  34. data/lib/devise/models/database_authenticatable.rb +23 -35
  35. data/lib/devise/models/encryptable.rb +65 -0
  36. data/lib/devise/models/lockable.rb +8 -7
  37. data/lib/devise/models/omniauthable.rb +23 -0
  38. data/lib/devise/models/recoverable.rb +5 -3
  39. data/lib/devise/models/registerable.rb +13 -0
  40. data/lib/devise/models/rememberable.rb +38 -30
  41. data/lib/devise/models/timeoutable.rb +20 -3
  42. data/lib/devise/models/token_authenticatable.rb +19 -7
  43. data/lib/devise/models/validatable.rb +16 -4
  44. data/lib/devise/modules.rb +15 -8
  45. data/lib/devise/omniauth.rb +47 -0
  46. data/lib/devise/omniauth/config.rb +30 -0
  47. data/lib/devise/omniauth/test_helpers.rb +57 -0
  48. data/lib/devise/omniauth/url_helpers.rb +29 -0
  49. data/lib/devise/orm/active_record.rb +2 -0
  50. data/lib/devise/orm/mongoid.rb +4 -2
  51. data/lib/devise/rails.rb +26 -46
  52. data/lib/devise/rails/routes.rb +64 -20
  53. data/lib/devise/rails/warden_compat.rb +18 -20
  54. data/lib/devise/schema.rb +13 -14
  55. data/lib/devise/strategies/authenticatable.rb +33 -7
  56. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  57. data/lib/devise/strategies/rememberable.rb +1 -1
  58. data/lib/devise/strategies/token_authenticatable.rb +6 -2
  59. data/lib/devise/test_helpers.rb +11 -1
  60. data/lib/devise/version.rb +1 -1
  61. data/lib/generators/active_record/templates/migration.rb +1 -0
  62. data/lib/generators/devise/orm_helpers.rb +3 -2
  63. data/lib/generators/templates/devise.rb +70 -39
  64. data/test/controllers/helpers_test.rb +43 -67
  65. data/test/controllers/internal_helpers_test.rb +29 -8
  66. data/test/controllers/url_helpers_test.rb +2 -1
  67. data/test/failure_app_test.rb +56 -21
  68. data/test/generators/generators_test_helper.rb +4 -0
  69. data/test/generators/install_generator_test.rb +14 -0
  70. data/test/generators/views_generator_test.rb +37 -0
  71. data/test/integration/authenticatable_test.rb +147 -62
  72. data/test/integration/database_authenticatable_test.rb +22 -0
  73. data/test/integration/http_authenticatable_test.rb +12 -2
  74. data/test/integration/omniauthable_test.rb +107 -0
  75. data/test/integration/recoverable_test.rb +39 -20
  76. data/test/integration/registerable_test.rb +30 -4
  77. data/test/integration/rememberable_test.rb +57 -34
  78. data/test/integration/timeoutable_test.rb +10 -1
  79. data/test/integration/token_authenticatable_test.rb +12 -17
  80. data/test/mailers/confirmation_instructions_test.rb +4 -0
  81. data/test/mailers/reset_password_instructions_test.rb +4 -0
  82. data/test/mailers/unlock_instructions_test.rb +4 -0
  83. data/test/mapping_test.rb +37 -3
  84. data/test/models/confirmable_test.rb +3 -3
  85. data/test/models/database_authenticatable_test.rb +14 -71
  86. data/test/models/encryptable_test.rb +65 -0
  87. data/test/models/lockable_test.rb +17 -1
  88. data/test/models/recoverable_test.rb +17 -0
  89. data/test/models/rememberable_test.rb +186 -125
  90. data/test/models/token_authenticatable_test.rb +1 -13
  91. data/test/models_test.rb +5 -5
  92. data/test/omniauth/url_helpers_test.rb +47 -0
  93. data/test/rails_app/app/active_record/admin.rb +4 -1
  94. data/test/rails_app/app/active_record/user.rb +5 -4
  95. data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
  96. data/test/rails_app/app/controllers/home_controller.rb +9 -0
  97. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
  98. data/test/rails_app/app/mongoid/admin.rb +4 -1
  99. data/test/rails_app/app/mongoid/shim.rb +16 -3
  100. data/test/rails_app/app/mongoid/user.rb +5 -5
  101. data/test/rails_app/config/initializers/devise.rb +52 -28
  102. data/test/rails_app/config/routes.rb +14 -6
  103. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
  104. data/test/rails_app/db/schema.rb +17 -51
  105. data/test/rails_app/lib/shared_admin.rb +9 -0
  106. data/test/rails_app/lib/shared_user.rb +23 -0
  107. data/test/routes_test.rb +42 -9
  108. data/test/support/integration.rb +3 -3
  109. data/test/support/webrat/integrations/rails.rb +7 -0
  110. data/test/test_helper.rb +2 -0
  111. data/test/test_helpers_test.rb +29 -0
  112. metadata +60 -30
  113. data/Gemfile +0 -27
  114. data/Gemfile.lock +0 -115
  115. data/Rakefile +0 -55
  116. data/TODO +0 -3
  117. data/lib/devise/encryptors/bcrypt.rb +0 -19
  118. data/lib/generators/devise_install_generator.rb +0 -4
  119. data/lib/generators/devise_views_generator.rb +0 -4
  120. data/test/indifferent_hash.rb +0 -33
  121. data/test/support/test_silencer.rb +0 -5
@@ -34,16 +34,4 @@ class TokenAuthenticatableTest < ActiveSupport::TestCase
34
34
  assert_nil authenticated_user
35
35
  end
36
36
 
37
- test 'should not be subject to injection' do
38
- user1 = create_user
39
- user1.ensure_authentication_token!
40
- user1.confirm!
41
-
42
- user2 = create_user
43
- user2.ensure_authentication_token!
44
- user2.confirm!
45
-
46
- user = User.find_for_token_authentication(:auth_token => {'$ne' => user1.authentication_token})
47
- assert_nil user
48
- end
49
- end
37
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Configurable < User
4
- devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
4
+ devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable,
5
5
  :stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
6
6
  :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
7
7
  end
@@ -26,16 +26,16 @@ class ActiveRecordTest < ActiveSupport::TestCase
26
26
  end
27
27
 
28
28
  test 'can cherry pick modules' do
29
- assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable
29
+ assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
30
30
  end
31
31
 
32
32
  test 'chosen modules are inheritable' do
33
- assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable
33
+ assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
34
34
  end
35
35
 
36
36
  test 'order of module inclusion' do
37
- correct_module_order = [:database_authenticatable, :recoverable, :registerable, :lockable, :timeoutable]
38
- incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable]
37
+ correct_module_order = [:database_authenticatable, :rememberable, :encryptable, :recoverable, :registerable, :lockable, :timeoutable]
38
+ incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable, :rememberable]
39
39
 
40
40
  assert_include_modules Admin, *incorrect_module_order
41
41
 
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class OmniAuthRoutesTest < ActionController::TestCase
4
+ tests ApplicationController
5
+
6
+ def assert_path(action, provider, with_param=true)
7
+ # Resource param
8
+ assert_equal @controller.send(action, :user, provider),
9
+ @controller.send("user_#{action}", provider)
10
+
11
+ # With an object
12
+ assert_equal @controller.send(action, User.new, provider),
13
+ @controller.send("user_#{action}", provider)
14
+
15
+ if with_param
16
+ # Default url params
17
+ assert_equal @controller.send(action, :user, provider, :param => 123),
18
+ @controller.send("user_#{action}", provider, :param => 123)
19
+ end
20
+ end
21
+
22
+ test 'should alias omniauth_callback to mapped user auth_callback' do
23
+ assert_path :omniauth_callback_path, :facebook
24
+ end
25
+
26
+ test 'should alias omniauth_authorize to mapped user auth_authorize' do
27
+ assert_path :omniauth_authorize_path, :facebook, false
28
+ end
29
+
30
+ test 'should generate authorization path' do
31
+ assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
32
+
33
+ assert_raise ArgumentError do
34
+ @controller.omniauth_authorize_path(:user, :github)
35
+ end
36
+ end
37
+
38
+ test 'should generate authorization path with params' do
39
+ assert_match "/users/auth/open_id?openid_url=http%3A%2F%2Fyahoo.com",
40
+ @controller.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
41
+ end
42
+
43
+ test 'should not add a "?" if no param was sent' do
44
+ assert_equal "/users/auth/open_id",
45
+ @controller.omniauth_authorize_path(:user, :open_id)
46
+ end
47
+ end
@@ -1,3 +1,6 @@
1
+ require 'shared_admin'
2
+
1
3
  class Admin < ActiveRecord::Base
2
- devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
4
+ include Shim
5
+ include SharedAdmin
3
6
  end
@@ -1,7 +1,8 @@
1
+ require 'shared_user'
2
+
1
3
  class User < ActiveRecord::Base
2
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
3
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
4
- :trackable, :validatable
4
+ include Shim
5
+ include SharedUser
5
6
 
6
- attr_accessible :username, :email, :password, :password_confirmation
7
+ attr_accessible :username, :email, :password, :password_confirmation, :remember_me
7
8
  end
@@ -1,4 +1,4 @@
1
- class SessionsController < Devise::SessionsController
1
+ class Admins::SessionsController < Devise::SessionsController
2
2
  def new
3
3
  flash[:special] = "Welcome to #{controller_path.inspect} controller!"
4
4
  super
@@ -4,4 +4,13 @@ class HomeController < ApplicationController
4
4
 
5
5
  def private
6
6
  end
7
+
8
+ def set
9
+ session["devise.foo_bar"] = "something"
10
+ head :ok
11
+ end
12
+
13
+ def unauthenticated
14
+ render :text => "unauthenticated", :status => :unauthorized
15
+ end
7
16
  end
@@ -0,0 +1,7 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ def facebook
3
+ data = env["omniauth.auth"]
4
+ session["devise.facebook_data"] = data["extra"]["user_hash"]
5
+ render :json => data
6
+ end
7
+ end
@@ -1,6 +1,9 @@
1
+ require 'shared_admin'
2
+
1
3
  class Admin
2
4
  include Mongoid::Document
3
5
  include Shim
6
+ include SharedAdmin
4
7
 
5
- devise :database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :unlock_strategy => :time
8
+ field :remember_token, :type => String
6
9
  end
@@ -1,16 +1,29 @@
1
1
  module Shim
2
2
  extend ::ActiveSupport::Concern
3
- include ::Mongoid::Timestamps
3
+
4
+ included do
5
+ include ::Mongoid::Timestamps
6
+ field :created_at, :type => DateTime
7
+ end
4
8
 
5
9
  module ClassMethods
6
10
  def last(options={})
7
11
  options.delete(:order) if options[:order] == "id"
8
12
  super(options)
9
13
  end
14
+
15
+ def find_by_email(email)
16
+ first(:conditions => { :email => email })
17
+ end
10
18
  end
11
-
12
- # overwrite equality (because some devise tests use this for asserting model equality)
19
+
20
+ # overwrite equality (because some devise tests use this for asserting model equality)
13
21
  def ==(other)
14
22
  other.is_a?(self.class) && _id == other._id
15
23
  end
24
+
25
+ # Mongoid does not have this method in the current beta version (2.0.0.beta.20)
26
+ def update_attribute(attribute, value)
27
+ update_attributes(attribute => value)
28
+ end
16
29
  end
@@ -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
@@ -20,15 +20,27 @@ Devise.setup do |config|
20
20
  # authenticating an 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
+
25
34
  # Tell if authentication through request.params is enabled. True by default.
26
35
  # config.params_authenticatable = true
27
36
 
28
- # Tell if authentication through HTTP Basic Auth is enabled. True by default.
37
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
29
38
  config.http_authenticatable = true
30
39
 
31
- # The realm used in Http Basic Authentication
40
+ # If http headers should be returned for AJAX requests. True by default.
41
+ # config.http_authenticatable_on_xhr = true
42
+
43
+ # The realm used in Http Basic Authentication. "Application" by default.
32
44
  # config.http_authentication_realm = "Application"
33
45
 
34
46
  # ==> Configuration for :database_authenticatable
@@ -36,15 +48,6 @@ Devise.setup do |config|
36
48
  # using other encryptors, it sets how many times you want the password re-encrypted.
37
49
  config.stretches = 10
38
50
 
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
51
  # ==> Configuration for :confirmable
49
52
  # The time you want to give your user to confirm his account. During this time
50
53
  # he will be able to access your application without confirming. Default is nil.
@@ -64,8 +67,12 @@ Devise.setup do |config|
64
67
  # If true, extends the user's remember period when remembered via cookie.
65
68
  # config.extend_remember_period = false
66
69
 
70
+ # If true, uses the password salt as remember token. This should be turned
71
+ # to false if you are not using database authenticatable.
72
+ config.use_salt_as_remember_token = true
73
+
67
74
  # ==> Configuration for :validatable
68
- # Range for password length
75
+ # Range for password length. Default is 6..20.
69
76
  # config.password_length = 6..20
70
77
 
71
78
  # Regex to use to validate the email address
@@ -73,8 +80,8 @@ Devise.setup do |config|
73
80
 
74
81
  # ==> Configuration for :timeoutable
75
82
  # 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
83
+ # time the user will be asked for credentials again. Default is 30 minutes.
84
+ # config.timeout_in = 30.minutes
78
85
 
79
86
  # ==> Configuration for :lockable
80
87
  # Defines which strategy will be used to lock an account.
@@ -96,24 +103,39 @@ Devise.setup do |config|
96
103
  # Time interval to unlock the account if :time is enabled as unlock_strategy.
97
104
  # config.unlock_in = 1.hour
98
105
 
106
+ # ==> Configuration for :encryptable
107
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
108
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
109
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
110
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
111
+ # REST_AUTH_SITE_KEY to pepper)
112
+ config.encryptor = :sha512
113
+
114
+ # Setup a pepper to generate the encrypted password.
115
+ config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
116
+
99
117
  # ==> Configuration for :token_authenticatable
100
118
  # Defines name of the authentication token params key
101
119
  # config.token_authentication_key = :auth_token
102
120
 
121
+ # If true, authentication through token does not store user in session and needs
122
+ # to be supplied on each request. Useful if you are using the token as API token.
123
+ # config.stateless_token = false
124
+
103
125
  # ==> Scopes configuration
104
126
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
105
127
  # "users/sessions/new". It's turned off by default because it's slower if you
106
128
  # are using only default views.
107
- # config.scoped_views = true
129
+ # config.scoped_views = false
108
130
 
109
131
  # Configure the default scope given to Warden. By default it's the first
110
- # devise role declared in your routes.
132
+ # devise role declared in your routes (usually :user).
111
133
  # config.default_scope = :user
112
134
 
113
135
  # 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
136
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
137
+ # The default is true, which means any logout action will sign out all active scopes.
138
+ # config.sign_out_all_scopes = true
117
139
 
118
140
  # ==> Navigation configuration
119
141
  # Lists the formats that should be treated as navigational. Formats like
@@ -123,17 +145,19 @@ Devise.setup do |config|
123
145
  # should add them to the navigational formats lists. Default is [:html]
124
146
  # config.navigational_formats = [:html, :iphone]
125
147
 
148
+ # The default HTTP method used to sign out a resource. Default is :get.
149
+ # config.sign_out_via = :get
150
+
151
+ # ==> OmniAuth
152
+ config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access'
153
+ config.omniauth :open_id
154
+
126
155
  # ==> 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
156
+ # If you want to use other strategies, that are not supported by Devise, or
157
+ # change the failure app, you can configure them inside the config.warden block.
130
158
  #
131
159
  # 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
160
+ # manager.failure_app = AnotherApp
161
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
138
162
  # end
139
163
  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
@@ -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