Sha256: 8aa633a4ca68b4d5b5dbbdee537090ed3a1481c6fbe9b7959c2b94e516e24c25

Contents?: true

Size: 881 Bytes

Versions: 16

Compression:

Stored size: 881 Bytes

Contents

module Notee
  class ApplicationController < ActionController::Base
    before_action :restrict_access_json
    before_filter :set_request_filter

    def set_request_filter
      Thread.current[:request] = request
    end

    def restrict_access_json
      return redirect_to new_token_path unless confirm_exist_token
      return redirect_to new_token_path unless confirm_expired_token
    end

    private

    def confirm_exist_token
      unless Token.exists?(access_token: session[:access_token])
        session.delete(:access_token)
        return false
      end

      true
    end

    def confirm_expired_token
      token = Token.find_by(access_token: session[:access_token])
      return false unless token

      if Time.now > token.expires_at
        token.destroy
        session.delete(:access_token)
        return false
      end

      true
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
notee-1.1.2.4 app/controllers/notee/application_controller.rb
notee-1.1.2.3 app/controllers/notee/application_controller.rb
notee-1.1.2.2 app/controllers/notee/application_controller.rb
notee-1.1.2.1 app/controllers/notee/application_controller.rb
notee-1.1.2 app/controllers/notee/application_controller.rb
notee-1.1.1 app/controllers/notee/application_controller.rb
notee-1.1.0 app/controllers/notee/application_controller.rb
notee-1.0.8 app/controllers/notee/application_controller.rb
notee-1.0.7 app/controllers/notee/application_controller.rb
notee-1.0.6 app/controllers/notee/application_controller.rb
notee-1.0.5 app/controllers/notee/application_controller.rb
notee-1.0.4 app/controllers/notee/application_controller.rb
notee-1.0.3 app/controllers/notee/application_controller.rb
notee-1.0.2 app/controllers/notee/application_controller.rb
notee-1.0.1 app/controllers/notee/application_controller.rb
notee-1.0.0 app/controllers/notee/application_controller.rb