rodauth 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +146 -0
  3. data/README.rdoc +644 -220
  4. data/Rakefile +99 -11
  5. data/doc/account_expiration.rdoc +55 -0
  6. data/doc/base.rdoc +104 -0
  7. data/doc/change_login.rdoc +29 -0
  8. data/doc/change_password.rdoc +26 -0
  9. data/doc/close_account.rdoc +31 -0
  10. data/doc/confirm_password.rdoc +22 -0
  11. data/doc/create_account.rdoc +34 -0
  12. data/doc/disallow_password_reuse.rdoc +37 -0
  13. data/doc/email_base.rdoc +19 -0
  14. data/doc/jwt.rdoc +35 -0
  15. data/doc/lockout.rdoc +83 -0
  16. data/doc/login.rdoc +27 -0
  17. data/doc/login_password_requirements_base.rdoc +50 -0
  18. data/doc/logout.rdoc +21 -0
  19. data/doc/otp.rdoc +100 -0
  20. data/doc/password_complexity.rdoc +50 -0
  21. data/doc/password_expiration.rdoc +52 -0
  22. data/doc/password_grace_period.rdoc +10 -0
  23. data/doc/recovery_codes.rdoc +60 -0
  24. data/doc/release_notes/1.0.0.txt +443 -0
  25. data/doc/remember.rdoc +82 -0
  26. data/doc/reset_password.rdoc +70 -0
  27. data/doc/session_expiration.rdoc +27 -0
  28. data/doc/single_session.rdoc +43 -0
  29. data/doc/sms_codes.rdoc +119 -0
  30. data/doc/two_factor_base.rdoc +27 -0
  31. data/doc/verify_account.rdoc +70 -0
  32. data/doc/verify_account_grace_period.rdoc +15 -0
  33. data/doc/verify_change_login.rdoc +9 -0
  34. data/lib/roda/plugins/rodauth.rb +3 -262
  35. data/lib/rodauth.rb +260 -0
  36. data/lib/rodauth/features/account_expiration.rb +108 -0
  37. data/lib/rodauth/features/base.rb +479 -0
  38. data/lib/rodauth/features/change_login.rb +77 -0
  39. data/lib/rodauth/features/change_password.rb +66 -0
  40. data/lib/rodauth/features/close_account.rb +82 -0
  41. data/lib/rodauth/features/confirm_password.rb +51 -0
  42. data/lib/rodauth/features/create_account.rb +128 -0
  43. data/lib/rodauth/features/disallow_password_reuse.rb +82 -0
  44. data/lib/rodauth/features/email_base.rb +63 -0
  45. data/lib/rodauth/features/jwt.rb +151 -0
  46. data/lib/rodauth/features/lockout.rb +262 -0
  47. data/lib/rodauth/features/login.rb +61 -0
  48. data/lib/rodauth/features/login_password_requirements_base.rb +123 -0
  49. data/lib/rodauth/features/logout.rb +37 -0
  50. data/lib/rodauth/features/otp.rb +338 -0
  51. data/lib/rodauth/features/password_complexity.rb +89 -0
  52. data/lib/rodauth/features/password_expiration.rb +111 -0
  53. data/lib/rodauth/features/password_grace_period.rb +46 -0
  54. data/lib/rodauth/features/recovery_codes.rb +240 -0
  55. data/lib/rodauth/features/remember.rb +200 -0
  56. data/lib/rodauth/features/reset_password.rb +207 -0
  57. data/lib/rodauth/features/session_expiration.rb +55 -0
  58. data/lib/rodauth/features/single_session.rb +87 -0
  59. data/lib/rodauth/features/sms_codes.rb +498 -0
  60. data/lib/rodauth/features/two_factor_base.rb +135 -0
  61. data/lib/rodauth/features/verify_account.rb +232 -0
  62. data/lib/rodauth/features/verify_account_grace_period.rb +76 -0
  63. data/lib/rodauth/features/verify_change_login.rb +20 -0
  64. data/lib/rodauth/migrations.rb +130 -0
  65. data/lib/rodauth/version.rb +9 -0
  66. data/spec/account_expiration_spec.rb +90 -0
  67. data/spec/all.rb +1 -0
  68. data/spec/change_login_spec.rb +149 -0
  69. data/spec/change_password_spec.rb +177 -0
  70. data/spec/close_account_spec.rb +162 -0
  71. data/spec/confirm_password_spec.rb +70 -0
  72. data/spec/create_account_spec.rb +127 -0
  73. data/spec/disallow_password_reuse_spec.rb +84 -0
  74. data/spec/lockout_spec.rb +228 -0
  75. data/spec/login_spec.rb +188 -0
  76. data/spec/migrate/001_tables.rb +103 -16
  77. data/spec/migrate/002_account_password_hash_column.rb +11 -0
  78. data/spec/migrate_password/001_tables.rb +60 -42
  79. data/spec/migrate_travis/001_tables.rb +116 -0
  80. data/spec/password_complexity_spec.rb +108 -0
  81. data/spec/password_expiration_spec.rb +243 -0
  82. data/spec/password_grace_period_spec.rb +93 -0
  83. data/spec/remember_spec.rb +424 -0
  84. data/spec/reset_password_spec.rb +185 -0
  85. data/spec/rodauth_spec.rb +57 -980
  86. data/spec/session_expiration_spec.rb +58 -0
  87. data/spec/single_session_spec.rb +107 -0
  88. data/spec/spec_helper.rb +202 -0
  89. data/spec/two_factor_spec.rb +1310 -0
  90. data/spec/verify_account_grace_period_spec.rb +135 -0
  91. data/spec/verify_account_spec.rb +142 -0
  92. data/spec/verify_change_login_spec.rb +46 -0
  93. data/spec/views/login.str +2 -2
  94. data/templates/add-recovery-codes.str +2 -0
  95. data/templates/button.str +5 -0
  96. data/templates/change-login.str +5 -18
  97. data/templates/change-password.str +6 -14
  98. data/templates/close-account.str +3 -6
  99. data/templates/confirm-password.str +4 -14
  100. data/templates/create-account.str +6 -30
  101. data/templates/login-confirm-field.str +6 -0
  102. data/templates/login-field.str +6 -0
  103. data/templates/login.str +5 -19
  104. data/templates/logout.str +2 -6
  105. data/templates/otp-auth-code-field.str +6 -0
  106. data/templates/otp-auth.str +8 -0
  107. data/templates/otp-disable.str +6 -0
  108. data/templates/otp-setup.str +21 -0
  109. data/templates/password-confirm-field.str +6 -0
  110. data/templates/password-field.str +6 -0
  111. data/templates/recovery-auth.str +12 -0
  112. data/templates/recovery-codes.str +6 -0
  113. data/templates/remember.str +8 -12
  114. data/templates/reset-password-request.str +2 -2
  115. data/templates/reset-password.str +4 -18
  116. data/templates/sms-auth.str +6 -0
  117. data/templates/sms-code-field.str +6 -0
  118. data/templates/sms-confirm.str +7 -0
  119. data/templates/sms-disable.str +7 -0
  120. data/templates/sms-request.str +5 -0
  121. data/templates/sms-setup.str +12 -0
  122. data/templates/unlock-account-request.str +3 -7
  123. data/templates/unlock-account.str +4 -7
  124. data/templates/verify-account-resend.str +2 -2
  125. data/templates/verify-account.str +2 -6
  126. metadata +191 -29
  127. data/lib/roda/plugins/rodauth/base.rb +0 -428
  128. data/lib/roda/plugins/rodauth/change_login.rb +0 -48
  129. data/lib/roda/plugins/rodauth/change_password.rb +0 -42
  130. data/lib/roda/plugins/rodauth/close_account.rb +0 -42
  131. data/lib/roda/plugins/rodauth/create_account.rb +0 -92
  132. data/lib/roda/plugins/rodauth/lockout.rb +0 -292
  133. data/lib/roda/plugins/rodauth/login.rb +0 -81
  134. data/lib/roda/plugins/rodauth/logout.rb +0 -36
  135. data/lib/roda/plugins/rodauth/remember.rb +0 -226
  136. data/lib/roda/plugins/rodauth/reset_password.rb +0 -205
  137. data/lib/roda/plugins/rodauth/verify_account.rb +0 -228
