#645 Avoid collisions by using a 20 character random string as a fallback

This commit is contained in:
Daniel O'Connor
2015-08-24 17:33:28 +09:30
parent 994296640b
commit 9564866f6d

View File

@@ -38,9 +38,13 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
m.email = auth.info.email
m.password = Devise.friendly_token[0,20]
# TODO This has a reasonable chance of collision
# First, try the nickname or friendly generate from the email
m.login_name = auth.info.nickname || auth.info.email.split("@").first.gsub(/[^A-Za-z]+/, '_').underscore
# Do we have a collision with an existing account? Generate a 20 character long random name
# so the user can update it later
m.login_name = Devise.friendly_token[0,20] if Member.where(login_name: m.login_name).any?
m.skip_confirmation!
# TODO Assess this later, if we introduce separate modelling for user photos