2014-06-12 02:42:41 +08:00
|
|
|
class UsernameSettingValidator
|
2017-10-05 03:08:51 +08:00
|
|
|
|
|
|
|
include RegexSettingValidation
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def initialize(opts = {})
|
2014-06-13 06:03:03 +08:00
|
|
|
@opts = opts
|
2017-10-05 03:08:51 +08:00
|
|
|
initialize_regex_opts(opts)
|
2014-06-13 06:03:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_value?(val)
|
2017-10-05 03:08:51 +08:00
|
|
|
!val.present? || (User.where(username: val).exists? && regex_match?(val))
|
2014-06-12 02:42:41 +08:00
|
|
|
end
|
|
|
|
|
2014-06-18 22:49:21 +08:00
|
|
|
def error_message
|
2017-10-05 03:08:51 +08:00
|
|
|
if @regex_fail
|
|
|
|
I18n.t(@regex_error)
|
|
|
|
else
|
|
|
|
I18n.t('site_settings.errors.invalid_username')
|
|
|
|
end
|
2014-06-12 02:42:41 +08:00
|
|
|
end
|
|
|
|
end
|