@@ -0,0 +1,185 @@
1
+ require File.expand_path("spec_helper", File.dirname(__FILE__))
2
+
3
+ describe 'Rodauth reset_password feature' do
4
+ it "should support resetting passwords for accounts" do
5
+ rodauth do
6
+ enable :login, :reset_password
7
+ end
8
+ roda do |r|
9
+ r.rodauth
10
+ r.root{view :content=>""}
11
+ end
12
+
13
+ login(:login=>'foo@example2.com', :pass=>'01234567')
14
+ page.html.wont_match(/notice_flash/)
15
+
16
+ login(:pass=>'01234567', :visit=>false)
17
+
18
+ click_button 'Request Password Reset'
19
+ page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to reset the password for your account"
20
+ page.current_path.must_equal '/'
21
+
22
+ link = email_link(/(\/reset-password\?key=.+)$/)
23
+ visit link[0...-1]
24
+ page.find('#error_flash').text.must_equal "invalid password reset key"
25
+
26
+ visit link
27
+ page.title.must_equal 'Reset Password'
28
+
29
+ fill_in 'Password', :with=>'0123456'
30
+ fill_in 'Confirm Password', :with=>'0123456789'
31
+ click_button 'Reset Password'
32
+ page.html.must_include("passwords do not match")
33
+ page.find('#error_flash').text.must_equal "There was an error resetting your password"
34
+ page.current_path.must_equal '/reset-password'
35
+
36
+ fill_in 'Password', :with=>'0123456789'
37
+ fill_in 'Confirm Password', :with=>'0123456789'
38
+ click_button 'Reset Password'
39
+ page.body.must_include 'invalid password, same as current password'
40
+ page.find('#error_flash').text.must_equal "There was an error resetting your password"
41
+ page.current_path.must_equal '/reset-password'
42
+
43
+ fill_in 'Password', :with=>'012'
44
+ fill_in 'Confirm Password', :with=>'012'
45
+ click_button 'Reset Password'
46
+ page.html.must_include("invalid password, does not meet requirements")
47
+ page.find('#error_flash').text.must_equal "There was an error resetting your password"
48
+ page.current_path.must_equal '/reset-password'
49
+
50
+ fill_in 'Password', :with=>'0123456'
51
+ fill_in 'Confirm Password', :with=>'0123456'
52
+ click_button 'Reset Password'
53
+ page.find('#notice_flash').text.must_equal "Your password has been reset"
54
+ page.current_path.must_equal '/'
55
+
56
+ login(:pass=>'0123456')
57
+ page.current_path.must_equal '/'
58
+ end
59
+
60
+ it "should support resetting passwords for accounts without confirmation" do
61
+ rodauth do
62
+ enable :login, :reset_password
63
+ require_password_confirmation? false
64
+ end
65
+ roda do |r|
66
+ r.rodauth
67
+ r.root{view :content=>""}
68
+ end
69
+
70
+ visit '/login'
71
+ login(:pass=>'01234567', :visit=>false)
72
+ click_button 'Request Password Reset'
73
+ page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to reset the password for your account"
74
+
75
+ link = email_link(/(\/reset-password\?key=.+)$/)
76
+ visit link
77
+ fill_in 'Password', :with=>'0123456'
78
+ click_button 'Reset Password'
79
+ page.find('#notice_flash').text.must_equal "Your password has been reset"
80
+ end
81
+
82
+ it "should support autologin when resetting passwords for accounts" do
83
+ rodauth do
84
+ enable :login, :reset_password
85
+ reset_password_autologin? true
86
+ end
87
+ roda do |r|
88
+ r.rodauth
89
+ r.root{view :content=>rodauth.logged_in? ? "Logged In" : "Not Logged"}
90
+ end
91
+
92
+ login(:pass=>'01234567')
93
+
94
+ click_button 'Request Password Reset'
95
+ link = email_link(/(\/reset-password\?key=.+)$/)
96
+ visit link
97
+ fill_in 'Password', :with=>'0123456'
98
+ fill_in 'Confirm Password', :with=>'0123456'
99
+ click_button 'Reset Password'
100
+ page.find('#notice_flash').text.must_equal "Your password has been reset"
101
+ page.body.must_include("Logged In")
102
+ end
103
+
104
+ it "should clear reset password token when closing account" do
105
+ rodauth do
106
+ enable :login, :reset_password, :close_account
107
+ reset_password_autologin? true
108
+ end
109
+ roda do |r|
110
+ r.rodauth
111
+ r.root{view :content=>rodauth.logged_in? ? "Logged In" : "Not Logged"}
112
+ end
113
+
114
+ login(:pass=>'01234567')
115
+ click_button 'Request Password Reset'
116
+ link = email_link(/(\/reset-password\?key=.+)$/)
117
+
118
+ login
119
+
120
+ DB[:account_password_reset_keys].count.must_equal 1
121
+ visit '/close-account'
122
+ fill_in 'Password', :with=>'0123456789'
123
+ click_button 'Close Account'
124
+ DB[:account_password_reset_keys].count.must_equal 0
125
+ end
126
+
127
+ it "should handle uniqueness errors raised when inserting password reset token" do
128
+ rodauth do
129
+ enable :login, :reset_password
130
+ end
131
+ roda do |r|
132
+ def rodauth.raised_uniqueness_violation(*) super; true; end
133
+ r.rodauth
134
+ r.root{view :content=>""}
135
+ end
136
+
137
+ login(:pass=>'01234567')
138
+
139
+ click_button 'Request Password Reset'
140
+ link = email_link(/(\/reset-password\?key=.+)$/)
141
+ visit link
142
+
143
+ fill_in 'Password', :with=>'0123456'
144
+ fill_in 'Confirm Password', :with=>'0123456'
145
+ click_button 'Reset Password'
146
+ page.find('#notice_flash').text.must_equal "Your password has been reset"
147
+ end
148
+
149
+ it "should support resetting passwords for accounts via jwt" do
150
+ rodauth do
151
+ enable :login, :reset_password
152
+ reset_password_email_body{reset_password_email_link}
153
+ end
154
+ roda(:jwt) do |r|
155
+ r.rodauth
156
+ end
157
+
158
+ res = json_request('/reset-password')
159
+ res.must_equal [400, {"error"=>"There was an error resetting your password"}]
160
+
161
+ res = json_request('/reset-password-request', :login=>'foo@example2.com')
162
+ res.must_equal [400, {"error"=>"There was an error requesting a password reset"}]
163
+
164
+ res = json_request('/reset-password-request', :login=>'foo@example.com')
165
+ res.must_equal [200, {"success"=>"An email has been sent to you with a link to reset the password for your account"}]
166
+
167
+ link = email_link(/key=.+$/)
168
+ res = json_request('/reset-password', :key=>link[4...-1])
169
+ res.must_equal [400, {"error"=>"There was an error resetting your password"}]
170
+
171
+ res = json_request('/reset-password', :key=>link[4..-1], :password=>'1', "password-confirm"=>'2')
172
+ res.must_equal [400, {"error"=>"There was an error resetting your password", "field-error"=>["password", 'passwords do not match']}]
173
+
174
+ res = json_request('/reset-password', :key=>link[4..-1], :password=>'0123456789', "password-confirm"=>'0123456789')
175
+ res.must_equal [400, {"error"=>"There was an error resetting your password", "field-error"=>["password", 'invalid password, same as current password']}]
176
+
177
+ res = json_request('/reset-password', :key=>link[4..-1], :password=>'1', "password-confirm"=>'1')
178
+ res.must_equal [400, {"error"=>"There was an error resetting your password", "field-error"=>["password", "invalid password, does not meet requirements (minimum 6 characters)"]}]
179
+
180
+ res = json_request('/reset-password', :key=>link[4..-1], :password=>'0123456', "password-confirm"=>'0123456')
181
+ res.must_equal [200, {"success"=>"Your password has been reset"}]
182
+
183
+ json_login(:pass=>'0123456')
184
+ end
185
+ end
@@ -1,573 +1,15 @@
1
- $: << 'lib'
2
-
3
- if ENV['COVERAGE']
4
- require 'coverage'
5
- require 'simplecov'
6
-
7
- def SimpleCov.rodauth_coverage(opts = {})
8
- start do
9
- add_filter "/spec/"
10
- add_group('Missing'){|src| src.covered_percent < 100}
11
- add_group('Covered'){|src| src.covered_percent == 100}
12
- yield self if block_given?
13
- end
14
- end
15
-
16
- ENV.delete('COVERAGE')
17
- SimpleCov.rodauth_coverage
18
- end
19
-
20
- require 'rubygems'
21
- require 'capybara'
22
- require 'capybara/dsl'
23
- require 'rack/test'
24
- gem 'minitest'
25
- require 'minitest/autorun'
26
- require 'minitest/hooks/default'
27
-
28
- require 'roda'
29
- require 'sequel'
30
- require 'bcrypt'
31
- require 'mail'
32
- require 'logger'
33
- require 'tilt/string'
34
-
35
- DB = Sequel.postgres(:user=>'rodauth_test', :password=>'rodauth_test')
36
- #DB.loggers << Logger.new($stdout)
37
-
38
- ENV['RACK_ENV'] = 'test'
39
-
40
- ::Mail.defaults do
41
- delivery_method :test
42
- end
43
-
44
- class Account < Sequel::Model
45
- plugin :validation_helpers
46
-
47
- def validate
48
- super
49
- validates_unique(:email){|ds| ds.where(:status_id=>[1,2])} unless status_id == 3
50
- end
51
- end
52
-
53
- Base = Class.new(Roda)
54
- Base.plugin :render, :layout=>{:path=>'spec/views/layout.str'}
55
- Base.plugin(:not_found){raise "path #{request.path_info} not found"}
56
- Base.use Rack::Session::Cookie, :secret=>'0123456789'
57
- class Base
58
- attr_writer :title
59
- end
60
-
61
- class Minitest::HooksSpec
62
- include Rack::Test::Methods
63
- include Capybara::DSL
64
-
65
- attr_reader :app
66
-
67
- def no_freeze!
68
- @no_freeze = true
69
- end
70
-
71
- def app=(app)
72
- @app = Capybara.app = app
73
- end
74
-
75
- def rodauth(&block)
76
- @rodauth_block = block
77
- end
78
-
79
- def roda(&block)
80
- app = Class.new(Base)
81
- rodauth_block = @rodauth_block
82
- app.plugin(:rodauth) do
83
- title_instance_variable :@title
84
- instance_exec(&rodauth_block)
85
- end
86
- app.route(&block)
87
- app.freeze unless @no_freeze
88
- self.app = app
89
- end
90
-
91
- def email_link(regexp)
92
- link = Mail::TestMailer.deliveries.first.body.to_s[regexp]
93
- Mail::TestMailer.deliveries.clear
94
- link.must_be_kind_of(String)
95
- link
96
- end
97
-
98
- def remove_cookie(key)
99
- page.driver.browser.rack_mock_session.cookie_jar.delete(key)
100
- end
101
-
102
- def get_cookie(key)
103
- page.driver.browser.rack_mock_session.cookie_jar[key]
104
- end
105
-
106
- def set_cookie(key, value)
107
- page.driver.browser.rack_mock_session.cookie_jar[key] = value
108
- end
109
-
110
- around do |&block|
111
- DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true){super(&block)}
112
- end
113
-
114
- around(:all) do |&block|
115
- DB.transaction(:rollback=>:always){super(&block)}
116
- end
117
-
118
- after do
119
- Capybara.reset_sessions!
120
- Capybara.use_default_driver
121
- end
122
- end
1
+ require File.expand_path("spec_helper", File.dirname(__FILE__))
123
2
 
