Correct annotations

allow longer usernames (up to 60)
This commit is contained in:
Sam
2014-04-15 15:53:48 +10:00
parent 86985e345e
commit 862a6696c0
41 changed files with 117 additions and 108 deletions

View File

@ -41,14 +41,14 @@ class DiscourseSingleSignOn < SingleSignOn
def lookup_or_create_user
sso_record = SingleSignOnRecord.where(external_id: external_id).first
if sso_record && user = sso_record.user
sso_record.last_payload = unsigned_payload
else
user = match_email_or_create_user
sso_record = user.single_sign_on_record
end
# if the user isn't new or it's attached to the SSO record we might be overriding username or email
unless user.new_record?
change_external_attributes_and_override(sso_record, user)
@ -59,16 +59,16 @@ class DiscourseSingleSignOn < SingleSignOn
user.save
user.enqueue_welcome_message('welcome_user')
end
# optionally save the user and sso_record if they have changed
user.save!
sso_record.save!
sso_record && sso_record.user
end
private
def match_email_or_create_user
user = User.where(email: Email.downcase(email)).first
@ -90,31 +90,31 @@ class DiscourseSingleSignOn < SingleSignOn
external_name: name)
end
end
user
end
def change_external_attributes_and_override(sso_record, user)
if SiteSetting.sso_overrides_email && email != sso_record.external_email
# set the user's email to whatever came in the payload
user.email = email
end
if SiteSetting.sso_overrides_username && username != sso_record.external_username && user.username != username
# we have an external username change, and the user's current username doesn't match
# run it through the UserNameSuggester to override it
user.username = UserNameSuggester.suggest(username || name || email)
user.username = UserNameSuggester.suggest(username || name || email)
end
if SiteSetting.sso_overrides_name && name != sso_record.external_name && user.name != name
# we have an external name change, and the user's current name doesn't match
# run it through the name suggester to override it
user.name = User.suggest_name(name || username || email)
end
# change external attributes for sso record
sso_record.external_username = username
sso_record.external_email = email
sso_record.external_name = name
end
end
end