mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Move password validation into PasswordValidator
This commit is contained in:
12
lib/validators/password_validator.rb
Normal file
12
lib/validators/password_validator.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class PasswordValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
return unless record.password_required?
|
||||
if value.nil?
|
||||
record.errors.add(attribute, :blank)
|
||||
elsif value.length < 6
|
||||
record.errors.add(attribute, :too_short, count: 6)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user