124
3
  describe 'Rodauth' do
125
- before(:all) do
126
- hash = BCrypt::Password.create('0123456789', :cost=>BCrypt::Engine::MIN_COST)
127
- DB[:account_password_hashes].insert(:id=>Account.create(:email=>'foo@example.com', :status_id=>2, :ph=>hash).id, :password_hash=>hash)
128
- end
129
-
130
- it "should handle logins and logouts" do
131
- rodauth{enable :login, :logout}
132
- roda do |r|
133
- r.rodauth
134
- next unless session[:account_id]
135
- r.root{view :content=>"Logged In"}
136
- end
137
-
138
- visit '/login'
139
- page.title.must_equal 'Login'
140
-
141
- fill_in 'Login', :with=>'foo@example2.com'
142
- fill_in 'Password', :with=>'0123456789'
143
- click_button 'Login'
144
- page.find('#error_flash').text.must_equal 'There was an error logging in'
145
- page.html.must_match(/no matching login/)
146
-
147
- fill_in 'Login', :with=>'foo@example.com'
148
- fill_in 'Password', :with=>'012345678'
149
- click_button 'Login'
150
- page.find('#error_flash').text.must_equal 'There was an error logging in'
151
- page.html.must_match(/invalid password/)
152
-
153
- fill_in 'Password', :with=>'0123456789'
154
- click_button 'Login'
155
- page.current_path.must_equal '/'
156
- page.find('#notice_flash').text.must_equal 'You have been logged in'
157
- page.html.must_match(/Logged In/)
158
-
159
- visit '/logout'
160
- page.title.must_equal 'Logout'
161
-
162
- click_button 'Logout'
163
- page.find('#notice_flash').text.must_equal 'You have been logged out'
164
- page.current_path.must_equal '/login'
165
- end
166
-
167
- it "should not allow login to unverified account" do
168
- rodauth{enable :login}
169
- roda do |r|
170
- r.rodauth
171
- next unless session[:account_id]
172
- r.root{view :content=>"Logged In"}
173
- end
174
-
175
- visit '/login'
176
- page.title.must_equal 'Login'
177
-
178
- Account.first.update(:status_id=>1)
179
- fill_in 'Login', :with=>'foo@example.com'
180
- fill_in 'Password', :with=>'0123456789'
181
- click_button 'Login'
182
- page.find('#error_flash').text.must_equal 'There was an error logging in'
183
- page.html.must_match(/unverified account, please verify account before logging in/)
184
- end
185
-
186
- it "should handle overriding login action" do
187
- rodauth do
188
- enable :login
189
- login_post_block do |r, _|
190
- if r['login'] == 'apple' && r['password'] == 'banana'
191
- session[:user_id] = 'pear'
192
- r.redirect '/'
193
- end
194
- r.redirect '/login'
195
- end
196
- end
197
- roda do |r|
198
- r.rodauth
199
- next unless session[:user_id] == 'pear'
200
- r.root{"Logged In"}
201
- end
202
-
203
- visit '/login'
204
-
205
- fill_in 'Login', :with=>'appl'
206
- fill_in 'Password', :with=>'banana'
207
- click_button 'Login'
208
- page.html.wont_match(/Logged In/)
209
-
210
- fill_in 'Login', :with=>'apple'
211
- fill_in 'Password', :with=>'banan'
212
- click_button 'Login'
213
- page.html.wont_match(/Logged In/)
214
-
215
- fill_in 'Login', :with=>'apple'
216
- fill_in 'Password', :with=>'banana'
217
- click_button 'Login'
218
- page.current_path.must_equal '/'
219
- page.html.must_match(/Logged In/)
220
- end
221
-
222
- it "should handle overriding some login attributes" do
223
- rodauth do
224
- enable :login
225
- account_from_login do |login|
226
- Account.first if login == 'apple'
227
- end
228
- password_match? do |password|
229
- password == 'banana'
230
- end
231
- update_session do
232
- session[:user_id] = 'pear'
233
- end
234
- no_matching_login_message "no user"
235
- invalid_password_message "bad password"
236
- end
237
- roda do |r|
238
- r.rodauth
239
- next unless session[:user_id] == 'pear'
240
- r.root{"Logged In"}
241
- end
242
-
243
- visit '/login'
244
-
245
- fill_in 'Login', :with=>'appl'
246
- fill_in 'Password', :with=>'banana'
247
- click_button 'Login'
248
- page.html.must_match(/no user/)
249
-
250
- fill_in 'Login', :with=>'apple'
251
- fill_in 'Password', :with=>'banan'
252
- click_button 'Login'
253
- page.html.must_match(/bad password/)
254
-
255
- fill_in 'Password', :with=>'banana'
256
- click_button 'Login'
257
- page.current_path.must_equal '/'
258
- page.html.must_match(/Logged In/)
259
- end
260
-
261
- it "should handle a prefix and some other login options" do
262
- rodauth do
263
- enable :login, :logout
264
- prefix 'auth'
265
- session_key :login_email
266
- account_from_session{Account.first(:email=>session_value)}
267
- account_session_value{account.email}
268
- login_param{request['lp']}
269
- password_param 'p'
270
- login_redirect{"/foo/#{account.email}"}
271
- logout_redirect '/auth/lin'
272
- login_route 'lin'
273
- logout_route 'lout'
274
- end
275
- no_freeze!
276
- roda do |r|
277
- r.on 'auth' do
278
- r.rodauth
279
- end
280
- next unless session[:login_email] =~ /example/
281
- r.get('foo/:email'){|e| "Logged In: #{e}"}
282
- end
283
- app.plugin :render, :views=>'spec/views', :engine=>'str'
284
-
285
- visit '/auth/lin?lp=l'
286
-
287
- fill_in 'Login', :with=>'foo@example2.com'
288
- fill_in 'Password', :with=>'0123456789'
289
- click_button 'Login'
290
- page.html.must_match(/no matching login/)
291
-
292
- fill_in 'Login', :with=>'foo@example.com'
293
- fill_in 'Password', :with=>'012345678'
294
- click_button 'Login'
295
- page.html.must_match(/invalid password/)
296
-
297
- fill_in 'Login', :with=>'foo@example.com'
298
- fill_in 'Password', :with=>'0123456789'
299
- click_button 'Login'
300
- page.current_path.must_equal '/foo/foo@example.com'
301
- page.html.must_match(/Logged In: foo@example\.com/)
302
-
303
- visit '/auth/lout'
304
- click_button 'Logout'
305
- page.current_path.must_equal '/auth/lin'
306
- end
307
-
308
- it "should support closing accounts" do
309
- rodauth do
310
- enable :login, :close_account
311
- end
312
- roda do |r|
313
- r.rodauth
314
- r.root{""}
315
- end
316
-
317
- visit '/login'
318
- fill_in 'Login', :with=>'foo@example.com'
319
- fill_in 'Password', :with=>'0123456789'
320
- click_button 'Login'
321
- page.current_path.must_equal '/'
322
-
323
- visit '/close-account'
324
- click_button 'Close Account'
325
- page.current_path.must_equal '/'
326
-
327
- Account.select_map(:status_id).must_equal [3]
328
- end
329
-
330
- it "should support closing accounts with overrides" do
331
- rodauth do
332
- enable :login, :close_account
333
- close_account do
334
- account.email = 'foo@bar.com'
335
- super()
336
- end
337
- close_account_route 'close'
338
- close_account_redirect '/login'
339
- end
340
- roda do |r|
341
- r.rodauth
342
- r.root{""}
343
- end
344
-
345
- visit '/login'
346
- fill_in 'Login', :with=>'foo@example.com'
347
- fill_in 'Password', :with=>'0123456789'
348
- click_button 'Login'
349
- page.current_path.must_equal '/'
350
-
351
- visit '/close'
352
- page.title.must_equal 'Close Account'
353
- click_button 'Close Account'
354
- page.find('#notice_flash').text.must_equal "Your account has been closed"
355
- page.current_path.must_equal '/login'
356
-
357
- Account.select_map(:status_id).must_equal [3]
358
- Account.select_map(:email).must_equal ['foo@bar.com']
359
- end
360
-
361
- [false, true].each do |ph|
362
- it "should support creating accounts #{'with account_password_hash_column' if ph}" do
363
- rodauth do
364
- enable :login, :create_account
365
- account_password_hash_column :ph if ph
366
- end
367
- roda do |r|
368
- r.rodauth
369
- r.root{view :content=>""}
370
- end
371
-
372
- visit '/create-account'
373
- fill_in 'Login', :with=>'foo@example.com'
374
- fill_in 'Confirm Login', :with=>'foo@example.com'
375
- fill_in 'Password', :with=>'0123456789'
376
- fill_in 'Confirm Password', :with=>'0123456789'
377
- click_button 'Create Account'
378
- page.html.must_match(/is already taken/)
379
- page.find('#error_flash').text.must_equal "There was an error creating your account"
380
- page.current_path.must_equal '/create-account'
381
-
382
- fill_in 'Login', :with=>'foo@example2.com'
383
- fill_in 'Password', :with=>'0123456789'
384
- fill_in 'Confirm Password', :with=>'0123456789'
385
- click_button 'Create Account'
386
- page.html.must_match(/logins do not match/)
387
- page.find('#error_flash').text.must_equal "There was an error creating your account"
388
- page.current_path.must_equal '/create-account'
389
-
390
- fill_in 'Confirm Login', :with=>'foo@example2.com'
391
- fill_in 'Password', :with=>'0123456789'
392
- fill_in 'Confirm Password', :with=>'012345678'
393
- click_button 'Create Account'
394
- page.html.must_match(/passwords do not match/)
395
- page.find('#error_flash').text.must_equal "There was an error creating your account"
396
- page.current_path.must_equal '/create-account'
397
-
398
- fill_in 'Password', :with=>'0123456789'
399
- fill_in 'Confirm Password', :with=>'0123456789'
400
- click_button 'Create Account'
401
- page.find('#notice_flash').text.must_equal "Your account has been created"
402
- page.current_path.must_equal '/'
403
-
404
- visit '/login'
405
- fill_in 'Login', :with=>'foo@example2.com'
406
- fill_in 'Password', :with=>'0123456789'
407
- click_button 'Login'
408
- page.current_path.must_equal '/'
409
- end
410
-
411
- it "should support changing passwords for accounts #{'with account_password_hash_column' if ph}" do
412
- rodauth do
413
- enable :login, :logout, :change_password
414
- account_password_hash_column :ph if ph
415
- end
416
- roda do |r|
417
- r.rodauth
418
- r.root{view :content=>""}
419
- end
420
-
421
- visit '/login'
422
- fill_in 'Login', :with=>'foo@example.com'
423
- fill_in 'Password', :with=>'0123456789'
424
- click_button 'Login'
425
- page.current_path.must_equal '/'
426
-
427
- visit '/change-password'
428
- page.title.must_equal 'Change Password'
429
-
430
- fill_in 'Password', :with=>'0123456'
431
- fill_in 'Confirm Password', :with=>'0123456789'
432
- click_button 'Change Password'
433
- page.html.must_match(/passwords do not match/)
434
- page.find('#error_flash').text.must_equal "There was an error changing your password"
435
- page.current_path.must_equal '/change-password'
436
-
437
- fill_in 'Password', :with=>'0123456'
438
- fill_in 'Confirm Password', :with=>'0123456'
439
- click_button 'Change Password'
440
- page.find('#notice_flash').text.must_equal "Your password has been changed"
441
- page.current_path.must_equal '/'
442
-
443
- visit '/logout'
444
- click_button 'Logout'
445
-
446
- visit '/login'
447
- fill_in 'Login', :with=>'foo@example.com'
448
- fill_in 'Password', :with=>'0123456789'
449
- click_button 'Login'
450
- page.html.must_match(/invalid password/)
451
- page.current_path.must_equal '/login'
452
-
453
- fill_in 'Password', :with=>'0123456'
454
- click_button 'Login'
455
- page.current_path.must_equal '/'
456
- end
457
- end
458
-
459
- it "should support changing logins for accounts" do
460
- Account.create(:email=>'foo2@example.com')
461
-
462
- rodauth do
463
- enable :login, :logout, :change_login
464
- end
465
- roda do |r|
466
- r.rodauth
467
- r.root{view :content=>""}
468
- end
469
-
470
- visit '/login'
471
- fill_in 'Login', :with=>'foo@example.com'
472
- fill_in 'Password', :with=>'0123456789'
473
- click_button 'Login'
474
- page.current_path.must_equal '/'
475
-
476
- visit '/change-login'
477
- page.title.must_equal 'Change Login'
478
-
479
- fill_in 'Login', :with=>'foo@example.com'
480
- fill_in 'Confirm Login', :with=>'foo2@example.com'
481
- click_button 'Change Login'
482
- page.find('#error_flash').text.must_equal "There was an error changing your login"
483
- page.html.must_match(/logins do not match/)
484
- page.current_path.must_equal '/change-login'
485
-
486
- fill_in 'Login', :with=>'foo2@example.com'
487
- click_button 'Change Login'
488
- page.find('#error_flash').text.must_equal "There was an error changing your login"
489
- page.html.must_match(/is already taken/)
490
- page.current_path.must_equal '/change-login'
491
-
492
- fill_in 'Login', :with=>'foo3@example.com'
493
- fill_in 'Confirm Login', :with=>'foo3@example.com'
494
- click_button 'Change Login'
495
- page.find('#notice_flash').text.must_equal "Your login has been changed"
496
- page.current_path.must_equal '/'
497
-
498
- visit '/logout'
499
- click_button 'Logout'
500
-
501
- visit '/login'
502
- fill_in 'Login', :with=>'foo3@example.com'
503
- fill_in 'Password', :with=>'0123456789'
504
- click_button 'Login'
505
- page.current_path.must_equal '/'
506
- end
507
-
508
- it "should support setting requirements for passwords" do
509
- rodauth do
510
- enable :login, :create_account, :change_password
511
- password_meets_requirements? do |password|
512
- password =~ /banana/
513
- end
514
- end
515
- roda do |r|
516
- r.rodauth
517
- r.root{view :content=>""}
518
- end
519
-
520
- visit '/create-account'
521
- fill_in 'Login', :with=>'foo2@example.com'
522
- fill_in 'Confirm Login', :with=>'foo2@example.com'
523
- fill_in 'Password', :with=>'apple'
524
- fill_in 'Confirm Password', :with=>'apple'
525
- click_button 'Create Account'
526
- page.html.must_match(/invalid password, does not meet requirements/)
527
- page.find('#error_flash').text.must_equal "There was an error creating your account"
528
- page.current_path.must_equal '/create-account'
529
-
530
- fill_in 'Password', :with=>'banana'
531
- fill_in 'Confirm Password', :with=>'banana'
532
- click_button 'Create Account'
533
-
534
- visit '/login'
535
- fill_in 'Login', :with=>'foo2@example.com'
536
- fill_in 'Password', :with=>'banana'
537
- click_button 'Login'
538
-
539
- visit '/change-password'
540
- fill_in 'Password', :with=>'apple'
541
- fill_in 'Confirm Password', :with=>'apple'
542
- click_button 'Change Password'
543
- page.html.must_match(/invalid password, does not meet requirements/)
544
- page.find('#error_flash').text.must_equal "There was an error changing your password"
545
- page.current_path.must_equal '/change-password'
546
-
547
- fill_in 'Password', :with=>'my_banana_3'
548
- fill_in 'Confirm Password', :with=>'my_banana_3'
549
- click_button 'Change Password'
550
- page.current_path.must_equal '/'
551
- end
552
-
553
- it "should support autologin after account creation" do
4
+ it "should keep private methods private when overridden" do
554
5
  rodauth do
