cartodb/lib/carto/password_validator.rb

25 lines
583 B
Ruby
Raw Normal View History

2020-06-15 10:58:47 +08:00
require_dependency 'carto/standard_password_strategy'
module Carto
class PasswordValidator
def initialize(strategy = Carto::StandardPasswordStrategy.new)
@strategy = strategy
end
def validate(password, password_confirmation, user = nil)
@strategy.validate(password, password_confirmation, user)
end
def formatted_error_message(errors)
return nil if errors.empty?
return errors.first if errors.size == 1
message = errors.first(errors.size - 1).join(', ')
message << " and #{errors.last}"
message
end
end
end