rodauth 1.20.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +170 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +211 -79
  5. data/doc/account_expiration.rdoc +12 -26
  6. data/doc/active_sessions.rdoc +49 -0
  7. data/doc/audit_logging.rdoc +44 -0
  8. data/doc/base.rdoc +75 -128
  9. data/doc/change_login.rdoc +7 -14
  10. data/doc/change_password.rdoc +9 -13
  11. data/doc/change_password_notify.rdoc +2 -2
  12. data/doc/close_account.rdoc +9 -16
  13. data/doc/confirm_password.rdoc +12 -5
  14. data/doc/create_account.rdoc +11 -22
  15. data/doc/disallow_password_reuse.rdoc +6 -13
  16. data/doc/email_auth.rdoc +15 -14
  17. data/doc/email_base.rdoc +6 -15
  18. data/doc/http_basic_auth.rdoc +10 -1
  19. data/doc/internals.rdoc +1 -1
  20. data/doc/jwt.rdoc +22 -22
  21. data/doc/jwt_cors.rdoc +22 -0
  22. data/doc/jwt_refresh.rdoc +12 -8
  23. data/doc/lockout.rdoc +17 -15
  24. data/doc/login.rdoc +10 -2
  25. data/doc/login_password_requirements_base.rdoc +15 -37
  26. data/doc/logout.rdoc +2 -2
  27. data/doc/otp.rdoc +24 -19
  28. data/doc/password_complexity.rdoc +10 -26
  29. data/doc/password_expiration.rdoc +11 -25
  30. data/doc/password_grace_period.rdoc +16 -2
  31. data/doc/recovery_codes.rdoc +18 -12
  32. data/doc/release_notes/1.21.0.txt +12 -0
  33. data/doc/release_notes/1.22.0.txt +11 -0
  34. data/doc/release_notes/1.23.0.txt +32 -0
  35. data/doc/release_notes/2.0.0.txt +361 -0
  36. data/doc/release_notes/2.1.0.txt +31 -0
  37. data/doc/remember.rdoc +40 -64
  38. data/doc/reset_password.rdoc +12 -9
  39. data/doc/session_expiration.rdoc +1 -0
  40. data/doc/single_session.rdoc +16 -25
  41. data/doc/sms_codes.rdoc +24 -14
  42. data/doc/two_factor_base.rdoc +60 -22
  43. data/doc/verify_account.rdoc +14 -12
  44. data/doc/verify_account_grace_period.rdoc +6 -2
  45. data/doc/verify_login_change.rdoc +9 -8
  46. data/doc/webauthn.rdoc +115 -0
  47. data/doc/webauthn_login.rdoc +15 -0
  48. data/doc/webauthn_verify_account.rdoc +9 -0
  49. data/javascript/webauthn_auth.js +45 -0
  50. data/javascript/webauthn_setup.js +35 -0
  51. data/lib/roda/plugins/rodauth.rb +1 -1
  52. data/lib/rodauth.rb +32 -24
  53. data/lib/rodauth/features/account_expiration.rb +5 -5
  54. data/lib/rodauth/features/active_sessions.rb +160 -0
  55. data/lib/rodauth/features/audit_logging.rb +96 -0
  56. data/lib/rodauth/features/base.rb +144 -43
  57. data/lib/rodauth/features/change_password_notify.rb +2 -2
  58. data/lib/rodauth/features/confirm_password.rb +40 -2
  59. data/lib/rodauth/features/create_account.rb +8 -13
  60. data/lib/rodauth/features/disallow_common_passwords.rb +1 -1
  61. data/lib/rodauth/features/disallow_password_reuse.rb +1 -1
  62. data/lib/rodauth/features/email_auth.rb +30 -29
  63. data/lib/rodauth/features/email_base.rb +9 -4
  64. data/lib/rodauth/features/http_basic_auth.rb +55 -35
  65. data/lib/rodauth/features/jwt.rb +58 -10
  66. data/lib/rodauth/features/jwt_cors.rb +53 -0
  67. data/lib/rodauth/features/jwt_refresh.rb +3 -3
  68. data/lib/rodauth/features/lockout.rb +12 -14
  69. data/lib/rodauth/features/login.rb +54 -10
  70. data/lib/rodauth/features/login_password_requirements_base.rb +4 -4
  71. data/lib/rodauth/features/otp.rb +72 -74
  72. data/lib/rodauth/features/password_complexity.rb +4 -11
  73. data/lib/rodauth/features/password_expiration.rb +2 -2
  74. data/lib/rodauth/features/password_grace_period.rb +17 -10
  75. data/lib/rodauth/features/recovery_codes.rb +49 -53
  76. data/lib/rodauth/features/remember.rb +11 -27
  77. data/lib/rodauth/features/reset_password.rb +26 -26
  78. data/lib/rodauth/features/session_expiration.rb +6 -4
  79. data/lib/rodauth/features/single_session.rb +7 -5
  80. data/lib/rodauth/features/sms_codes.rb +62 -71
  81. data/lib/rodauth/features/two_factor_base.rb +132 -28
  82. data/lib/rodauth/features/verify_account.rb +25 -21
  83. data/lib/rodauth/features/verify_account_grace_period.rb +20 -9
  84. data/lib/rodauth/features/verify_login_change.rb +12 -11
  85. data/lib/rodauth/features/webauthn.rb +507 -0
  86. data/lib/rodauth/features/webauthn_login.rb +70 -0
  87. data/lib/rodauth/features/webauthn_verify_account.rb +46 -0
  88. data/lib/rodauth/version.rb +2 -2
  89. data/templates/button.str +1 -3
  90. data/templates/change-login.str +1 -2
  91. data/templates/change-password.str +3 -5
  92. data/templates/close-account.str +2 -2
  93. data/templates/confirm-password.str +1 -1
  94. data/templates/create-account.str +1 -1
  95. data/templates/email-auth-email.str +1 -1
  96. data/templates/email-auth-request-form.str +2 -3
  97. data/templates/email-auth.str +1 -1
  98. data/templates/global-logout-field.str +6 -0
  99. data/templates/login-confirm-field.str +2 -4
  100. data/templates/login-display.str +3 -2
  101. data/templates/login-field.str +2 -4
  102. data/templates/login-form-footer.str +6 -0
  103. data/templates/login-form.str +7 -0
  104. data/templates/login.str +1 -9
  105. data/templates/logout.str +1 -1
  106. data/templates/multi-phase-login.str +3 -0
  107. data/templates/otp-auth-code-field.str +5 -3
  108. data/templates/otp-auth.str +1 -1
  109. data/templates/otp-disable.str +1 -1
  110. data/templates/otp-setup.str +3 -3
  111. data/templates/password-confirm-field.str +2 -4
  112. data/templates/password-field.str +2 -4
  113. data/templates/recovery-auth.str +3 -6
  114. data/templates/recovery-codes.str +1 -1
  115. data/templates/remember.str +15 -20
  116. data/templates/reset-password-email.str +1 -1
  117. data/templates/reset-password-request.str +3 -3
  118. data/templates/reset-password.str +1 -2
  119. data/templates/sms-auth.str +1 -1
  120. data/templates/sms-code-field.str +5 -3
  121. data/templates/sms-confirm.str +1 -2
  122. data/templates/sms-disable.str +1 -2
  123. data/templates/sms-request.str +1 -1
  124. data/templates/sms-setup.str +6 -4
  125. data/templates/two-factor-auth.str +5 -0
  126. data/templates/two-factor-disable.str +6 -0
  127. data/templates/two-factor-manage.str +16 -0
  128. data/templates/unlock-account-email.str +1 -1
  129. data/templates/unlock-account-request.str +4 -4
  130. data/templates/unlock-account.str +1 -1
  131. data/templates/verify-account-email.str +1 -1
  132. data/templates/verify-account-resend.str +3 -3
  133. data/templates/verify-account.str +1 -2
  134. data/templates/verify-login-change-email.str +2 -1
  135. data/templates/verify-login-change.str +1 -1
  136. data/templates/webauthn-auth.str +11 -0
  137. data/templates/webauthn-remove.str +14 -0
  138. data/templates/webauthn-setup.str +12 -0
  139. metadata +89 -50
  140. data/Rakefile +0 -179
  141. data/doc/verify_change_login.rdoc +0 -11
  142. data/lib/rodauth/features/verify_change_login.rb +0 -20
  143. data/spec/account_expiration_spec.rb +0 -225
  144. data/spec/all.rb +0 -1
  145. data/spec/change_login_spec.rb +0 -156
  146. data/spec/change_password_notify_spec.rb +0 -33
  147. data/spec/change_password_spec.rb +0 -202
  148. data/spec/close_account_spec.rb +0 -162
  149. data/spec/confirm_password_spec.rb +0 -70
  150. data/spec/create_account_spec.rb +0 -127
  151. data/spec/disallow_common_passwords_spec.rb +0 -93
  152. data/spec/disallow_password_reuse_spec.rb +0 -179
  153. data/spec/email_auth_spec.rb +0 -285
  154. data/spec/http_basic_auth_spec.rb +0 -143
  155. data/spec/jwt_refresh_spec.rb +0 -256
  156. data/spec/jwt_spec.rb +0 -235
  157. data/spec/lockout_spec.rb +0 -250
  158. data/spec/login_spec.rb +0 -328
  159. data/spec/migrate/001_tables.rb +0 -184
  160. data/spec/migrate/002_account_password_hash_column.rb +0 -11
  161. data/spec/migrate_password/001_tables.rb +0 -73
  162. data/spec/migrate_travis/001_tables.rb +0 -141
  163. data/spec/password_complexity_spec.rb +0 -109
  164. data/spec/password_expiration_spec.rb +0 -244
  165. data/spec/password_grace_period_spec.rb +0 -93
  166. data/spec/remember_spec.rb +0 -451
  167. data/spec/reset_password_spec.rb +0 -229
  168. data/spec/rodauth_spec.rb +0 -343
  169. data/spec/session_expiration_spec.rb +0 -58
  170. data/spec/single_session_spec.rb +0 -127
  171. data/spec/spec_helper.rb +0 -327
  172. data/spec/two_factor_spec.rb +0 -1423
  173. data/spec/update_password_hash_spec.rb +0 -40
  174. data/spec/verify_account_grace_period_spec.rb +0 -171
  175. data/spec/verify_account_spec.rb +0 -240
  176. data/spec/verify_change_login_spec.rb +0 -46
  177. data/spec/verify_login_change_spec.rb +0 -232
  178. data/spec/views/layout-other.str +0 -11
  179. data/spec/views/layout.str +0 -11
  180. data/spec/views/login.str +0 -21
