<commit_before># frozen_string_literal: true

module Users
  # Overrides to Devise's sign up registrations
  class RegistrationsController < Devise::RegistrationsController
    include Dmptool::Authenticatable
    include OrgSelectable

    # See the Authenticatable concern for additional callbacks

    before_action :configure_sign_up_params, only: [:create]

    before_action :configure_account_update_params, only: [:update]

    # GET /users/sign_up
    def new
      # See if there was any OmniAuth information. If so use it to prepoluate fields
      self.resource = user_from_omniauth
    end

    # rubocop:disable Metrics/AbcSize
    # POST /users
    def create
      if resource.active_invitation? && !resource.new_record?
        # The user record already existed
        if resource.update(sign_up_params)
          resource.accept_invitation

          # Follow the standard Devise logic to sign in
          set_flash_message! :notice, :signed_up
          sign_up(resource_name, resource)
          respond_with resource, location: after_sign_up_path_for(resource)
        else
          # Follow the standard Devise failed registration logic
          clean_up_passwords resource
          set_minimum_password_length
          respond_with resource
        end
      else
        # Devise doesn't set a flash message for some reason if its going to fail
        # so do it here
        super do |user|
          flash[:alert] = _('Unable to create your account!') unless user.valid?
        end
      end
    end
    # rubocop:enable Metrics/AbcSize<commit_msg>Added handler to save shib eppn on new account sign up for brand new user<commit_after># frozen_string_literal: true

module Users
  # Overrides to Devise's sign up registrations
  class RegistrationsController < Devise::RegistrationsController
    include Dmptool::Authenticatable
    include OrgSelectable

    # See the Authenticatable concern for additional callbacks

    before_action :configure_sign_up_params, only: [:create]

    before_action :configure_account_update_params, only: [:update]

    # GET /users/sign_up
    def new
      # See if there was any OmniAuth information. If so use it to prepoluate fields
      self.resource = user_from_omniauth
    end

    # rubocop:disable Metrics/AbcSize
    # POST /users
    def create
      if resource.active_invitation? && !resource.new_record?
        # The user record already existed
        if resource.update(sign_up_params)
          resource.accept_invitation

          # Follow the standard Devise logic to sign in
          set_flash_message! :notice, :signed_up
          sign_up(resource_name, resource)
          respond_with resource, location: after_sign_up_path_for(resource)
        else
          # Follow the standard Devise failed registration logic
          clean_up_passwords resource
          set_minimum_password_length
          respond_with resource
        end
      else
        # Devise doesn't set a flash message for some reason if its going to fail
        # so do it here
        super do |user|
          flash[:alert] = _('Unable to create your account!') unless user.valid?

          omniauth = session.fetch("devise.#{scheme.name}_data", {})
          if omniauth.present?
            user.attach_omniauth_credentials(scheme_name: 'shibboleth', omniauth_hash: omniauth)
          end
        end
      end
    end
    # rubocop:enable Metrics/AbcSize
{'fraction_non_alphanumeric': 0.05413271245634459, 'fraction_numerical': 0.0, 'mean_word_length': 2.752183406113537, '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': '5556632', 'n_tokens_mistral': 952, 'n_tokens_neox': 928, 'n_words': 296}