555
- enable :login, :create_account
556
- create_account_autologin? true
6
+ use_database_authentication_functions? false
557
7
  end
558
8
  roda do |r|
559
- r.rodauth
560
- next unless session[:account_id]
561
- r.root{view :content=>"Logged In: #{Account[session[:account_id]].email}"}
9
+ rodauth.use_database_authentication_functions?.to_s
562
10
  end
563
11
 
564
- visit '/create-account'
565
- fill_in 'Login', :with=>'foo2@example.com'
566
- fill_in 'Confirm Login', :with=>'foo2@example.com'
567
- fill_in 'Password', :with=>'apple2'
568
- fill_in 'Confirm Password', :with=>'apple2'
569
- click_button 'Create Account'
570
- page.html.must_match(/Logged In: foo2@example\.com/)
12
+ proc{visit '/'}.must_raise NoMethodError
571
13
  end
572
14
 
573
15
  it "should require login to perform certain actions" do
@@ -599,6 +41,7 @@ describe 'Rodauth' do
599
41
  rodauth do
600
42
  enable :login, :change_password
601
43
  already_logged_in{request.redirect '/'}
44
+ skip_status_checks? false
602
45
  end
603
46
  roda do |r|
604
47
  r.rodauth
@@ -608,17 +51,14 @@ describe 'Rodauth' do
608
51
  end