data/Rakefile DELETED
@@ -1,179 +0,0 @@
1
- require "rake"
2
- require "rake/clean"
3
-
4
- CLEAN.include ["rodauth-*.gem", "rdoc", "coverage", "www/public/rdoc", "www/public/*.html"]
5
-
6
- # Packaging
7
-
8
- desc "Build rodauth gem"
9
- task :package=>[:clean] do |p|
10
- sh %{#{FileUtils::RUBY} -S gem build rodauth.gemspec}
11
- end
12
-
13
- ### RDoc
14
-
15
- RDOC_DEFAULT_OPTS = ["--line-numbers", "--inline-source", '--title', 'Rodauth: Authentication and Account Management Framework for Rack Applications']
16
-
17
- begin
18
- gem 'hanna-nouveau'
19
- RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
20
- rescue Gem::LoadError
21
- end
22
-
23
- rdoc_task_class = begin
24
- require "rdoc/task"
25
- RDoc::Task
26
- rescue LoadError
27
- require "rake/rdoctask"
28
- Rake::RDocTask
29
- end
30
-
31
- RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
32
- RDOC_FILES = %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb" + Dir["doc/*.rdoc"] + Dir['doc/release_notes/*.txt']
33
-
34
- rdoc_task_class.new do |rdoc|
35
- rdoc.rdoc_dir = "rdoc"
36
- rdoc.options += RDOC_OPTS
37
- rdoc.rdoc_files.add RDOC_FILES
38
- end
39
-
40
- # Specs
41
-
42
- desc "Run specs"
43
- task :default=>:spec
44
-
45
- spec = proc do |env|
46
- env.each{|k,v| ENV[k] = v}
47
- sh "#{FileUtils::RUBY} spec/all.rb"
48
- env.each{|k,v| ENV.delete(k)}
49
- end
50
-
51
- desc "Run specs on PostgreSQL"
52
- task "spec" do
53
- spec.call({})
54
- end
55
-
56
- desc "Run specs with coverage"
57
- task "spec_cov" do
58
- ENV['COVERAGE'] = '1'
59
- spec.call('COVERAGE'=>'1')
60
- end
61
-
62
- desc "Run specs with -w, some warnings filtered"
63
- task "spec_w" do
64
- rubyopt = ENV['RUBYOPT']
65
- ENV['RUBYOPT'] = "#{rubyopt} -w"
66
- spec.call('WARNING'=>'1')
67
- ENV['RUBYOPT'] = rubyopt
68
- end
69
-
70
- desc "Setup database used for testing on PostgreSQL"
71
- task :db_setup_postgres do
72
- sh 'psql -U postgres -c "CREATE USER rodauth_test PASSWORD \'rodauth_test\'"'
73
- sh 'psql -U postgres -c "CREATE USER rodauth_test_password PASSWORD \'rodauth_test\'"'
74
- sh 'createdb -U postgres -O rodauth_test rodauth_test'
75
- sh 'psql -U postgres -c "CREATE EXTENSION citext" rodauth_test'
76
- $: << 'lib'
77
- require 'sequel'
78
- Sequel.extension :migration
79
- Sequel.postgres(:user=>'rodauth_test', :password=>'rodauth_test') do |db|
80
- Sequel::Migrator.run(db, 'spec/migrate')
81
- end
82
- Sequel.postgres('rodauth_test', :user=>'rodauth_test_password', :password=>'rodauth_test') do |db|
83
- Sequel::Migrator.run(db, 'spec/migrate_password', :table=>'schema_info_password')
84
- end
85
- end
86
-
87
- desc "Teardown database used for testing on MySQL"
88
- task :db_teardown_postgres do
89
- sh 'dropdb -U postgres rodauth_test'
90
- sh 'dropuser -U postgres rodauth_test_password'
91
- sh 'dropuser -U postgres rodauth_test'
92
- end
93
-
94
- desc "Setup database used for testing on MySQL"
95
- task :db_setup_mysql do
96
- sh 'mysql --user=root -p mysql < spec/sql/mysql_setup.sql'
97
- $: << 'lib'
98
- require 'sequel'
99
- Sequel.extension :migration
100
- Sequel.mysql2('rodauth_test', :user=>'rodauth_test_password', :password=>'rodauth_test') do |db|
101
- Sequel::Migrator.run(db, 'spec/migrate')
102
- end
103
- Sequel.mysql2('rodauth_test', :user=>'rodauth_test_password', :password=>'rodauth_test') do |db|
104
- Sequel::Migrator.run(db, 'spec/migrate_password', :table=>'schema_info_password')
105
- end
106
- end
107
-
108
- desc "Teardown database used for testing on MySQL"
109
- task :db_teardown_mysql do
110
- sh 'mysql --user=root -p mysql < spec/sql/mysql_teardown.sql'
111
- end
112
-
113
- desc "Setup database used for testing on Microsoft SQL Server"
114
- task :db_setup_mssql do
115
- sh 'sqlcmd -E -e -b -r1 -i spec\\sql\\mssql_setup.sql'
116
- $: << 'lib'
117
- require 'sequel'
118
- Sequel.extension :migration
119
- Sequel.tinytds('rodauth_test', :host=>'localhost', :user=>'rodauth_test_password', :password=>'Rodauth1.') do |db|
120
- Sequel::Migrator.run(db, 'spec/migrate')
121
- end
122
- Sequel.tinytds('rodauth_test', :host=>'localhost', :user=>'rodauth_test_password', :password=>'Rodauth1.') do |db|
123
- Sequel::Migrator.run(db, 'spec/migrate_password', :table=>'schema_info_password')
124
- end
125
- end
126
-
127
- desc "Teardown database used for testing on Microsoft SQL Server"
128
- task :db_teardown_mssql do
129
- sh 'sqlcmd -E -e -b -r1 -i spec\\sql\\mssql_teardown.sql'
130
- end
131
-
132
- desc "Run specs on MySQL"
133
- task :spec_mysql do
134
- spec.call('RODAUTH_SPEC_DB'=>'mysql2://rodauth_test:rodauth_test@localhost/rodauth_test')
135
- end
136
-
137
- task :spec_travis do
138
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
139
- pg_db = 'jdbc:postgresql://localhost/rodauth_test?user=postgres'
140
- my_db = "jdbc:mysql://localhost/rodauth_test?user=root"
141
- else
142
- pg_db = 'postgres:///rodauth_test?user=postgres'
143
- my_db = "mysql2://localhost/rodauth_test?user=root"
144
- end
145
- sh 'psql -U postgres -c "CREATE EXTENSION citext" rodauth_test'
146
- spec.call('RODAUTH_SPEC_MIGRATE'=>'1', 'RODAUTH_SPEC_DB'=>pg_db)
147
- spec.call('RODAUTH_SPEC_MIGRATE'=>'1', 'RODAUTH_SPEC_DB'=>my_db)
148
- end
149
-
150
- desc "Run specs on SQLite"
151
- task :spec_sqlite do
152
- spec_db = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
153
- 'jdbc:sqlite::memory:'
154
- else
155
- 'sqlite:/'
156
- end
157
- spec.call('RODAUTH_SPEC_MIGRATE'=>'1', 'RODAUTH_SPEC_DB'=>spec_db)
158
- end
159
-
160
- ### Website
161
-
162
- rdoc_task_class.new(:website_rdoc) do |rdoc|
163
- rdoc.rdoc_dir = "www/public/rdoc"
164
- rdoc.options += RDOC_OPTS
165
- rdoc.rdoc_files.add RDOC_FILES
166
- end
167
-
168
- desc "Make local version of website"
169
- task :website_base do
170
- sh %{#{FileUtils::RUBY} -I lib www/make_www.rb}
171
- end
172
-
173
- desc "Make local version of website, with rdoc"
174
- task :website => [:website_base, :website_rdoc]
175
-
176
- desc "Serve local version of website via rackup"
177
- task :serve => :website do
178
- sh %{#{FileUtils::RUBY} -C www -S rackup}
179
- end
@@ -1,11 +0,0 @@
1
- = Documentation for Verify Change Login Feature
2
-
3
- This feature is deprecated, because it is possible for a user to get
4
- locked out of their account if they use the wrong address on the
5
- change login page. It is recommended that users switch to using the
6
- verify login change feature, which doesn't change the login until
7
- after it has been verified.
8
-
9
- The verify change login feature implements account reverification after
10
- change login. Depends on the change login and verify account grace
11
- period features.
@@ -1,20 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- module Rodauth
4
- Feature.define(:verify_change_login, :VerifyChangeLogin) do
5
- depends :change_login, :verify_account_grace_period
6
-
7
- def change_login_notice_flash
8
- "#{super}. #{verify_account_email_sent_notice_flash}"
9
- end
10
-
11
- private
12
-
13
- def after_change_login
14
- super
15
- update_account(account_status_column=>account_unverified_status_value)
16
- setup_account_verification
17
- session[unverified_account_session_key] = true
18
- end
19
- end
20
- end
@@ -1,225 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth account expiration feature' do
4
- it "should force account expiration after x number of days since last login" do
5
- rodauth do
6
- enable :login, :logout, :account_expiration
7
- end
8
- roda do |r|
9
- r.rodauth
10
- r.root{view :content=>rodauth.logged_in? ? "Logged In#{rodauth.last_account_login_at.strftime('%m%d%y')}" : "Not Logged"}
11
- end
12
-
13
- now = Time.now
14
- 2.times do
15
- login
16
- page.body.must_include "Logged In#{now.strftime('%m%d%y')}"
17
-
18
- logout
19
- end
20
-
21
- DB[:account_activity_times].update(:last_login_at => Time.now - 181*86400)
22
-
23
- 2.times do
24
- login
25
- page.body.must_include 'Not Logged'
26
- page.find('#error_flash').text.must_equal "You cannot log into this account as it has expired"
27
- end
28
- end
29
-
30
- it "should not allow resetting of passwords for expired accounts" do
31
- rodauth do
32
- enable :login, :logout, :account_expiration, :reset_password
33
- end
34
- roda do |r|
35
- r.rodauth
36
- r.root{view :content=>rodauth.logged_in? ? "Logged In#{rodauth.last_account_login_at.strftime('%m%d%y')}" : "Not Logged"}
37
- end
38
-
39
- now = Time.now
40
- login
41
- page.body.must_include "Logged In#{now.strftime('%m%d%y')}"
42
- logout
43
-
44
- visit '/login'
45
- click_link 'Forgot Password?'
46
- fill_in 'Login', :with=>'foo@example.com'
47
- click_button 'Request Password Reset'
48
- link = email_link(/(\/reset-password\?key=.+)$/)
49
-
50
- visit link
51
- fill_in 'Password', :with=>'0123456'
52
- fill_in 'Confirm Password', :with=>'0123456'
53
- click_button 'Reset Password'
54
- page.find('#notice_flash').text.must_equal "Your password has been reset"
55
- page.current_path.must_equal '/'
56
-
57
- visit '/login'
58
- click_link 'Forgot Password?'
59
- fill_in 'Login', :with=>'foo@example.com'
60
- click_button 'Request Password Reset'
61
- link = email_link(/(\/reset-password\?key=.+)$/)
62
-
63
- DB[:account_activity_times].update(:last_login_at => Time.now - 181*86400)
64
-
65
- visit link
66
- page.title.must_equal 'Reset Password'
67
- fill_in 'Password', :with=>'01234567'
68
- fill_in 'Confirm Password', :with=>'01234567'
69
- click_button 'Reset Password'
70
- page.find('#error_flash').text.must_equal "You cannot log into this account as it has expired"
71
- page.body.must_include 'Not Logged'
72
- page.current_path.must_equal '/'
73
-
74
- visit '/login'
75
- click_link 'Forgot Password?'
76
- fill_in 'Login', :with=>'foo@example.com'
77
- click_button 'Request Password Reset'
78
- page.find('#error_flash').text.must_equal "You cannot log into this account as it has expired"
79
- page.body.must_include 'Not Logged'
80
- page.current_path.must_equal '/'
81
- end
82
-
83
- it "should not allow account unlocks for expired accounts" do
84
- rodauth do
85
- enable :lockout, :account_expiration, :logout
86
- max_invalid_logins 2
87
- unlock_account_autologin? false
88
- end
89
- roda do |r|
90
- r.rodauth
91
- r.root{view :content=>(rodauth.logged_in? ? "Logged In" : "Not Logged")}
92
- end
93
-
94
- login
95
- logout
96
-
97
- visit '/login'
98
- fill_in 'Login', :with=>'foo@example.com'
99
- 3.times do
100
- fill_in 'Password', :with=>'012345678910'
101
- click_button 'Login'
102
- end
103
-
104
- page.body.must_include("This account is currently locked out")
105
- click_button 'Request Account Unlock'
106
- page.find('#notice_flash').text.must_equal 'An email has been sent to you with a link to unlock your account'
107
- link = email_link(/(\/unlock-account\?key=.+)$/)
108
-
109
- visit link
110
- click_button 'Unlock Account'
111
- page.find('#notice_flash').text.must_equal 'Your account has been unlocked'
112
- page.body.must_include('Not Logged')
113
-
114
- visit '/login'
115
- fill_in 'Login', :with=>'foo@example.com'
116
- 3.times do
117
- fill_in 'Password', :with=>'012345678910'
118
- click_button 'Login'
119
- end
120
-
121
- page.body.must_include("This account is currently locked out")
122
- click_button 'Request Account Unlock'
123
- page.find('#notice_flash').text.must_equal 'An email has been sent to you with a link to unlock your account'
124
- link = email_link(/(\/unlock-account\?key=.+)$/)
125
-
126
- DB[:account_activity_times].update(:last_login_at => Time.now - 181*86400)
127
-
128
- visit link
129
- click_button 'Unlock Account'
130
- page.find('#error_flash').text.must_equal "You cannot log into this account as it has expired"
131
- page.body.must_include 'Not Logged'
132
- page.current_path.must_equal '/'
133
- end
134
-
135
- it "should not allow account unlock requests for expired accounts" do
136
- rodauth do
137
- enable :lockout, :account_expiration, :logout
138
- max_invalid_logins 2
139
- unlock_account_autologin? false
140
- end
141
- roda do |r|
142
- r.rodauth
143
- r.root{view :content=>(rodauth.logged_in? ? "Logged In" : "Not Logged")}
144
- end
145
-
146
- login
147
- logout
148
-
149
- visit '/login'
150
- fill_in 'Login', :with=>'foo@example.com'
151
- 3.times do
152
- fill_in 'Password', :with=>'012345678910'
153
- click_button 'Login'
154
- end
155
-
156
- DB[:account_activity_times].update(:last_login_at => Time.now - 181*86400)
157
-
158
- page.body.must_include("This account is currently locked out")
159
- click_button 'Request Account Unlock'
160
- page.find('#error_flash').text.must_equal "You cannot log into this account as it has expired"
161
- page.body.must_include 'Not Logged'
162
- page.current_path.must_equal '/'
163
- end
164
-
165
- it "should use last activity time if configured" do
166
- rodauth do
167
- enable :login, :logout, :account_expiration
168
- expire_account_on_last_activity? true
169
- account_expiration_error_flash{"Account expired on #{account_expired_at.strftime('%m%d%y')}"}
170
- end
171
- roda do |r|
172
- r.is("a"){view :content=>"Logged In#{rodauth.last_account_activity_at.strftime('%m%d%y')}"}
173
- rodauth.update_last_activity
174
- r.rodauth
175
- r.root{view :content=>rodauth.logged_in? ? "Logged In#{rodauth.last_account_activity_at.strftime('%m%d%y')}" : 'Not Logged'}
176
- end
177
-
178
- now = Time.now
179
- login
180
- page.body.must_include "Logged In#{now.strftime('%m%d%y')}"
181
-
182
- DB[:account_activity_times].count.must_equal 1
183
- DB[:account_activity_times].delete
184
-
185
- visit '/'
186
- DB[:account_activity_times].count.must_equal 1
187
-
188
- t1 = now - 179*86400
189
- DB[:account_activity_times].update(:last_activity_at => t1)
190
- visit '/a'
191
- page.body.must_include "Logged In#{t1.strftime('%m%d%y')}"
192
-
193
- logout
194
-
195
- t2 = now - 181*86400
196
- DB[:account_activity_times].update(:last_activity_at => t2).must_equal 1
197
-
198
- login
199
- page.body.must_include 'Not Logged'
200
- page.find('#error_flash').text.must_equal "Account expired on #{now.strftime('%m%d%y')}"
201
-
202
- DB[:account_activity_times].update(:expired_at=>t1).must_equal 1
203
-
204
- login
205
- page.body.must_include 'Not Logged'
206
- page.find('#error_flash').text.must_equal "Account expired on #{t1.strftime('%m%d%y')}"
207
- end
208
-
209
- it "should remove account activity data when closing accounts" do
210
- rodauth do
211
- enable :login, :close_account, :account_expiration
212
- close_account_requires_password? false
213
- end
214
- roda do |r|
215
- r.rodauth
216
- r.root{view :content=>rodauth.logged_in? ? "Logged In#{rodauth.last_account_login_at.strftime('%m%d%y')}" : "Not Logged"}
217
- end
218
-
219
- login
220
- DB[:account_activity_times].count.must_equal 1
221
- visit '/close-account'
222
- click_button 'Close Account'
223
- DB[:account_activity_times].count.must_equal 0
224
- end
225
- end
@@ -1 +0,0 @@
1
- Dir['./spec/*_spec.rb'].each{|f| require f}
@@ -1,156 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth change_login feature' do
4
- it "should support changing logins for accounts" do
5
- DB[:accounts].insert(:email=>'foo2@example.com')
6
- require_password = false
7
- require_email = true
8
-
9
- rodauth do
10
- enable :login, :logout, :change_login
11
- change_login_requires_password?{require_password}
12
- require_email_address_logins?{require_email}
13
- end
14
- roda do |r|
15
- r.rodauth
16
- r.root{view :content=>""}
17
- end
18
-
19
- login
20
- page.current_path.must_equal '/'
21
-
22
- visit '/change-login'
23
- page.title.must_equal 'Change Login'
24
-
25
- fill_in 'Login', :with=>'foobar'
26
- fill_in 'Confirm Login', :with=>'foobar'
27
- click_button 'Change Login'
28
- page.find('#error_flash').text.must_equal "There was an error changing your login"
29
- page.html.must_include("invalid login, not a valid email address")
30
- page.current_path.must_equal '/change-login'
31
-
32
- require_email = false
33
-
34
- fill_in 'Login', :with=>'fb'
35
- fill_in 'Confirm Login', :with=>'fb'
36
- click_button 'Change Login'
37
- page.find('#error_flash').text.must_equal "There was an error changing your login"
38
- page.html.must_include("invalid login, minimum 3 characters")
39
- page.current_path.must_equal '/change-login'
40
-
41
- fill_in 'Login', :with=>'f'*256
42
- fill_in 'Confirm Login', :with=>'f'*256
43
- click_button 'Change Login'
44
- page.find('#error_flash').text.must_equal "There was an error changing your login"
45
- page.html.must_include("invalid login, maximum 255 characters")
46
- page.current_path.must_equal '/change-login'
47
-
48
- fill_in 'Login', :with=>'foo@example.com'
49
- fill_in 'Confirm Login', :with=>'foo2@example.com'
50
- click_button 'Change Login'
51
- page.find('#error_flash').text.must_equal "There was an error changing your login"
52
- page.html.must_include("logins do not match")
53
- page.current_path.must_equal '/change-login'
54
-
55
- fill_in 'Login', :with=>'foo2@example.com'
56
- click_button 'Change Login'
57
- page.find('#error_flash').text.must_equal "There was an error changing your login"
58
- page.html.must_include("invalid login, already an account with this login")
59
- page.current_path.must_equal '/change-login'
60
-
61
- fill_in 'Login', :with=>'foo@example.com'
62
- fill_in 'Confirm Login', :with=>'foo@example.com'
63
- click_button 'Change Login'
64
- page.find('#error_flash').text.must_equal "There was an error changing your login"
65
- page.html.must_include("invalid login, same as current login")
66
- page.current_path.must_equal '/change-login'
67
-
68
- fill_in 'Login', :with=>'foo3@example.com'
69
- fill_in 'Confirm Login', :with=>'foo3@example.com'
70
- click_button 'Change Login'
71
- page.find('#notice_flash').text.must_equal "Your login has been changed"
72
- page.current_path.must_equal '/'
73
-
74
- logout
75
- login(:login=>'foo3@example.com')
76
- page.current_path.must_equal '/'
77
-
78
- require_password = true
79
- visit '/change-login'
80
- fill_in 'Password', :with=>'012345678'
81
- fill_in 'Login', :with=>'foo4@example.com'
82
- fill_in 'Confirm Login', :with=>'foo4@example.com'
83
- click_button 'Change Login'
84
- page.find('#error_flash').text.must_equal "There was an error changing your login"
85
- page.html.must_include("invalid password")
86
- page.current_path.must_equal '/change-login'
87
-
88
- fill_in 'Password', :with=>'0123456789'
89
- click_button 'Change Login'
90
- page.find('#notice_flash').text.must_equal "Your login has been changed"
91
- page.current_path.must_equal '/'
92
-
93
- logout
94
- login(:login=>'foo4@example.com')
95
- page.current_path.must_equal '/'
96
- end
97
-
98
- it "should support changing logins for accounts with login confirmation" do
99
- rodauth do
100
- enable :login, :change_login
101
- change_login_requires_password? false
102
- require_login_confirmation? false
103
- end
104
- roda do |r|
105
- r.rodauth
106
- r.root{view :content=>""}
107
- end
108
-
109
- login
110
- visit '/change-login'
111
- fill_in 'Login', :with=>'foo3@example.com'
112
- click_button 'Change Login'
113
- page.find('#notice_flash').text.must_equal "Your login has been changed"
114
- end
115
-
116
- it "should support changing logins via jwt" do
117
- DB[:accounts].insert(:email=>'foo2@example.com')
118
- require_password = false
119
-
120
- rodauth do
121
- enable :login, :logout, :change_login
122
- change_login_requires_password?{require_password}
123
- end
124
- roda(:jwt) do |r|
125
- r.rodauth
126
- end
127
-
128
- json_login
129
-
130
- res = json_request('/change-login', :login=>'foobar', "login-confirm"=>'foobar')
131
- res.must_equal [422, {'error'=>"There was an error changing your login", "field-error"=>["login", "invalid login, not a valid email address"]}]
132
-
133
- res = json_request('/change-login', :login=>'foo@example.com', "login-confirm"=>'foo2@example.com')
134
- res.must_equal [422, {'error'=>"There was an error changing your login", "field-error"=>["login", "logins do not match"]}]
135
-
136
- res = json_request('/change-login', :login=>'foo2@example.com', "login-confirm"=>'foo2@example.com')
137
- res.must_equal [422, {'error'=>"There was an error changing your login", "field-error"=>["login", "invalid login, already an account with this login"]}]
138
-
139
- res = json_request('/change-login', :login=>'foo3@example.com', "login-confirm"=>'foo3@example.com')
140
- res.must_equal [200, {'success'=>"Your login has been changed"}]
141
-
142
- json_logout
143
- json_login(:login=>'foo3@example.com')
144
-
145
- require_password = true
146
-
147
- res = json_request('/change-login', :login=>'foo4@example.com', "login-confirm"=>'foo4@example.com', :password=>'012345678')
148
- res.must_equal [401, {'error'=>"There was an error changing your login", "field-error"=>["password", "invalid password"]}]
149
-
150
- res = json_request('/change-login', :login=>'foo4@example.com', "login-confirm"=>'foo4@example.com', :password=>'0123456789')
151
- res.must_equal [200, {'success'=>"Your login has been changed"}]
152
-
153
- json_logout
154
- json_login(:login=>'foo4@example.com')
155
- end
156
- end