<commit_before>module Empower
  module OmniAuth
    extend ActiveSupport::Concern

    included do
      devise :omniauthable, :omniauth_providers => [:facebook]
    end

    module ClassMethods
      def from_omniauth(auth)
        user = User.find_by_email(auth.info.email)
        if user.nil?
          user = User.create!(
            :email => auth.info.email,
            :password => Devise.friendly_token[0,20],
          )
          attrs = {}
          if user.respond_to?(:name)
            attrs[:name] = auth.info.name
          end
          if user.respond_to?(:image)
            attrs[:image] = auth.info.image
          end
          if attrs.keys.size > 0
            user.update_columns(attrs)
          end
        elsif user.respond_to?(:name)
          user.update(:name => auth.info.name)
        end
        user
      end

      def new_with_session(params, session)
        super.tap do |user|
          if data = session["devise.facebook_data"] &&
            session["devise.facebook_data"]["extra"]["raw_info"]
              user.email = data["email"] if user.email.blank?
          end
        end
      end
    end
  end
end<commit_msg>save image on sign in<commit_after>module Empower
  module OmniAuth
    extend ActiveSupport::Concern

    included do
      devise :omniauthable, :omniauth_providers => [:facebook]
    end

    module ClassMethods
      def from_omniauth(auth)
        user = User.find_by_email(auth.info.email)
        if user.nil?
          user = User.create!(
            :email => auth.info.email,
            :password => <PASSWORD>ise.friendly_token[0,20],
          )
          attrs = {}
          if user.respond_to?(:name)
            attrs[:name] = auth.info.name
          end
          if user.respond_to?(:image)
            attrs[:image] = auth.info.image
          end
          if attrs.keys.size > 0
            user.update_columns(attrs)
          end
        else
          attrs = {}
          if user.respond_to?(:name)
            attrs[:name] = auth.info.name
          end
          if user.respond_to?(:image)
            attrs[:image] = auth.info.image
          end
          if attrs.keys.size > 0
            user.update_columns(attrs)
          end
        end
        user
      end

      def new_with_session(params, session)
        super.tap do |user|
          if data = session["devise.facebook_data"] &&
            session["devise.facebook_data"]["extra"]["raw_info"]
              user.email = data["email"] if user.email.blank?
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10244470314318975, 'fraction_numerical': 0.0034924330616996507, 'mean_word_length': 1.622583926754832, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5967333', 'n_tokens_mistral': 759, 'n_tokens_neox': 748, 'n_words': 156}