609
52
  end
610
53
 
611
- visit '/login'
612
- fill_in 'Login', :with=>'foo@example.com'
613
- fill_in 'Password', :with=>'0123456789'
614
- click_button 'Login'
615
- page.body.must_match(/Logged In/)
54
+ login
55
+ page.body.must_include("Logged In")
616
56
 
617
- Account.first.update(:status_id=>3)
57
+ DB[:accounts].update(:status_id=>3)
618
58
  visit '/change-password'
619
59
  page.current_path.must_equal '/login'
620
60
  visit '/'
621
- page.body.must_match(/Not Logged/)
61
+ page.body.must_include("Not Logged")
622
62
  end
623
63
 
624
64
  it "should handle cases where you are already logged in on pages that don't expect a login" do
@@ -634,10 +74,7 @@ describe 'Rodauth' do
634
74
  end
635
75
  end
636
76
 
637
- visit '/login'
638
- fill_in 'Login', :with=>'foo@example.com'
639
- fill_in 'Password', :with=>'0123456789'
640
- click_button 'Login'
77
+ login
641
78
 
642
79
  visit '/login'
643
80
  page.current_path.must_equal '/'
@@ -655,423 +92,34 @@ describe 'Rodauth' do
655
92
  page.current_path.must_equal '/logout'
