discourse/app/services/username_checker_service.rb

23 lines
524 B
Ruby
Raw Normal View History

class UsernameCheckerService
def check_username(username, email)
if username && username.length > 0
validator = UsernameValidator.new(username)
if !validator.valid_format?
{errors: validator.errors}
else
2014-07-17 00:25:24 +08:00
check_username_availability(username)
end
end
end
2014-07-17 00:25:24 +08:00
def check_username_availability(username)
if User.username_available?(username)
{ available: true }
else
{ available: false, suggestion: UserNameSuggester.suggest(username) }
end
end
end