forked from External/greenlight
		
	GRN2-213: Cleaned up omniauth user create (#682)
* Fixed omniauth user create * Added readonly exception
This commit is contained in:
		
				
					committed by
					
						
						Jesus Federico
					
				
			
			
				
	
			
			
			
						parent
						
							4e16e99758
						
					
				
				
					commit
					d1e50f2ef6
				
			@@ -55,14 +55,31 @@ class User < ApplicationRecord
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user