add fix script for user names

This commit is contained in:
r888888888
2017-03-06 16:56:23 -08:00
parent 51c752be2f
commit 26267cd238
2 changed files with 14 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
class UserNameValidator < ActiveModel::EachValidator
def validate_each(rec, attr, value)
name = value
rec.errors[attr] << "already exists" if User.find_by_name(name).present?
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/