<commit_before>#
# Handle signup or signin
# from various oauth providers
#
# Heavily overlaps with Authentications controller
#
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    create
  end
  def failure
    flash[:error] = "Authentication failed."
    redirect_to request.env['omniauth.origin'] || "/"
  end

  private

  #
  # Inspects the omniauth information
  # and determines if we have an existing member 
  # (to add authentication to)
  # or if this is a new signup
  #
  # As a side affect, this method sets the @member_created
  # variable
  #
  def member
    @member_created = false

    auth = request.env['omniauth.auth']

    authentication = Authentication.where(provider: auth.provider, uid: auth.uid).first
    if authentication && authentication.member.id.present?
      member = authentication.member
    end

    member = Member.where(email: auth.info.email).first_or_create do |m|
      m.email = auth.info.email
      m.password = <PASSWORD>[0,20]
      m.tos_agreement = true
      # TODO This has a reasonable chance of collision
      m.login_name = auth.info.nickname || auth.info.email.split("@").first.gsub(/[^A-Za-z]+/, '_').underscore<commit_msg>#645 Fix minor logic error<commit_after>#
# Handle signup or signin
# from various oauth providers
#
# Heavily overlaps with Authentications controller
#
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    create
  end
  def failure
    flash[:error] = "Authentication failed."
    redirect_to request.env['omniauth.origin'] || "/"
  end

  private

  #
  # Inspects the omniauth information
  # and determines if we have an existing member 
  # (to add authentication to)
  # or if this is a new signup
  #
  # As a side affect, this method sets the @member_created
  # variable
  #
  def member
    @member_created = false

    auth = request.env['omniauth.auth']

    authentication = Authentication.where(provider: auth.provider, uid: auth.uid).first
    if authentication && authentication.member.id.present?
      member = authentication.member
    end

    member ||= Member.where(email: auth.info.email).first_or_create do |m|
      m.email = auth.info.email
      m.password = <PASSWORD>_token[0,20]
      m.tos_agreement = true
      # TODO This has a reasonable chance of collision
      m.login_name = auth.info.nickname || auth.info.email.split("@").first.gsub(/[^A-Za-z]+/, '_').underscore
{'fraction_non_alphanumeric': 0.10190824198132359, 'fraction_numerical': 0.0036540803897685747, 'mean_word_length': 3.423698384201077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3863442', 'n_tokens_mistral': 759, 'n_tokens_neox': 729, 'n_words': 209}