2013-09-06 05:35:29 -04:00
|
|
|
class UsernameCheckerService
|
|
|
|
|
|
|
|
def check_username(username, email)
|
2013-11-19 14:15:05 -05:00
|
|
|
if username && username.length > 0
|
|
|
|
validator = UsernameValidator.new(username)
|
|
|
|
if !validator.valid_format?
|
|
|
|
{errors: validator.errors}
|
|
|
|
else
|
2014-07-16 12:25:24 -04:00
|
|
|
check_username_availability(username)
|
2013-11-19 14:15:05 -05:00
|
|
|
end
|
2013-09-06 05:35:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-16 12:25:24 -04:00
|
|
|
def check_username_availability(username)
|
2013-09-06 05:35:29 -04:00
|
|
|
if User.username_available?(username)
|
|
|
|
{ available: true }
|
|
|
|
else
|
|
|
|
{ available: false, suggestion: UserNameSuggester.suggest(username) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|