rodauth 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -0
  3. data/README.rdoc +5 -3
  4. data/doc/email_base.rdoc +1 -0
  5. data/doc/release_notes/1.23.0.txt +32 -0
  6. data/lib/rodauth.rb +5 -2
  7. data/lib/rodauth/features/base.rb +8 -0
  8. data/lib/rodauth/features/change_password_notify.rb +1 -1
  9. data/lib/rodauth/features/create_account.rb +1 -1
  10. data/lib/rodauth/features/email_auth.rb +3 -4
  11. data/lib/rodauth/features/email_base.rb +7 -2
  12. data/lib/rodauth/features/lockout.rb +1 -1
  13. data/lib/rodauth/features/login.rb +6 -2
  14. data/lib/rodauth/features/otp.rb +6 -3
  15. data/lib/rodauth/features/password_expiration.rb +1 -1
  16. data/lib/rodauth/features/recovery_codes.rb +3 -3
  17. data/lib/rodauth/features/reset_password.rb +2 -2
  18. data/lib/rodauth/features/sms_codes.rb +5 -5
  19. data/lib/rodauth/features/verify_account.rb +2 -2
  20. data/lib/rodauth/features/verify_login_change.rb +1 -1
  21. data/lib/rodauth/version.rb +1 -1
  22. data/templates/email-auth-request-form.str +2 -2
  23. data/templates/reset-password-request.str +3 -3
  24. data/templates/unlock-account-request.str +3 -3
  25. data/templates/verify-account-resend.str +3 -3
  26. metadata +5 -43
  27. data/Rakefile +0 -179
  28. data/spec/account_expiration_spec.rb +0 -225
  29. data/spec/all.rb +0 -1
  30. data/spec/change_login_spec.rb +0 -156
  31. data/spec/change_password_notify_spec.rb +0 -33
  32. data/spec/change_password_spec.rb +0 -202
  33. data/spec/close_account_spec.rb +0 -162
  34. data/spec/confirm_password_spec.rb +0 -70
  35. data/spec/create_account_spec.rb +0 -127
  36. data/spec/disallow_common_passwords_spec.rb +0 -93
  37. data/spec/disallow_password_reuse_spec.rb +0 -179
  38. data/spec/email_auth_spec.rb +0 -285
  39. data/spec/http_basic_auth_spec.rb +0 -143
  40. data/spec/jwt_cors_spec.rb +0 -57
  41. data/spec/jwt_refresh_spec.rb +0 -256
  42. data/spec/jwt_spec.rb +0 -235
  43. data/spec/lockout_spec.rb +0 -250
  44. data/spec/login_spec.rb +0 -328
  45. data/spec/migrate/001_tables.rb +0 -184
  46. data/spec/migrate/002_account_password_hash_column.rb +0 -11
  47. data/spec/migrate_password/001_tables.rb +0 -73
  48. data/spec/migrate_travis/001_tables.rb +0 -141
  49. data/spec/password_complexity_spec.rb +0 -109
  50. data/spec/password_expiration_spec.rb +0 -244
  51. data/spec/password_grace_period_spec.rb +0 -93
  52. data/spec/remember_spec.rb +0 -451
  53. data/spec/reset_password_spec.rb +0 -229
  54. data/spec/rodauth_spec.rb +0 -343
  55. data/spec/session_expiration_spec.rb +0 -58
  56. data/spec/single_session_spec.rb +0 -127
  57. data/spec/spec_helper.rb +0 -327
  58. data/spec/two_factor_spec.rb +0 -1462
  59. data/spec/update_password_hash_spec.rb +0 -40
  60. data/spec/verify_account_grace_period_spec.rb +0 -171
  61. data/spec/verify_account_spec.rb +0 -240
  62. data/spec/verify_change_login_spec.rb +0 -46
  63. data/spec/verify_login_change_spec.rb +0 -232
  64. data/spec/views/layout-other.str +0 -11
  65. data/spec/views/layout.str +0 -11
  66. data/spec/views/login.str +0 -21
