<commit_before># Copyright (C) 2009 <NAME>.

class Editor::AuthRenderer < ParagraphRenderer #:nodoc:all

  features '/editor/auth_feature'

  paragraph :user_register
  paragraph :user_activation
  paragraph :login
  paragraph :enter_vip
  paragraph :edit_account
  paragraph :missing_password
  paragraph :email_list
  paragraph :splash
  paragraph :view_account
  paragraph :user_edit_account

  def user_register

    @options = paragraph_options(:user_register)

    if !editor? &&  myself.id && @options.already_registered_page_url
      return redirect_paragraph @options.already_registered_page_url
    end

    if myself.id && !editor?
      @registered = true
    else
      @usr = EndUser.new
      @address = @usr.build_address(:address_name => 'Default Address'.t, :country => @options.country )
      @business = @usr.build_work_address(:address_name => 'Business Address'.t, :country => @options.country )
      if request.post? && params[:user] && params[:partial]
        @usr.attributes =  params[:user].slice(*(@options.required_fields + @options.optional_fields + @options.always_required_fields).uniq)
        @address.attributes = params[:address].slice( @options.available_address_field_list.keys) if params[:address]
        @business.attributes = params[:business].slice( @options.available_address_field_list.keys) if params[:business]


      end

      if @options.publication
        @model = @options.publication.content_model.content_model.new
      end
    end

    @options.register_features.each do |feature|
      feature.feature_instance.generate(params)
    end

    @captcha = WebivaCaptcha.new(self) if @options.require_captcha

    if request.post? && params[:user] && !@registered && !params[:partial]
      # See we already have an unregistered user with this email
      @usr = EndUser.find_target(params[:user][:email],:no_create => true)
      
      if @usr.registered?
        # If user is registered we need to create a new user
        @usr = EndUser.new(:source => 'website')
      end
      
      # Assign a slice of params to the user
      @usr.attributes = params[:user].slice(*(@options.required_fields + @options.optional_fields + @options.always_required_fields).uniq)

      @usr.registered = true if @options.registration_type == 'account'
      @usr.user_class_id = @options.user_class_id if @usr.user_class_id.blank? || @options.modify_profile == 'modify'

      # check everything is valid
      all_valid = true
      @captcha.validate_object(@usr) if @captcha

      @usr.valid?

      # go over each required field - add an error if it's missing
      @options.required_fields.each do |fld|
        if @usr.send(fld).blank?
          @usr.errors.add(fld,'is missing')
        end
      end

      all_valid = false unless @usr.errors.length == 0
     
      # same for address
      all_valid = false unless assign_entry(@address, params[:address], @options.available_address_field_list.keys, @options.address_required_fields)

      # same for business address
      all_valid = false unless assign_entry(@business, params[:business], @options.available_address_field_list.keys, @options.work_address_required_fields)

      if @model
        @options.publication.assign_entry(@model,params[:model],renderer_state)
        all_valid = false unless @model.errors.length == 0
      end
      
      @options.register_features.each do |feature|
        all_valid=false unless feature.feature_instance.valid?
      end


      # if there are no errors on anything
      # save the user,

      @failed = true unless all_valid

      if all_valid 
      
        # Set a source if we have one        
        if session[:user_referrer]
          @usr.referrer = session[:user_referrer]
        end

        @usr.lead_source = @options.source unless @options.source.blank?

        if params[:address]
          @address.save
          @usr.address_id =@address.id
        end

        if params[:business]
          @business.save
          @usr.work_address_id = @business.id
        end

        if @options.require_activation
          @usr.activated = false
          @usr.generate_activation_string
        end

        # Make sure save is successful - will recheck validation and
        # rescan for uniques
        if(@usr.save)
          self.elevate_user_level @usr, @options.user_level

          @usr.tag_names_add(@options.add_tags) unless @options.add_tags.blank?
          @usr.tag_names_add(session[:user_tags]) if session[:user_tags]

          session[:user_tags] = nil
          session[:user_source] = nil

          @address.update_attribute(:end_user_id,@usr.id) if @address.id
          @business.update_attribute(:end_user_id,@usr.id) if @business.id

          if @options.include_subscriptions.is_a?(Array) && @options.include_subscriptions.length > 0
            @options.subscriptions.each do |sub|
              sub.subscribe_user @usr, :ip_address => request.remote_ip
            end
          end

          @options.register_features.each do |feature|
            feature.feature_instance.post_process(@usr)
          end

          if !@options.require_activation
            process_login(@usr)
          end

          if @model
            # Re-update entry as we now have a user object
            @options.publication.assign_entry(@model,params[:model],renderer_state(:myself => @usr))
            @model.save
          end

          # run any triggered actions
          paragraph.run_triggered_actions(@usr,'action',@usr)

          # send mail template if we have one
          if @options.registration_template_id.to_i > 0 && @mail_template = MailTemplate.find_by_id(@options.registration_template_id)
            vars = { 

            }
            if @options.require_activation
              url = Configuration.domain_link(@options.activation_page_url + "?code=#{@usr.activation_string}")
              vars['ACTIVATION_URL'] = url
              vars['ACTIVATION_LINK'] = "<a href='#{url}'>#{url}</a>"
            end
            @mail_template.deliver_to_user(@usr,vars)
          end
          
          paragraph_action(@usr.action('/editor/auth/user_registration', :identifier => @usr.email))

          if @options.lockout_redirect &&  session[:lock_lockout]
            lock_logout = session[:lock_lockout]
            session[:lock_lockout] = nil
            redirect_paragraph lock_logout
            return
          elsif @options.success_page_url
            redirect_paragraph @options.success_page_url
            return<commit_msg>Content model user ID pushing fix<commit_after># Copyright (C) 2009 <NAME>.

