mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-25 08:39:38 -05:00
22 lines
524 B
Ruby
22 lines
524 B
Ruby
class UsernameCheckerService
|
|
|
|
def check_username(username, email)
|
|
if username && username.length > 0
|
|
validator = UsernameValidator.new(username)
|
|
if !validator.valid_format?
|
|
{errors: validator.errors}
|
|
else
|
|
check_username_availability(username)
|
|
end
|
|
end
|
|
end
|
|
|
|
def check_username_availability(username)
|
|
if User.username_available?(username)
|
|
{ available: true }
|
|
else
|
|
{ available: false, suggestion: UserNameSuggester.suggest(username) }
|
|
end
|
|
end
|
|
|
|
end
|