@@ -1,127 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth create_account feature' do
4
- [false, true].each do |ph|
5
- it "should support creating accounts #{'with account_password_hash_column' if ph}" do
6
- rodauth do
7
- enable :login, :create_account
8
- account_password_hash_column :ph if ph
9
- create_account_autologin? false
10
- end
11
- roda do |r|
12
- r.rodauth
13
- r.root{view :content=>""}
14
- end
15
-
16
- visit '/create-account'
17
- fill_in 'Login', :with=>'foo@example.com'
18
- fill_in 'Confirm Login', :with=>'foo@example.com'
19
- fill_in 'Password', :with=>'0123456789'
20
- fill_in 'Confirm Password', :with=>'0123456789'
21
- click_button 'Create Account'
22
- page.html.must_include("invalid login, already an account with this login")
23
- page.find('#error_flash').text.must_equal "There was an error creating your account"
24
- page.current_path.must_equal '/create-account'
25
-
26
- fill_in 'Login', :with=>'foobar'
27
- fill_in 'Confirm Login', :with=>'foobar'
28
- fill_in 'Password', :with=>'0123456789'
29
- fill_in 'Confirm Password', :with=>'0123456789'
30
- click_button 'Create Account'
31
- page.html.must_include("invalid login, not a valid email address")
32
- page.find('#error_flash').text.must_equal "There was an error creating your account"
33
- page.current_path.must_equal '/create-account'
34
-
35
- fill_in 'Login', :with=>'foo@example2.com'
36
- fill_in 'Password', :with=>'0123456789'
37
- fill_in 'Confirm Password', :with=>'0123456789'
38
- click_button 'Create Account'
39
- page.html.must_include("logins do not match")
40
- page.find('#error_flash').text.must_equal "There was an error creating your account"
41
- page.current_path.must_equal '/create-account'
42
-
43
- fill_in 'Confirm Login', :with=>'foo@example2.com'
44
- fill_in 'Password', :with=>'0123456789'
45
- fill_in 'Confirm Password', :with=>'012345678'
46
- click_button 'Create Account'
47
- page.html.must_include("passwords do not match")
48
- page.find('#error_flash').text.must_equal "There was an error creating your account"
49
- page.current_path.must_equal '/create-account'
50
-
51
- fill_in 'Password', :with=>'0123456789'
52
- fill_in 'Confirm Password', :with=>'0123456789'
53
- click_button 'Create Account'
54
- page.find('#notice_flash').text.must_equal "Your account has been created"
55
- page.current_path.must_equal '/'
56
-
57
- login(:login=>'foo@example2.com')
58
- page.current_path.must_equal '/'
59
- end
60
- end
61
-
62
- it "should support creating accounts without login/password confirmation" do
63
- rodauth do
64
- enable :login, :create_account
65
- require_login_confirmation? false
66
- require_password_confirmation? false
67
- create_account_autologin? false
68
- end
69
- roda do |r|
70
- r.rodauth
71
- r.root{view :content=>""}
72
- end
73
-
74
- visit '/create-account'
75
- fill_in 'Login', :with=>'foo@example2.com'
76
- fill_in 'Password', :with=>'0123456789'
77
- click_button 'Create Account'
78
- page.find('#notice_flash').text.must_equal "Your account has been created"
79
- end
80
-
81
- it "should support autologin after account creation" do
82
- rodauth do
83
- enable :create_account
84
- end
85
- roda do |r|
86
- r.rodauth
87
- next unless rodauth.logged_in?
88
- r.root{view :content=>"Logged In: #{DB[:accounts].where(:id=>rodauth.session_value).get(:email)}"}
89
- end
90
-
91
- visit '/create-account'
92
- fill_in 'Login', :with=>'foo2@example.com'
93
- fill_in 'Confirm Login', :with=>'foo2@example.com'
94
- fill_in 'Password', :with=>'apple2'
95
- fill_in 'Confirm Password', :with=>'apple2'
96
- click_button 'Create Account'
97
- page.html.must_include("Logged In: foo2@example.com")
98
- end
99
-
100
- it "should support creating accounts via jwt" do
101
- rodauth do
102
- enable :login, :create_account
103
- after_create_account{json_response[:account_id] = account_id}
104
- create_account_autologin? false
105
- end
106
- roda(:jwt) do |r|
107
- r.rodauth
108
- end
109
-
110
- res = json_request('/create-account', :login=>'foo@example.com', "login-confirm"=>'foo@example.com', :password=>'0123456789', "password-confirm"=>'0123456789')
111
- res.must_equal [422, {'error'=>"There was an error creating your account", "field-error"=>["login", "invalid login, already an account with this login"]}]
112
-
113
- res = json_request('/create-account', :login=>'foobar', "login-confirm"=>'foobar', :password=>'0123456789', "password-confirm"=>'0123456789')
114
- res.must_equal [422, {'error'=>"There was an error creating your account", "field-error"=>["login", "invalid login, not a valid email address"]}]
115
-
116
- res = json_request('/create-account', :login=>'foo@example2.com', "login-confirm"=>'foobar', :password=>'0123456789', "password-confirm"=>'0123456789')
117
- res.must_equal [422, {'error'=>"There was an error creating your account", "field-error"=>["login", "logins do not match"]}]
118
-
119
- res = json_request('/create-account', :login=>'foo@example2.com', "login-confirm"=>'foo@example2.com', :password=>'012345678', "password-confirm"=>'0123456789')
120
- res.must_equal [422, {'error'=>"There was an error creating your account", "field-error"=>["password", "passwords do not match"]}]
121
-
122
- res = json_request('/create-account', :login=>'foo@example2.com', "login-confirm"=>'foo@example2.com', :password=>'0123456789', "password-confirm"=>'0123456789')
123
- res.must_equal [200, {'success'=>"Your account has been created", 'account_id'=>DB[:accounts].max(:id)}]
124
-
125
- json_login(:login=>'foo@example2.com')
126
- end
127
- end
@@ -1,93 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth disallow common passwords feature' do
4
- it "should check that password used is not one of the most common" do
5
- rodauth do
6
- enable :login, :change_password, :disallow_common_passwords
7
- change_password_requires_password? false
8
- password_minimum_length 1
9
- end
10
- roda do |r|
11
- r.rodauth
12
- r.root{view :content=>""}
13
- end
14
-
15
- login
16
- page.current_path.must_equal '/'
17
-
18
- visit '/change-password'
19
-
20
- bad_password_file = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'dict', 'top-10_000-passwords.txt')
21
- (File.read(bad_password_file).split.shuffle - ['0123456789']).take(5).each do |pass|
22
- fill_in 'New Password', :with=>pass
23
- fill_in 'Confirm Password', :with=>pass
24
- click_button 'Change Password'
25
- page.html.must_include("invalid password, does not meet requirements (is one of the most common passwords)")
26
- page.find('#error_flash').text.must_equal "There was an error changing your password"
27
- end
28
-
29
- fill_in 'New Password', :with=>'footpassword'
30
- fill_in 'Confirm Password', :with=>'footpassword'
31
- click_button 'Change Password'
32
- page.find('#notice_flash').text.must_equal "Your password has been changed"
33
- end
34
-
35
- it "should check that password used is not one of the most common with custom password set" do
36
- rodauth do
37
- enable :login, :change_password, :disallow_common_passwords
38
- change_password_requires_password? false
39
- most_common_passwords ['foobarbaz']
40
- end
41
- roda do |r|
42
- r.rodauth
43
- r.root{view :content=>""}
44
- end
45
-
46
- login
47
- page.current_path.must_equal '/'
48
-
49
- visit '/change-password'
50
-
51
- fill_in 'New Password', :with=>'foobarbaz'
52
- fill_in 'Confirm Password', :with=>'foobarbaz'
53
- click_button 'Change Password'
54
- page.html.must_include("invalid password, does not meet requirements (is one of the most common passwords)")
55
- page.find('#error_flash').text.must_equal "There was an error changing your password"
56
-
57
- fill_in 'New Password', :with=>'footpassword'
58
- fill_in 'Confirm Password', :with=>'footpassword'
59
- click_button 'Change Password'
60
- page.find('#notice_flash').text.must_equal "Your password has been changed"
61
- end
62
-
63
- it "should check that password used is not one of the most common with custom check" do
64
- rodauth do
65
- enable :login, :change_password, :disallow_common_passwords
66
- change_password_requires_password? false
67
- most_common_passwords_file nil
68
- password_one_of_most_common? do |password|
69
- password == 'foobarbaz'
70
- end
71
- end
72
- roda do |r|
73
- r.rodauth
74
- r.root{view :content=>""}
75
- end
76
-
77
- login
78
- page.current_path.must_equal '/'
79
-
80
- visit '/change-password'
81
-
82
- fill_in 'New Password', :with=>'foobarbaz'
83
- fill_in 'Confirm Password', :with=>'foobarbaz'
84
- click_button 'Change Password'
85
- page.html.must_include("invalid password, does not meet requirements (is one of the most common passwords)")
86
- page.find('#error_flash').text.must_equal "There was an error changing your password"
87
-
88
- fill_in 'New Password', :with=>'footpassword'
89
- fill_in 'Confirm Password', :with=>'footpassword'
90
- click_button 'Change Password'
91
- page.find('#notice_flash').text.must_equal "Your password has been changed"
92
- end
93
- end
@@ -1,179 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth disallow_password_reuse feature' do
4
- it "should disallow reuse of passwords" do
5
- table = :account_previous_password_hashes
6
- rodauth do
7
- enable :login, :change_password, :disallow_password_reuse, :close_account
8
- if ENV['RODAUTH_SEPARATE_SCHEMA']
9
- table = Sequel[:rodauth_test_password][:account_previous_password_hashes]
10
- previous_password_hash_table table
11
- end
12
- change_password_requires_password? false
13
- close_account_requires_password? false
14
- end
15
- roda do |r|
16
- r.rodauth
17
- r.root{view :content=>""}
18
- end
19
-
20
- login
21
- page.current_path.must_equal '/'
22
-
23
- 8.times do |i|
24
- visit '/change-password'
25
- fill_in 'New Password', :with=>"password#{i}"
26
- fill_in 'Confirm Password', :with=>"password#{i}"
27
- click_button 'Change Password'
28
- page.find('#notice_flash').text.must_equal "Your password has been changed"
29
- end
30
-
31
- visit '/change-password'
32
-
33
- (1..6).each do |i|
34
- fill_in 'New Password', :with=>"password#{i}"
35
- fill_in 'Confirm Password', :with=>"password#{i}"
36
- click_button 'Change Password'
37
- page.html.must_include("invalid password, does not meet requirements (same as previous password)")
38
- page.find('#error_flash').text.must_equal "There was an error changing your password"
39
- end
40
-
41
- fill_in 'New Password', :with=>"password7"
42
- fill_in 'Confirm Password', :with=>"password7"
43
- click_button 'Change Password'
44
- page.html.must_include("invalid password, same as current password")
45
-
46
- fill_in 'New Password', :with=>'password0'
47
- fill_in 'Confirm Password', :with=>'password0'
48
- click_button 'Change Password'
49
- page.find('#notice_flash').text.must_equal "Your password has been changed"
50
-
51
- DB[table].get{count(:id)}.must_equal 7
52
- visit '/close-account'
53
- click_button 'Close Account'
54
- DB[table].get{count(:id)}.must_equal 0
55
- end
56
-
57
- [true, false].each do |ph|
58
- it "should handle create account when account_password_hash_column is #{ph}" do
59
- rodauth do
60
- enable :login, :create_account, :change_password, :disallow_password_reuse
61
- if ENV['RODAUTH_SEPARATE_SCHEMA']
62
- previous_password_hash_table Sequel[:rodauth_test_password][:account_previous_password_hashes]
63
- end
64
- account_password_hash_column :ph if ph
65
- change_password_requires_password? false
66
- end
67
- roda do |r|
68
- r.rodauth
69
- r.root{view :content=>""}
70
- end
71
-
72
- visit '/create-account'
73
- fill_in 'Login', :with=>'bar@example.com'
74
- fill_in 'Confirm Login', :with=>'bar@example.com'
75
- fill_in 'Password', :with=>'0123456789'
76
- fill_in 'Confirm Password', :with=>'0123456789'
77
- click_button 'Create Account'
78
- page.current_path.must_equal '/'
79
- page.find('#notice_flash').text.must_equal "Your account has been created"
80
-
81
- visit '/change-password'
82
- fill_in 'New Password', :with=>"012345678"
83
- fill_in 'Confirm Password', :with=>"012345678"
84
- click_button 'Change Password'
85
- page.find('#notice_flash').text.must_equal "Your password has been changed"
86
-
87
- visit '/change-password'
88
- fill_in 'New Password', :with=>"0123456789"
89
- fill_in 'Confirm Password', :with=>"0123456789"
90
- click_button 'Change Password'
91
- page.html.must_include("invalid password, does not meet requirements (same as previous password)")
92
- end
93
-
94
- it "should handle verify account when account_password_hash_column is #{ph}" do
95
- rodauth do
96
- enable :login, :verify_account, :change_password, :disallow_password_reuse
97
- if ENV['RODAUTH_SEPARATE_SCHEMA']
98
- previous_password_hash_table Sequel[:rodauth_test_password][:account_previous_password_hashes]
99
- end
100
- account_password_hash_column :ph if ph
101
- change_password_requires_password? false
102
- end
103
- roda do |r|
104
- r.rodauth
105
- r.root{view :content=>""}
106
- end
107
-
108
- visit '/create-account'
109
- fill_in 'Login', :with=>'bar@example.com'
110
- fill_in 'Confirm Login', :with=>'bar@example.com'
111
- fill_in 'Password', :with=>'0123456789'
112
- fill_in 'Confirm Password', :with=>'0123456789'
113
- click_button 'Create Account'
114
- page.current_path.must_equal '/'
115
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
116
- link = email_link(/(\/verify-account\?key=.+)$/, 'bar@example.com')
117
-
118
- visit link
119
- click_button 'Verify Account'
120
- page.find('#notice_flash').text.must_equal "Your account has been verified"
121
- page.current_path.must_equal '/'
122
-
123
- visit '/change-password'
124
- fill_in 'New Password', :with=>"012345678"
125
- fill_in 'Confirm Password', :with=>"012345678"
126
- click_button 'Change Password'
127
- page.find('#notice_flash').text.must_equal "Your password has been changed"
128
-
129
- visit '/change-password'
130
- fill_in 'New Password', :with=>"0123456789"
131
- fill_in 'Confirm Password', :with=>"0123456789"
132
- click_button 'Change Password'
133
- page.html.must_include("invalid password, does not meet requirements (same as previous password)")
134
- end
135
-
136
- it "should handle verify account when account_password_hash_column is #{ph} and verify_account_set_password? is true" do
137
- rodauth do
138
- enable :login, :verify_account, :change_password, :disallow_password_reuse
139
- if ENV['RODAUTH_SEPARATE_SCHEMA']
140
- previous_password_hash_table Sequel[:rodauth_test_password][:account_previous_password_hashes]
141
- end
142
- account_password_hash_column :ph if ph
143
- change_password_requires_password? false
144
- verify_account_set_password? true
145
- end
146
- roda do |r|
147
- r.rodauth
148
- r.root{view :content=>""}
149
- end
150
-
151
- visit '/create-account'
152
- fill_in 'Login', :with=>'bar@example.com'
153
- fill_in 'Confirm Login', :with=>'bar@example.com'
154
- click_button 'Create Account'
155
- page.current_path.must_equal '/'
156
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
157
- link = email_link(/(\/verify-account\?key=.+)$/, 'bar@example.com')
158
-
159
- visit link
160
- fill_in 'Password', :with=>'0123456789'
161
- fill_in 'Confirm Password', :with=>'0123456789'
162
- click_button 'Verify Account'
163
- page.find('#notice_flash').text.must_equal "Your account has been verified"
164
- page.current_path.must_equal '/'
165
-
166
- visit '/change-password'
167
- fill_in 'New Password', :with=>"012345678"
168
- fill_in 'Confirm Password', :with=>"012345678"
169
- click_button 'Change Password'
170
- page.find('#notice_flash').text.must_equal "Your password has been changed"
171
-
172
- visit '/change-password'
173
- fill_in 'New Password', :with=>"0123456789"
174
- fill_in 'Confirm Password', :with=>"0123456789"
175
- click_button 'Change Password'
176
- page.html.must_include("invalid password, does not meet requirements (same as previous password)")
177
- end
178
- end
179
- end
@@ -1,285 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth email auth feature' do
4
- it "should support logging in use link sent via email, without a password for the account" do
5
- rodauth do
6
- enable :login, :email_auth, :logout
7
- account_password_hash_column :ph
8
- end
9
- roda do |r|
10
- r.rodauth
11
- r.root{view :content=>""}
12
- end
13
-
14
- DB[:accounts].update(:ph=>nil).must_equal 1
15
-
16
- visit '/login'
17
- fill_in 'Login', :with=>'foo2@example.com'
18
- click_button 'Login'
19
- page.find('#error_flash').text.must_equal 'There was an error logging in'
20
- page.html.must_include("no matching login")
21
-
22
- fill_in 'Login', :with=>'foo@example.com'
23
- click_button 'Login'
24
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to login to your account"
25
- page.current_path.must_equal '/'
26
- link = email_link(/(\/email-auth\?key=.+)$/)
27
-
28
- visit link[0...-1]
29
- page.find('#error_flash').text.must_equal "There was an error logging you in: invalid email authentication key"
30
-
31
- visit '/login'
32
- fill_in 'Login', :with=>'foo@example.com'
33
- click_button 'Login'
34
- page.find('#error_flash').text.must_equal "An email has recently been sent to you with a link to login"
35
- Mail::TestMailer.deliveries.must_equal []
36
-
37
- DB[:account_email_auth_keys].update(:email_last_sent => Time.now - 250).must_equal 1
38
- visit '/login'
39
- fill_in 'Login', :with=>'foo@example.com'
40
- click_button 'Login'
41
- page.find('#error_flash').text.must_equal "An email has recently been sent to you with a link to login"
42
- Mail::TestMailer.deliveries.must_equal []
43
-
44
- DB[:account_email_auth_keys].update(:email_last_sent => Time.now - 350).must_equal 1
45
- visit '/login'
46
- fill_in 'Login', :with=>'foo@example.com'
47
- click_button 'Login'
48
- email_link(/(\/email-auth\?key=.+)$/).must_equal link
49
-
50
- visit link
51
- page.title.must_equal 'Login'
52
- click_button 'Login'
53
- page.find('#notice_flash').text.must_equal 'You have been logged in'
54
- page.current_path.must_equal '/'
55
-
56
- logout
57
-
58
- visit link
59
- visit '/login'
60
- fill_in 'Login', :with=>'foo@example.com'
61
- click_button 'Login'
62
-
63
- link2 = email_link(/(\/email-auth\?key=.+)$/)
64
- link2.wont_equal link
65
-
66
- visit link2
67
- DB[:account_email_auth_keys].update(:deadline => Time.now - 60).must_equal 1
68
- click_button 'Login'
69
- page.find('#error_flash').text.must_equal "There was an error logging you in"
70
- page.current_path.must_equal '/'
71
- DB[:account_email_auth_keys].count.must_equal 0
72
-
73
- visit '/login'
74
- fill_in 'Login', :with=>'foo@example.com'
75
- click_button 'Login'
76
-
77
- visit email_link(/(\/email-auth\?key=.+)$/)
78
- DB[:account_email_auth_keys].update(:key=>'1').must_equal 1
79
- click_button 'Login'
80
- page.find('#error_flash').text.must_equal "There was an error logging you in"
81
- page.current_path.must_equal '/'
82
- end
83
-
84
- it "should support logging in use link sent via email, with a password for the account" do
85
- rodauth do
86
- enable :login, :email_auth, :logout
87
- email_auth_email_last_sent_column nil
88
- end
89
- roda do |r|
90
- r.rodauth
91
- r.root{view :content=>""}
92
- end
93
-
94
- visit '/login'
95
- fill_in 'Login', :with=>'foo2@example.com'
96
- click_button 'Login'
97
- page.find('#error_flash').text.must_equal 'There was an error logging in'
98
- page.html.must_include("no matching login")
99
-
100
- fill_in 'Login', :with=>'foo@example.com'
101
- click_button 'Login'
102
- click_button 'Send Login Link Via Email'
103
- page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to login to your account"
104
- page.current_path.must_equal '/'
105
- link = email_link(/(\/email-auth\?key=.+)$/)
106
-
107
- visit link[0...-1]
108
- page.find('#error_flash').text.must_equal "There was an error logging you in: invalid email authentication key"
109
-
110
- visit '/login'
111
- fill_in 'Login', :with=>'foo@example.com'
112
- click_button 'Login'
113
- click_button 'Send Login Link Via Email'
114
- email_link(/(\/email-auth\?key=.+)$/).must_equal link
115
-
116
- visit link
117
- page.title.must_equal 'Login'
118
- click_button 'Login'
119
- page.find('#notice_flash').text.must_equal 'You have been logged in'
120
- page.current_path.must_equal '/'
121
-
122
- logout
123
-
124
- visit link
125
- visit '/login'
126
- fill_in 'Login', :with=>'foo@example.com'
127
- click_button 'Login'
128
- click_button 'Send Login Link Via Email'
129
-
130
- link2 = email_link(/(\/email-auth\?key=.+)$/)
131
- link2.wont_equal link
132
-
133
- visit link2
134
- DB[:account_email_auth_keys].update(:deadline => Time.now - 60).must_equal 1
135
- click_button 'Login'
136
- page.find('#error_flash').text.must_equal "There was an error logging you in"
137
- page.current_path.must_equal '/'
138
- DB[:account_email_auth_keys].count.must_equal 0
139
-
140
- visit '/login'
141
- fill_in 'Login', :with=>'foo@example.com'
142
- click_button 'Login'
143
- click_button 'Send Login Link Via Email'
144
-
145
- visit email_link(/(\/email-auth\?key=.+)$/)
146
- DB[:account_email_auth_keys].update(:key=>'1').must_equal 1
147
- click_button 'Login'
148
- page.find('#error_flash').text.must_equal "There was an error logging you in"
149
- page.current_path.must_equal '/'
150
- end
151
-
152
- it "should allow password login for accounts with password hashes" do
153
- rodauth do
154
- enable :login, :email_auth
155
- end
156
- roda do |r|
157
- r.rodauth
158
- next unless rodauth.logged_in?
159
- r.root{view :content=>"Logged In"}
160
- end
161
-
162
- visit '/login'
163
- page.title.must_equal 'Login'
164
- fill_in 'Login', :with=>'foo@example.com'
165
- click_button 'Login'
166
- page.html.must_include 'Send Login Link Via Email'
167
- fill_in 'Password', :with=>'0123456789'
168
- click_button 'Login'
169
- page.current_path.must_equal '/'
170
- page.find('#notice_flash').text.must_equal 'You have been logged in'
171
- end
172
-
173
- it "should work with creating accounts without setting passwords" do
174
- rodauth do
175
- enable :login, :create_account, :email_auth
176
- require_login_confirmation? false
177
- create_account_autologin? false
178
- create_account_set_password? false
179
- end
180
- roda do |r|
181
- r.rodauth
182
- r.root{view :content=>""}
183
- end
184
-
185
- visit '/create-account'
186
- fill_in 'Login', :with=>'foo@example2.com'
187
- click_button 'Create Account'
188
- page.find('#notice_flash').text.must_equal "Your account has been created"
189
-
190
- visit '/login'
191
- fill_in 'Login', :with=>'foo@example2.com'
192
- click_button 'Login'
193
- page.current_path.must_equal '/'
194
- visit email_link(/(\/email-auth\?key=.+)$/, 'foo@example2.com')
195
- page.title.must_equal 'Login'
196
- click_button 'Login'
197
- page.find('#notice_flash').text.must_equal 'You have been logged in'
198
- page.current_path.must_equal '/'
199
- end
200
-
201
- it "should clear email auth token when closing account" do
202
- rodauth do
203
- enable :login, :email_auth, :close_account
204
- end
205
- roda do |r|
206
- r.rodauth
207
- r.root{view :content=>rodauth.logged_in? ? "Logged In" : "Not Logged"}
208
- end
209
-
210
- visit '/login'
211
- page.title.must_equal 'Login'
212
- fill_in 'Login', :with=>'foo@example.com'
213
- click_button 'Login'
214
- click_button 'Send Login Link Via Email'
215
-
216
- hash = DB[:account_email_auth_keys].first
217
-
218
- visit email_link(/(\/email-auth\?key=.+)$/)
219
- click_button 'Login'
220
-
221
- DB[:account_email_auth_keys].count.must_equal 0
222
- DB[:account_email_auth_keys].insert(hash)
223
-
224
- visit '/close-account'
225
- fill_in 'Password', :with=>'0123456789'
226
- click_button 'Close Account'
227
- DB[:account_email_auth_keys].count.must_equal 0
228
- end
229
-
230
- it "should handle uniqueness errors raised when inserting email auth token" do
231
- rodauth do
232
- enable :login, :email_auth
233
- end
234
- roda do |r|
235
- def rodauth.raised_uniqueness_violation(*) super; true; end
236
- r.rodauth
237
- r.root{view :content=>""}
238
- end
239
-
240
- visit '/login'
241
- page.title.must_equal 'Login'
242
- fill_in 'Login', :with=>'foo@example.com'
243
- click_button 'Login'
244
- click_button 'Send Login Link Via Email'
245
- link = email_link(/(\/email-auth\?key=.+)$/)
246
-
247
- DB[:account_email_auth_keys].update(:email_last_sent => Time.now - 350).must_equal 1
248
- visit '/login'
249
- page.title.must_equal 'Login'
250
- fill_in 'Login', :with=>'foo@example.com'
251
- click_button 'Login'
252
- click_button 'Send Login Link Via Email'
253
- email_link(/(\/email-auth\?key=.+)$/).must_equal link
254
- end
255
-
256
- it "should support email auth for accounts via jwt" do
257
- rodauth do
258
- enable :login, :email_auth
259
- email_auth_email_body{email_auth_email_link}
260
- end
261
- roda(:jwt) do |r|
262
- r.rodauth
263
- end
264
-
265
- res = json_request('/email-auth-request')
266
- res.must_equal [401, {"error"=>"There was an error requesting an email link to authenticate"}]
267
-
268
- res = json_request('/email-auth-request', :login=>'foo@example2.com')
269
- res.must_equal [401, {"error"=>"There was an error requesting an email link to authenticate"}]
270
-
271
- res = json_request('/email-auth-request', :login=>'foo@example.com')
272
- res.must_equal [200, {"success"=>"An email has been sent to you with a link to login to your account"}]
273
-
274
- link = email_link(/key=.+$/)
275
- res = json_request('/email-auth')
276
- res.must_equal [401, {"error"=>"There was an error logging you in"}]
277
-
278
- res = json_request('/email-auth', :key=>link[4...-1])
279
- res.must_equal [401, {"error"=>"There was an error logging you in"}]
280
-
281
- res = json_request('/email-auth', :key=>link[4..-1])
282
- res.must_equal [200, {"success"=>"You have been logged in"}]
283
- end
284
- end
285
-