656
93
  end
657
94
 
658
- it "should support resetting passwords for accounts" do
659
- rodauth do
660
- enable :login, :reset_password
661
- end
662
- roda do |r|
663
- r.rodauth
664
- r.root{view :content=>""}
665
- end
666
-
667
- visit '/login'
668
- fill_in 'Login', :with=>'foo@example2.com'
669
- fill_in 'Password', :with=>'01234567'
670
- click_button 'Login'
671
- page.html.wont_match(/notice_flash/)
672
-
673
- fill_in 'Login', :with=>'foo@example.com'
674
- fill_in 'Password', :with=>'01234567'
675
- click_button 'Login'
676
-
677
- click_button 'Request Password Reset'
678
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to reset the password for your account"
679
- page.current_path.must_equal '/'
680
-
681
- link = email_link(/(\/reset-password\?key=.+)$/)
682
- visit link[0...-1]
683
- page.find('#error_flash').text.must_equal "invalid password reset key"
684
-
685
- visit link
686
- page.title.must_equal 'Reset Password'
687
-
688
- fill_in 'Password', :with=>'0123456'
689
- fill_in 'Confirm Password', :with=>'0123456789'
690
- click_button 'Reset Password'
691
- page.html.must_match(/passwords do not match/)
692
- page.find('#error_flash').text.must_equal "There was an error resetting your password"
693
- page.current_path.must_equal '/reset-password'
694
-
695
- fill_in 'Password', :with=>'012'
696
- fill_in 'Confirm Password', :with=>'012'
697
- click_button 'Reset Password'
698
- page.html.must_match(/invalid password, does not meet requirements/)
699
- page.find('#error_flash').text.must_equal "There was an error resetting your password"
700
- page.current_path.must_equal '/reset-password'
701
-
702
- fill_in 'Password', :with=>'0123456'
703
- fill_in 'Confirm Password', :with=>'0123456'
704
- click_button 'Reset Password'
705
- page.find('#notice_flash').text.must_equal "Your password has been reset"
706
- page.current_path.must_equal '/'
707
-
708
- visit '/login'
709
- fill_in 'Login', :with=>'foo@example.com'
710
- fill_in 'Password', :with=>'0123456'
711
- click_button 'Login'
712
- page.current_path.must_equal '/'
713
- end
714
-
715
- it "should support autologin when resetting passwords for accounts" do
716
- rodauth do
717
- enable :login, :reset_password
718
- reset_password_autologin? true
719
- end
720
- roda do |r|
721
- r.rodauth
722
- r.root{view :content=>rodauth.logged_in? ? "Logged In" : "Not Logged"}
723
- end
724
-
725
- visit '/login'
726
- fill_in 'Login', :with=>'foo@example.com'
727
- fill_in 'Password', :with=>'01234567'
728
- click_button 'Login'
729
-
730
- click_button 'Request Password Reset'
731
- link = email_link(/(\/reset-password\?key=.+)$/)
732
- visit link
733
- fill_in 'Password', :with=>'0123456'
734
- fill_in 'Confirm Password', :with=>'0123456'
735
- click_button 'Reset Password'
736
- page.find('#notice_flash').text.must_equal "Your password has been reset"
737
- page.body.must_match(/Logged In/)
738
- end
739
-
740
- it "should support verifying accounts" do
741
- rodauth do
742
- enable :login, :create_account, :verify_account
743
- end
744
- roda do |r|
745
- r.rodauth
746
- r.root{view :content=>""}
747
- end
748
-
749
- visit '/create-account'
750
- fill_in 'Login', :with=>'foo@example2.com'
751
- fill_in 'Confirm Login', :with=>'foo@example2.com'
752
- fill_in 'Password', :with=>'0123456789'
753
- fill_in 'Confirm Password', :with=>'0123456789'
754
- click_button 'Create Account'
755
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
756
- page.current_path.must_equal '/'
757
-
758
- link = email_link(/(\/verify-account\?key=.+)$/)
759
- visit '/login'
760
- fill_in 'Login', :with=>'foo@example2.com'
761
- fill_in 'Password', :with=>'0123456789'
762
- click_button 'Login'
763
- page.find('#error_flash').text.must_equal 'The account you tried to login with is currently awaiting verification'
764
- page.html.must_match(/If you no longer have the email to verify the account, you can request that it be resent to you/)
765
- click_button 'Send Verification Email Again'
766
- page.current_path.must_equal '/login'
767
-
768
- email_link(/(\/verify-account\?key=.+)$/).must_equal link
769
- visit '/create-account'
770
- fill_in 'Login', :with=>'foo@example2.com'
771
- click_button 'Create Account'
772
- click_button 'Send Verification Email Again'
773
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
774
- page.current_path.must_equal '/login'
775
-
776
- link = email_link(/(\/verify-account\?key=.+)$/)
777
- visit link[0...-1]
778
- page.find('#error_flash').text.must_equal "invalid verify account key"
779
-
780
- visit link
781
- click_button 'Verify Account'
782
- page.find('#notice_flash').text.must_equal "Your account has been verified"
783
- page.current_path.must_equal '/'
784
-
785
- visit '/login'
786
- fill_in 'Login', :with=>'foo@example2.com'
787
- fill_in 'Password', :with=>'0123456789'
788
- click_button 'Login'
789
- page.find('#notice_flash').text.must_equal 'You have been logged in'
790
- page.current_path.must_equal '/'
791
- end
792
-
793
- it "should support autologin when verifying accounts" do
794
- rodauth do
795
- enable :login, :create_account, :verify_account
796
- verify_account_autologin? true
797
- end
798
- roda do |r|
799
- r.rodauth
800
- r.root{view :content=>rodauth.logged_in? ? "Logged In" : "Not Logged"}
801
- end
802
-
803
- visit '/create-account'
804
- fill_in 'Login', :with=>'foo@example2.com'
805
- fill_in 'Confirm Login', :with=>'foo@example2.com'
806
- fill_in 'Password', :with=>'0123456789'
807
- fill_in 'Confirm Password', :with=>'0123456789'
808
- click_button 'Create Account'
809
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
810
- page.current_path.must_equal '/'
811
-
812
- link = email_link(/(\/verify-account\?key=.+)$/)
813
- visit link
814
- click_button 'Verify Account'
815
- page.find('#notice_flash').text.must_equal "Your account has been verified"
816
- page.body.must_match /Logged In/
817
- end
818
-
819
- it "should support login via remember token" do
820
- rodauth do
821
- enable :login, :remember
822
- end
823
- roda do |r|
824
- r.rodauth
825
- r.get 'load' do
826
- rodauth.load_memory
827
- r.redirect '/'
828
- end
829
- r.root{rodauth.logged_in? ? "Logged In#{session[:remembered]}" : "Not Logged In"}
830
- end
831
-
832
- visit '/login'
833
- fill_in 'Login', :with=>'foo@example.com'
834
- fill_in 'Password', :with=>'0123456789'
835
- click_button 'Login'
836
- page.body.must_equal 'Logged In'
837
-
838
- visit '/remember'
839
- choose 'Remember Me'
840
- click_button 'Change Remember Setting'
841
- page.body.must_equal 'Logged In'
842
-
843
- remove_cookie('rack.session')
844
- visit '/'
845
- page.body.must_equal 'Not Logged In'
846
-
847
- visit '/load'
848
- page.body.must_equal 'Logged Intrue'
849
-
850
- key = get_cookie('_remember')
851
- visit '/remember'
852
- choose 'Forget Me'
853
- click_button 'Change Remember Setting'
854
- page.body.must_equal 'Logged Intrue'
855
-
856
- remove_cookie('rack.session')
857
- visit '/'
858
- page.body.must_equal 'Not Logged In'
859
-
860
- visit '/load'
861
- page.body.must_equal 'Not Logged In'
862
-
863
- set_cookie('_remember', key)
864
- visit '/load'
865
- page.body.must_equal 'Logged Intrue'
866
-
867
- visit '/remember'
868
- choose 'Disable Remember Me'
869
- click_button 'Change Remember Setting'
870
- page.body.must_equal 'Logged Intrue'
871
-
872
- remove_cookie('rack.session')
873
- visit '/'
874
- page.body.must_equal 'Not Logged In'
875
-
876
- set_cookie('_remember', key)
877
- visit '/load'
878
- page.body.must_equal 'Not Logged In'
879
- end
880
-
881
- it "should forget remember token when explicitly logging out" do
95
+ it "should have rodauth.features and rodauth.session_value work when not logged in" do
882
96
  rodauth do
