forked from External/greenlight
GRN2-213: Cleaned up omniauth user create (#682)
* Fixed omniauth user create * Added readonly exception
This commit is contained in:
parent
4e16e99758
commit
d1e50f2ef6
|
@ -55,14 +55,31 @@ class User < ApplicationRecord
|
||||||
def from_omniauth(auth)
|
def from_omniauth(auth)
|
||||||
# Provider is the customer name if in loadbalanced config mode
|
# Provider is the customer name if in loadbalanced config mode
|
||||||
provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider']
|
provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider']
|
||||||
find_or_initialize_by(social_uid: auth['uid'], provider: provider).tap do |u|
|
u = find_by(social_uid: auth['uid'], provider: provider)
|
||||||
u.name = auth_name(auth) unless u.name
|
|
||||||
u.username = auth_username(auth) unless u.username
|
if ENV["MAINTENANCE_MODE"] == "readonly"
|
||||||
u.email = auth_email(auth)
|
raise ActiveRecord::ReadOnlyRecord if u.nil?
|
||||||
u.image = auth_image(auth)
|
|
||||||
u.email_verified = true
|
return u
|
||||||
u.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return User.create(
|
||||||
|
name: auth_name(auth),
|
||||||
|
username: auth_username(auth),
|
||||||
|
email: auth_email(auth),
|
||||||
|
social_uid: auth['uid'],
|
||||||
|
provider: provider,
|
||||||
|
image: auth_image(auth),
|
||||||
|
email_verified: true
|
||||||
|
) if u.nil?
|
||||||
|
|
||||||
|
u.name = auth_name(auth) unless u.name
|
||||||
|
u.username = auth_username(auth) unless u.username
|
||||||
|
u.email = auth_email(auth)
|
||||||
|
u.image = auth_image(auth)
|
||||||
|
u.email_verified = true
|
||||||
|
u.save!
|
||||||
|
u
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in New Issue