Skip to content

Commit

Permalink
GRN2-213: Cleaned up omniauth user create (bigbluebutton#682)
Browse files Browse the repository at this point in the history
* Fixed omniauth user create

* Added readonly exception
  • Loading branch information
farhatahmad authored and jfederico committed Jul 23, 2019
1 parent 4e16e99 commit d1e50f2
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,31 @@ class << self
def from_omniauth(auth)
# Provider is the customer name if in loadbalanced config mode
provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider']
find_or_initialize_by(social_uid: auth['uid'], provider: provider).tap do |u|
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 = find_by(social_uid: auth['uid'], provider: provider)

if ENV["MAINTENANCE_MODE"] == "readonly"
raise ActiveRecord::ReadOnlyRecord if u.nil?

return u
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

private
Expand Down

0 comments on commit d1e50f2

Please sign in to comment.