class Editor::AuthRenderer < ParagraphRenderer #:nodoc:all

  features '/editor/auth_feature'

  paragraph :user_register
  paragraph :user_activation
  paragraph :login
  paragraph :enter_vip
  paragraph :edit_account
  paragraph :missing_password
  paragraph :email_list
  paragraph :splash
  paragraph :view_account
  paragraph :user_edit_account

  def user_register

    @options = paragraph_options(:user_register)

    if !editor? &&  myself.id && @options.already_registered_page_url
      return redirect_paragraph @options.already_registered_page_url
    end

    if myself.id && !editor?
      @registered = true
    else
      @usr = EndUser.new
      @address = @usr.build_address(:address_name => 'Default Address'.t, :country => @options.country )
      @business = @usr.build_work_address(:address_name => 'Business Address'.t, :country => @options.country )
      if request.post? && params[:user] && params[:partial]
        @usr.attributes =  params[:user].slice(*(@options.required_fields + @options.optional_fields + @options.always_required_fields).uniq)
        @address.attributes = params[:address].slice( @options.available_address_field_list.keys) if params[:address]
        @business.attributes = params[:business].slice( @options.available_address_field_list.keys) if params[:business]


      end

      if @options.publication
        @model = @options.publication.content_model.content_model.new
      end
    end

    @options.register_features.each do |feature|
      feature.feature_instance.generate(params)
    end

    @captcha = WebivaCaptcha.new(self) if @options.require_captcha

    if request.post? && params[:user] && !@registered && !params[:partial]
      # See we already have an unregistered user with this email
      @usr = EndUser.find_target(params[:user][:email],:no_create => true)
      
      if @usr.registered?
        # If user is registered we need to create a new user
        @usr = EndUser.new(:source => 'website')
      end
      
      # Assign a slice of params to the user
      @usr.attributes = params[:user].slice(*(@options.required_fields + @options.optional_fields + @options.always_required_fields).uniq)

      @usr.registered = true if @options.registration_type == 'account'
      @usr.user_class_id = @options.user_class_id if @usr.user_class_id.blank? || @options.modify_profile == 'modify'

      # check everything is valid
      all_valid = true
      @captcha.validate_object(@usr) if @captcha

      @usr.valid?

      # go over each required field - add an error if it's missing
      @options.required_fields.each do |fld|
        if @usr.send(fld).blank?
          @usr.errors.add(fld,'is missing')
        end
      end

      all_valid = false unless @usr.errors.length == 0
     
      # same for address
      all_valid = false unless assign_entry(@address, params[:address], @options.available_address_field_list.keys, @options.address_required_fields)

      # same for business address
      all_valid = false unless assign_entry(@business, params[:business], @options.available_address_field_list.keys, @options.work_address_required_fields)

      if @model
        @options.publication.assign_entry(@model,params[:model],renderer_state)
        all_valid = false unless @model.errors.length == 0
      end
      
      @options.register_features.each do |feature|
        all_valid=false unless feature.feature_instance.valid?
      end


      # if there are no errors on anything
      # save the user,

      @failed = true unless all_valid

      if all_valid 
      
        # Set a source if we have one        
        if session[:user_referrer]
          @usr.referrer = session[:user_referrer]
        end

        @usr.lead_source = @options.source unless @options.source.blank?

        if params[:address]
          @address.save
          @usr.address_id =@address.id
        end

        if params[:business]
          @business.save
          @usr.work_address_id = @business.id
        end

        if @options.require_activation
          @usr.activated = false
          @usr.generate_activation_string
        end

        # Make sure save is successful - will recheck validation and
        # rescan for uniques
        if(@usr.save)
          self.elevate_user_level @usr, @options.user_level

          @usr.tag_names_add(@options.add_tags) unless @options.add_tags.blank?
          @usr.tag_names_add(session[:user_tags]) if session[:user_tags]

          session[:user_tags] = nil
          session[:user_source] = nil

          @address.update_attribute(:end_user_id,@usr.id) if @address.id
          @business.update_attribute(:end_user_id,@usr.id) if @business.id

          if @options.include_subscriptions.is_a?(Array) && @options.include_subscriptions.length > 0
            @options.subscriptions.each do |sub|
              sub.subscribe_user @usr, :ip_address => request.remote_ip
            end
          end

          @options.register_features.each do |feature|
            feature.feature_instance.post_process(@usr)
          end

          if !@options.require_activation
            process_login(@usr)
          end

          if @model
            # Re-update entry as we now have a user object
            @options.publication.assign_entry(@model,params[:model],renderer_state(:user => @usr))
            @model.save
          end

          # run any triggered actions
          paragraph.run_triggered_actions(@usr,'action',@usr)

          # send mail template if we have one
          if @options.registration_template_id.to_i > 0 && @mail_template = MailTemplate.find_by_id(@options.registration_template_id)
            vars = { 

            }
            if @options.require_activation
              url = Configuration.domain_link(@options.activation_page_url + "?code=#{@usr.activation_string}")
              vars['ACTIVATION_URL'] = url
              vars['ACTIVATION_LINK'] = "<a href='#{url}'>#{url}</a>"
            end
            @mail_template.deliver_to_user(@usr,vars)
          end
          
          paragraph_action(@usr.action('/editor/auth/user_registration', :identifier => @usr.email))

          if @options.lockout_redirect &&  session[:lock_lockout]
            lock_logout = session[:lock_lockout]
            session[:lock_lockout] = nil
            redirect_paragraph lock_logout
            return
          elsif @options.success_page_url
            redirect_paragraph @options.success_page_url
            return
{'fraction_non_alphanumeric': 0.10022848438690023, 'fraction_numerical': 0.0012185833968012185, 'mean_word_length': 2.6556236080178173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '5310712', 'n_tokens_mistral': 3789, 'n_tokens_neox': 3656, 'n_words': 794}