<commit_before>class Users::SessionsController < Devise::SessionsController
  layout 'pages'
  include AutodetectTimeZone
  include InvitationsHelper
  include OmniauthAuthenticationHelper

  # at some point in the future we can remove this
  before_filter :create_parse_user_if_needed, only: :create

  before_filter :store_previous_location, only: :new
  before_filter :load_invitation_from_session, only: :new
  after_filter :set_time_zone_from_javascript, only: :create

  private

  # and this
  def create_parse_user_if_needed
    if ENV['PARSE_ID'] and request.subdomain == ENV['PARSE_SUBDOMAIN']
      unless warden.authenticate?(auth_options)
        if user_hash = ParseAuth.login_with_email_and_password(params[:user][:email], params[:user][:password])
          u = User.create!(name: "#{user_hash['firstname']} #{user_hash['lastname']}",
                           email: params[:user][:email],
                           password: params[:user][:password])
          g = Group.find(ENV['PARSE_GROUP_ID'])
          g.add_member!(u)
          flash[:notice] = t(:'devise.sessions.signed_in')
          sign_in(:user, u)
          redirect_to after_sign_in_path_for(u)
        end
      end
    end
  end
end<commit_msg>support logging in users when parse password is correct but different to loomio password<commit_after>class Users::SessionsController < Devise::SessionsController
  layout 'pages'
  include AutodetectTimeZone
  include InvitationsHelper
  include OmniauthAuthenticationHelper

  # at some point in the future we can remove this
  before_filter :create_parse_user_if_needed, only: :create

  before_filter :store_previous_location, only: :new
  before_filter :load_invitation_from_session, only: :new
  after_filter :set_time_zone_from_javascript, only: :create

  private

  # and this
  def create_parse_user_if_needed
    if ENV['PARSE_ID'] and request.subdomain == ENV['PARSE_SUBDOMAIN']
      unless warden.authenticate?(auth_options)
        if user_hash = ParseAuth.login_with_email_and_password(params[:user][:email], params[:user][:password])

          unless u = User.find_by_email(params[:user][:email])
            u = User.create!(name: "#{user_hash['firstname']} #{user_hash['lastname']}",
                             email: params[:user][:email],
                             password: params[:user][:password])
          end

          g = Group.find(ENV['PARSE_GROUP_ID'])
          g.add_member!(u)
          flash[:notice] = t(:'devise.sessions.signed_in')
          sign_in(:user, u)
          redirect_to after_sign_in_path_for(u)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10060975609756098, 'fraction_numerical': 0.0, 'mean_word_length': 3.4642857142857144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4659441', 'n_tokens_mistral': 801, 'n_tokens_neox': 786, 'n_words': 166}