883
- enable :login, :logout, :remember
884
- end
885
- roda do |r|
886
- r.rodauth
887
- r.get 'load' do
888
- rodauth.load_memory
889
- r.redirect '/'
890
- end
891
- r.root{rodauth.logged_in? ? "Logged In#{session[:remembered]}" : "Not Logged In"}
892
- end
893
-
894
- visit '/login'
895
- fill_in 'Login', :with=>'foo@example.com'
896
- fill_in 'Password', :with=>'0123456789'
897
- click_button 'Login'
898
- page.body.must_equal 'Logged In'
899
-
900
- visit '/remember'
901
- choose 'Remember Me'
902
- click_button 'Change Remember Setting'
903
- page.body.must_equal 'Logged In'
904
-
905
- visit '/logout'
906
- click_button 'Logout'
907
-
908
- visit '/'
909
- page.body.must_equal 'Not Logged In'
910
-
911
- visit '/load'
912
- page.body.must_equal 'Not Logged In'
913
- end
914
-
915
- it "should support clearing remembered flag" do
916
- rodauth do
917
- enable :login, :remember
97
+ enable :login
918
98
  end
919
99
  roda do |r|
920
- r.rodauth
921
- r.get 'load' do
922
- rodauth.load_memory
923
- r.redirect '/'
924
- end
925
- r.root{rodauth.logged_in? ? "Logged In#{session[:remembered]}" : "Not Logged In"}
100
+ "#{rodauth.features.first.inspect}#{rodauth.session_value.inspect}"
926
101
  end
927
102
 
928
- visit '/login'
929
- fill_in 'Login', :with=>'foo@example.com'
930
- fill_in 'Password', :with=>'0123456789'
931
- click_button 'Login'
932
- page.body.must_equal 'Logged In'
933
-
934
- visit '/remember'
935
- choose 'Remember Me'
936
- click_button 'Change Remember Setting'
937
- page.body.must_equal 'Logged In'
938
-
939
- remove_cookie('rack.session')
940
103
  visit '/'
941
- page.body.must_equal 'Not Logged In'
942
-
943
- visit '/load'
944
- page.body.must_equal 'Logged Intrue'
945
-
946
- visit '/remember?confirm=t'
947
- fill_in 'Password', :with=>'012345678'
948
- click_button 'Confirm Password'
949
- page.html.must_match(/invalid password/)
950
-
951
- fill_in 'Password', :with=>'0123456789'
952
- click_button 'Confirm Password'
953
- page.body.must_equal 'Logged In'
104
+ page.body.must_equal ':loginnil'
954
105
  end
