rodauth 0.10.0 → 1.0.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 (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
@@ -1,228 +0,0 @@
1
- class Roda
2
- module RodaPlugins
3
- module Rodauth
4
- VerifyAccount = Feature.define(:verify_account) do
5
- depends :login, :create_account
6
- route 'verify-account'
7
- notice_flash "Your account has been verified"
8
- view 'verify-account', 'Verify Account'
9
- additional_form_tags
10
- after
11
- button 'Verify Account'
12
- redirect
13
-
14
- auth_value_methods(
15
- :no_matching_verify_account_key_message,
16
- :verify_account_autologin?,
17
- :verify_account_email_subject,
18
- :verify_account_email_sent_redirect,
19
- :verify_account_email_sent_notice_flash,
20
- :verify_account_id_column,
21
- :verify_account_key_column,
22
- :verify_account_key_param,
23
- :verify_account_key_value,
24
- :verify_account_table
25
- )
26
- auth_methods(
27
- :account_from_verify_account_key,
28
- :create_verify_account_key,
29
- :create_verify_account_email,
30
- :remove_verify_account_key,
31
- :send_verify_account_email,
32
- :verify_account,
33
- :verify_account_email_body,
34
- :verify_account_email_link,
35
- :verify_account_key_insert_hash
36
- )
37
-
38
- get_block do |r, auth|
39
- if key = r[auth.verify_account_key_param]
40
- if auth._account_from_verify_account_key(key)
41
- auth.verify_account_view
42
- else
43
- auth.set_redirect_error_flash auth.no_matching_verify_account_key_message
44
- r.redirect auth.require_login_redirect
45
- end
46
- end
47
- end
48
-
49
- post_block do |r, auth|
50
- if login = r[auth.login_param]
51
- if auth._account_from_login(login.to_s) && !auth.open_account? && auth.verify_account_email_resend
52
- auth.set_notice_flash auth.verify_account_email_sent_notice_flash
53
- r.redirect auth.verify_account_email_sent_redirect
54
- end
55
- elsif key = r[auth.verify_account_key_param]
56
- if auth._account_from_verify_account_key(key.to_s)
57
- auth.transaction do
58
- auth.verify_account
59
- auth.remove_verify_account_key
60
- auth.after_verify_account
61
- end
62
- if auth.verify_account_autologin?
63
- auth.update_session
64
- end
65
- auth.set_notice_flash auth.verify_account_notice_flash
66
- r.redirect(auth.verify_account_redirect)
67
- end
68
- end
69
- end
70
-
71
- def before_login_attempt
72
- unless open_account?
73
- set_error_flash attempt_to_login_to_unverified_account_notice_message
74
- response.write resend_verify_account_view
75
- request.halt
76
- end
77
- super
78
- end
79
-
80
- def generate_verify_account_key_value
81
- @verify_account_key_value = random_key
82
- end
83
-
84
- def create_verify_account_key
85
- ds = db[verify_account_table].where(verify_account_id_column=>account_id_value)
86
- transaction do
87
- ds.insert(verify_account_key_insert_hash) if ds.empty?
88
- end
89
- end
90
-
91
- def verify_account_key_insert_hash
92
- {verify_account_id_column=>account_id_value, verify_account_key_column=>verify_account_key_value}
93
- end
94
-
95
- def remove_verify_account_key
96
- db[verify_account_table].where(verify_account_id_column=>account_id_value).delete
97
- end
98
-
99
- def verify_account
100
- account.set(account_status_id=>account_open_status_value).save_changes(:raise_on_failure=>true)
101
- end
102
-
103
- def verify_account_resend_additional_form_tags
104
- nil
105
- end
106
-
107
- def verify_account_resend_button
108
- 'Send Verification Email Again'
109
- end
110
-
111
- def verify_account_email_resend
112
- if @verify_account_key_value = db[verify_account_table].where(verify_account_id_column=>account_id_value).get(verify_account_key_column)
113
- send_verify_account_email
114
- true
115
- end
116
- end
117
-
118
- def attempt_to_create_unverified_account_notice_message
119
- "The account you tried to create is currently awaiting verification"
120
- end
121
-
122
- def attempt_to_login_to_unverified_account_notice_message
123
- "The account you tried to login with is currently awaiting verification"
124
- end
125
-
126
- def resend_verify_account_view
127
- view('verify-account-resend', 'Resend Verification Email')
128
- end
129
-
130
- def verify_account_email_sent_notice_flash
131
- "An email has been sent to you with a link to verify your account"
132
- end
133
-
134
- def create_account_notice_flash
135
- verify_account_email_sent_notice_flash
136
- end
137
-
138
- def after_create_account
139
- generate_verify_account_key_value
140
- create_verify_account_key
141
- send_verify_account_email
142
- end
143
-
144
- def new_account(login)
145
- if _account_from_login(login)
146
- set_error_flash attempt_to_create_unverified_account_notice_message
147
- response.write resend_verify_account_view
148
- request.halt
149
- end
150
- super
151
- end
152
-
153
- def no_matching_verify_account_key_message
154
- "invalid verify account key"
155
- end
156
-
157
- def _account_from_verify_account_key(key)
158
- @account = account_from_verify_account_key(key)
159
- end
160
-
161
- def account_from_verify_account_key(key)
162
- id, key = key.split('_', 2)
163
- id_column = verify_account_id_column
164
- ds = db[verify_account_table].
165
- select(id_column).
166
- where(id_column=>id, verify_account_key_column=>key)
167
- @account = account_model.where(account_status_id=>account_unverified_status_value, account_id=>ds).first
168
- end
169
-
170
- def verify_account_email_sent_redirect
171
- require_login_redirect
172
- end
173
-
174
- def verify_account_table
175
- :account_verification_keys
176
- end
177
-
178
- def verify_account_id_column
179
- :id
180
- end
181
-
182
- def verify_account_key_column
183
- :key
184
- end
185
-
186
- def account_initial_status_value
187
- account_unverified_status_value
188
- end
189
-
190
- attr_reader :verify_account_key_value
191
-
192
- def create_verify_account_email
193
- create_email(verify_account_email_subject, verify_account_email_body)
194
- end
195
-
196
- def send_verify_account_email
197
- create_verify_account_email.deliver!
198
- end
199
-
200
- def verify_account_email_body
201
- render('verify-account-email')
202
- end
203
-
204
- def verify_account_email_link
205
- "#{request.base_url}#{prefix}/#{verify_account_route}?#{verify_account_key_param}=#{account_id_value}_#{verify_account_key_value}"
206
- end
207
-
208
- def verify_account_email_subject
209
- 'Verify Account'
210
- end
211
-
212
- def verify_account_key_param
213
- 'key'
214
- end
215
-
216
- def verify_account_autologin?
217
- false
218
- end
219
-
220
- def after_close_account
221
- super
222
- db[verify_account_table].where(reset_password_id_column=>account_id_value).delete
223
- end
224
- end
225
- end
226
- end
227
- end
228
-