<commit_before>module Bpluser::User


  def self.included(base)
    base.send :devise, :database_authenticatable, :registerable,
              :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:ldap, :polaris, :facebook, :password]
    base.send :attr_accessible, :provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid
    base.send :has_many, :user_institutions, :class_name => "Bpluser::UserInstitution"
    base.send :has_many, :folders, :dependent => :destroy, :class_name => "Bpluser::Folder"
    base.extend(ClassMethods)
    base.send :include, InstanceMethods

  end

  module ClassMethods
    def find_for_ldap_oauth(auth_response, signed_in_resource=nil)

      ldap_raw_details = auth_response[:extra][:raw_info]
      ldap_info_details = auth_response[:info]

      user = User.where(:provider => auth_response.provider, :uid => ldap_raw_details.samaccountname[0].downcase).first

      #first_name:ldap_info_details.first_name,
      #last_name:ldap_info_details.last_name,
      unless user
        user = User.create(provider:auth_response.provider,
                           uid:ldap_raw_details.samaccountname[0].downcase,
                           username:ldap_raw_details.samaccountname[0].downcase,
                           email:ldap_raw_details.mail[0].to_s.downcase,
                           password:<PASSWORD>[0,20],
                           display_name: ldap_info_details.first_name + " " + ldap_info_details.last_name,
                           first_name: ldap_info_details.first_name,
                           last_name: ldap_info_details.last_name
        )
      end
      groups = user.ldap_groups
      groups.each do |group|
        if(group == "Repository Administrators")
          admin_role = Role.where(:name=>'admin')
          if(admin_role.length == 0)
            Role.create(:name=>"admin")
            admin_role = Role.where(:name=>'admin')
          end
          user.roles << admin_role[0] unless user.roles.include?(admin_role[0])
          user.save!
        end

      end

      user
    end

    def find_for_polaris_oauth(auth_response, signed_in_resource=nil)
      polaris_raw_details = auth_response[:extra][:raw_info]
      polaris_info_details = auth_response[:info]

      user = User.where(:provider => auth_response.provider, :uid => auth_response[:uid]).first

      #first_name:ldap_info_details.first_name,
      #last_name:ldap_info_details.last_name,
      unless user
        user = User.create(provider:auth_response.provider,
                           uid:auth_response[:uid],
                           username:auth_response[:uid],
                           email:auth_response[:uid]+"@<EMAIL>",
                           password:<PASSWORD>],
                           display_name:auth_response[:uid]
        )

      end
      user
    end

    def find_for_facebook_oauth(auth, signed_in_resource=nil)
      user = User.where(:provider => auth.provider, :uid => auth.uid).first
      unless user
        user = User.create(display_name:auth.extra.raw_info.name,
                           uid:auth.uid,
                           provider:auth.provider,
                           username:auth.info.nickname,
                           email:auth.info.email,
                           password:<PASSWORD>[0,20] ,
                           first_name:auth.extra.raw_info.first_name,
                           last_name:auth.extra.raw_info.last_name
        )
      end<commit_msg>Include more polaris details and other changes.<commit_after>module Bpluser::User


  def self.included(base)
    base.send :devise, :database_authenticatable, :registerable,
              :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:ldap, :polaris, :facebook, :password]
    base.send :attr_accessible, :provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid
    base.send :has_many, :user_institutions, :class_name => "Bpluser::UserInstitution"
    base.send :has_many, :folders, :dependent => :destroy, :class_name => "Bpluser::Folder"
    base.extend(ClassMethods)
    base.send :include, InstanceMethods

  end

  module ClassMethods
    def find_for_ldap_oauth(auth_response, signed_in_resource=nil)

      ldap_raw_details = auth_response[:extra][:raw_info]
      ldap_info_details = auth_response[:info]

      user = User.where(:provider => auth_response.provider, :uid => ldap_raw_details.samaccountname[0].downcase).first

      #first_name:ldap_info_details.first_name,
      #last_name:ldap_info_details.last_name,
      unless user
        user = User.create(provider:auth_response.provider,
                           uid:ldap_raw_details.samaccountname[0].downcase,
                           username:ldap_raw_details.samaccountname[0].downcase,
                           email:ldap_raw_details.mail[0].to_s.downcase,
                           password:<PASSWORD>[0,20],
                           display_name: ldap_info_details.first_name + " " + ldap_info_details.last_name,
                           first_name: ldap_info_details.first_name,
                           last_name: ldap_info_details.last_name
        )
      end
      groups = user.ldap_groups
      groups.each do |group|
        if(group == "Repository Administrators")
          admin_role = Role.where(:name=>'admin')
          if(admin_role.length == 0)
            Role.create(:name=>"admin")
            admin_role = Role.where(:name=>'admin')
          end
          user.roles << admin_role[0] unless user.roles.include?(admin_role[0])
          user.save!
        end

      end

      user
    end

    def find_for_polaris_oauth(auth_response, signed_in_resource=nil)
      polaris_raw_details = auth_response[:extra][:raw_info]
      polaris_info_details = auth_response[:info]

      user = User.where(:provider => auth_response.provider, :uid => auth_response[:uid]).first

      #first_name:ldap_info_details.first_name,
      #last_name:ldap_info_details.last_name,
      unless user
        user = User.create(provider:auth_response.provider,
                           uid:auth_response[:uid],
                           username:polaris_info_details[:first_name],
                           email:polaris_info_details[:email],
                           password:<PASSWORD>],
                           display_name:polaris_info_details[:first_name] + " " + polaris_info_details[:last_name],
                           first_name: polaris_info_details[:first_name],
                           last_name: polaris_info_details[:last_name]

        )

      end
      user
    end

    def find_for_facebook_oauth(auth, signed_in_resource=nil)
      user = User.where(:provider => auth.provider, :uid => auth.uid).first
      unless user
        user = User.create(display_name:auth.extra.raw_info.name,
                           uid:auth.uid,
                           provider:auth.provider,
                           username:auth.info.nickname,
                           email:auth.info.email,
                           password:<PASSWORD>,20] ,
                           first_name:auth.extra.raw_info.first_name,
                           last_name:auth.extra.raw_info.last_name
        )
      end
{'fraction_non_alphanumeric': 0.10086183678965796, 'fraction_numerical': 0.0033665499596014004, 'mean_word_length': 2.2460664335664338, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 36, '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': '7455794', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2159, 'n_words': 310}