955
106
 
956
- it "should support extending remember token" do
107
+ it "should support auth_class_eval for evaluation inside Auth class" do
957
108
  rodauth do
958
- enable :login, :remember
959
- extend_remember_deadline? true
960
- end
961
- roda do |r|
962
- r.rodauth
963
- r.get 'load' do
964
- rodauth.load_memory
965
- r.redirect '/'
109
+ enable :login
110
+ login_label{foo}
111
+ auth_class_eval do
112
+ def foo
113
+ 'Lonig'
114
+ end
966
115
  end
967
- r.root{rodauth.logged_in? ? "Logged In#{session[:remembered]}" : "Not Logged In"}
968
- end
969
-
970
- visit '/login'
971
- fill_in 'Login', :with=>'foo@example.com'
972
- fill_in 'Password', :with=>'0123456789'
973
- click_button 'Login'
974
-
975
- visit '/remember'
976
- choose 'Remember Me'
977
- click_button 'Change Remember Setting'
978
-
979
- remove_cookie('rack.session')
980
- visit '/'
981
- page.body.must_equal 'Not Logged In'
982
-
983
- visit '/load'
984
- page.body.must_equal 'Logged Intrue'
985
- end
986
-
987
- it "should support account lockouts" do
988
- rodauth do
989
- enable :lockout
990
- max_invalid_logins 2
991
116
  end
992
117
  roda do |r|
993
118
  r.rodauth
994
- r.root{view :content=>(rodauth.logged_in? ? "Logged In" : "Not Logged")}
995
119
  end
996
120
 
997
121
  visit '/login'
998
- fill_in 'Login', :with=>'foo@example.com'
999
- fill_in 'Password', :with=>'012345678910'
1000
- click_button 'Login'
1001
- page.find('#error_flash').text.must_equal 'There was an error logging in'
1002
-
1003
- fill_in 'Login', :with=>'foo@example.com'
1004
- fill_in 'Password', :with=>'0123456789'
1005
- click_button 'Login'
1006
- page.find('#notice_flash').text.must_equal 'You have been logged in'
1007
- page.body.must_match(/Logged In/)
1008
-
1009
- remove_cookie('rack.session')
1010
-
1011
- visit '/login'
1012
- fill_in 'Login', :with=>'foo@example.com'
1013
- 3.times do
1014
- fill_in 'Password', :with=>'012345678910'
1015
- click_button 'Login'
1016
- page.find('#error_flash').text.must_equal 'There was an error logging in'
1017
- end
1018
- page.body.must_match(/This account is currently locked out/)
1019
- click_button 'Request Account Unlock'
1020
- page.find('#notice_flash').text.must_equal 'An email has been sent to you with a link to unlock your account'
1021
-
1022
- link = email_link(/(\/unlock-account\?key=.+)$/)
1023
- visit link[0...-1]
1024
- page.find('#error_flash').text.must_equal 'No matching unlock account key'
1025
-
1026
- visit link
1027
- click_button 'Unlock Account'
1028
- page.find('#notice_flash').text.must_equal 'Your account has been unlocked'
1029
-
1030
- visit '/login'
1031
- fill_in 'Login', :with=>'foo@example.com'
1032
- fill_in 'Password', :with=>'0123456789'
1033
- click_button 'Login'
1034
- page.find('#notice_flash').text.must_equal 'You have been logged in'
1035
- page.body.must_match(/Logged In/)
1036
- end
1037
-
1038
- it "should support autologin when unlocking account" do
1039
- rodauth do
1040
- enable :lockout
1041
- unlock_account_autologin? true
1042
- end
1043
- roda do |r|
1044
- r.rodauth
1045
- r.root{view :content=>(rodauth.logged_in? ? "Logged In" : "Not Logged")}
1046
- end
1047
-
1048
- visit '/login'
1049
- fill_in 'Login', :with=>'foo@example.com'
1050
- 101.times do |i|
1051
- fill_in 'Password', :with=>'012345678910'
1052
- click_button 'Login'
1053
- page.find('#error_flash').text.must_equal 'There was an error logging in'
1054
- end
1055
- page.body.must_match(/This account is currently locked out/)
1056
- click_button 'Request Account Unlock'
1057
- page.find('#notice_flash').text.must_equal 'An email has been sent to you with a link to unlock your account'
1058
-
1059
- link = email_link(/(\/unlock-account\?key=.+)$/)
1060
- visit link
1061
- click_button 'Unlock Account'
1062
- page.body.must_match(/Logged In/)
1063
- end
1064
-
1065
- it "should support verifying accounts" do
1066
- rodauth do
1067
- enable :login
1068
- end
1069
- roda do |r|
1070
- "#{rodauth.features.first.inspect}#{rodauth.session_value.inspect}"
1071
- end
1072
-
1073
- visit '/'
1074
- page.body.must_equal ':loginnil'
122
+ fill_in 'Lonig', :with=>'foo@example.com'
1075
123
  end
1076
124
 
1077
125
  it "should support multiple rodauth configurations in an app" do
@@ -1096,11 +144,8 @@ describe 'Rodauth' do
1096
144
  app.freeze
1097
145
  self.app = app
1098
146
 
1099
- visit '/r1/login'
1100
- fill_in 'Login', :with=>'foo@example.com'
1101
- fill_in 'Password', :with=>'0123456789'
1102
- click_button 'Login'
1103
- page.body.must_equal Account.first.id.to_s
147
+ login(:path=>'/r1/login')
148
+ page.body.must_equal DB[:accounts].get(:id).to_s
1104
149
 
1105
150
  visit '/r2/logout'
1106
151
  click_button 'Logout'
@@ -1111,4 +156,36 @@ describe 'Rodauth' do
1111
156
  visit '/r2/login'
1112
157
  page.body.must_equal 'r2'
1113
158
  end
159
+
160
+ it "should support account_model setting for backwards compatibility" do
161
+ warning = nil
162
+ rodauth do
163
+ enable :login
164
+ (class << self; self end).send(:define_method, :warn){|msg| warning = msg}
165
+ account_model Sequel::Model(DB[:accs].select(:id))
166
+ end
167
+ roda do |r|
168
+ "#{rodauth.accounts_table}#{rodauth.account_select.length}"
169
+ end
170
+
171
+ visit '/'
172
+ page.body.must_equal 'accs1'
173
+ warning.must_equal "account_model is deprecated, use db and accounts_table settings"
174
+ end
175
+
176
+ it "should support account_select setting for choosing account columns" do
177
+ warning = nil
178
+ rodauth do
179
+ enable :login
180
+ account_select [:id, :email]
181
+ end
182
+ roda do |r|
183
+ r.rodauth
184
+ rodauth.account_from_session
185
+ rodauth.account.keys.map(&:to_s).sort.join(' ')
186
+ end
187
+
188
+ login
189
+ page.body.must_equal 'email id'
190
+ end
1114
191
  end