Add age verification on sign-up (#34150)
This commit is contained in:
parent
4a6cf67c46
commit
d213c585ff
18 changed files with 268 additions and 38 deletions
15
app/validators/date_of_birth_validator.rb
Normal file
15
app/validators/date_of_birth_validator.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DateOfBirthValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
record.errors.add(attribute, :below_limit) if value.present? && value.to_date > min_age.ago
|
||||
rescue Date::Error
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def min_age
|
||||
Setting.min_age.to_i.years
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue