Remove hub username integration

This commit is contained in:
Neil Lalonde
2014-07-16 12:25:24 -04:00
parent 01a68f8cc7
commit 939e8505a9
19 changed files with 77 additions and 676 deletions

View File

@@ -6,13 +6,10 @@ class UserActivator
@session = session
@cookies = cookies
@request = request
@settings = SiteSetting
@hub = DiscourseHub
@message = nil
end
def start
register_username
end
def finish
@@ -26,7 +23,7 @@ class UserActivator
end
def factory
if @settings.must_approve_users?
if SiteSetting.must_approve_users?
ApprovalActivator
elsif !user.active?
EmailActivator
@@ -35,11 +32,6 @@ class UserActivator
end
end
def register_username
if user.valid? && @settings.call_discourse_hub?
@hub.register_username(user.username, user.email)
end
end
end
class ApprovalActivator < UserActivator

View File

@@ -61,7 +61,6 @@ class UserDestroyer
end
StaffActionLogger.new(@actor == user ? Discourse.system_user : @actor).log_user_deletion(user, opts.slice(:context))
DiscourseHub.unregister_username(user.username) if SiteSetting.call_discourse_hub?
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
end
end

View File

@@ -5,54 +5,13 @@ class UsernameCheckerService
validator = UsernameValidator.new(username)
if !validator.valid_format?
{errors: validator.errors}
elsif !SiteSetting.call_discourse_hub?
check_username_locally(username)
else
check_username_with_hub_server(username, email)
end
elsif email and SiteSetting.call_discourse_hub?
username_from_hub = DiscourseHub.username_for_email(email)
if username_from_hub && User.username_available?(username_from_hub)
{suggestion: username_from_hub}
else
{suggestion: nil}
check_username_availability(username)
end
end
end
# Contact the Discourse Hub server
def check_username_with_hub_server(username, email)
available_locally = User.username_available?(username)
info = available_globally_and_suggestion_from_hub(username, email)
available_globally = info[:available_globally]
suggestion_from_discourse_hub = info[:suggestion_from_discourse_hub]
global_match = info[:global_match]
if available_globally && available_locally
{ available: true, global_match: (global_match ? true : false) }
elsif available_locally && !available_globally
if email.present?
# Nickname and email do not match what's registered on the discourse hub.
{ available: false, global_match: false, suggestion: suggestion_from_discourse_hub }
else
# The username is available locally, but is registered on the discourse hub.
# We need an email to see if the username belongs to this person.
# Don't give a suggestion until we get the email and try to match it with on the discourse hub.
{ available: false }
end
elsif available_globally && !available_locally
# Already registered on this site with the matching username and email address. Why are you signing up again?
{ available: false, suggestion: UserNameSuggester.suggest(username) }
else
# Not available anywhere.
render_unavailable_with_suggestion(suggestion_from_discourse_hub)
end
end
def render_unavailable_with_suggestion(suggestion)
{ available: false, suggestion: suggestion }
end
def check_username_locally(username)
def check_username_availability(username)
if User.username_available?(username)
{ available: true }
else
@@ -60,18 +19,4 @@ class UsernameCheckerService
end
end
def available_globally_and_suggestion_from_hub(username, email)
if email.present?
global_match, available, suggestion =
DiscourseHub.username_match?(username, email)
{ available_globally: available || global_match,
suggestion_from_discourse_hub: suggestion,
global_match: global_match }
else
args = DiscourseHub.username_available?(username)
{ available_globally: args[0],
suggestion_from_discourse_hub: args[1],
global_match: false }
end
end
end