Sha256: 4a483853dca41c196cc5f71cb6a96bf61e9436e411f4f88fde427f0442588511

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

module AdsenseCrawlerForPrivate
  class AdsenseCrawlerLoginController < ApplicationController

    # Making sure that verify_authenticity_token is not on, adsense does not have it
    skip_before_filter :verify_authenticity_token, :only => :login

    def login
      unless AdsenseCrawlerForPrivate.crawler_password.blank?

        crawler_name = params[:name]
        crawler_password = params[:password]

        if (AdsenseCrawlerForPrivate.ip_check(request) and
            crawler_name == AdsenseCrawlerForPrivate.crawler_name and
            crawler_password == AdsenseCrawlerForPrivate.crawler_password)

          cookies.signed[AdsenseCrawlerForPrivate.cookie_name] = AdsenseCrawlerForPrivate.cookie_hash(crawler_name, crawler_password, request.remote_addr)

          AdsenseCrawlerForPrivate.logger.warn "login successfully. Crawler_name: #{crawler_name}"

          render :text => 'crawler login ok', :status => 200
        else
          cookies.delete(AdsenseCrawlerForPrivate.cookie_name, :domain => AdsenseCrawlerForPrivate.cookie_domain)

          AdsenseCrawlerForPrivate.logger.warn "login unsuccessful. Crawler_name: #{crawler_name}, crawler_password: #{crawler_password}, crawler_ip: #{request.remote_addr}"

          render :text => 'crawler login unsuccessful', :status => 401 # 401 unauthorized
        end

      else
        str = "AdsenseCrawlerForPrivate not configured, no password given."
        AdsenseCrawlerForPrivate.logger.warn(str)
        render :text => str, :status => 401
      end

    end
  
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adsense_crawler_for_private-1.1.0 app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb
adsense_crawler_for_private-1.0.1 app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb
adsense_crawler_for_private-1.0.0 app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb