adminlock 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/adminlock.rb +48 -0
- metadata +43 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 603f724873f122c822b6b5acf81bc04ed4e46edc17f2081274c7c06db2be0945
         | 
| 4 | 
            +
              data.tar.gz: d07795ec5e09258ab909c7a96c53d6e0f6ee952b82cca22a13cf0cc2850b52c3
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: ab796004895ae6c8648819227b29218f67c085cbce49f17ec7b58c576b5e574d443d0b54f640c1db9c94ce2867b7fc1e5b2b5c13bb06989663173e5ba838ecd3
         | 
| 7 | 
            +
              data.tar.gz: 17a8bb95d77073e6353136cfc84134ee9e8ba4a314caaf13972bb6539b6a7b0081dca6d53511bac9510494958b9122f04a5136c6e264c2363a8b20cc70716160
         | 
    
        data/lib/adminlock.rb
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            module Adminlock
         | 
| 2 | 
            +
              def self.from_config(setting, secrets_or_credentials = :credentials)
         | 
| 3 | 
            +
                return unless Rails.application.respond_to?(secrets_or_credentials)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                store = Rails.application.public_send(secrets_or_credentials)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                store.adminlock.respond_to?(:fetch) &&
         | 
| 8 | 
            +
                  store.adminlock.fetch(setting, store.public_send("adminlock_#{setting}")) ||
         | 
| 9 | 
            +
                  store.public_send("adminlock_#{setting}") || store.public_send(setting)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              private
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def check_for_adminlock
         | 
| 15 | 
            +
                return unless respond_to?(:adminlock) && adminlock_codeword
         | 
| 16 | 
            +
                return if cookies[:adminlock].present? && cookies[:adminlock] == adminlock_codeword.to_s.downcase
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                redirect_to adminlock.unlock_path(
         | 
| 19 | 
            +
                  return_to: request.fullpath.split('?adminlock_codeword')[0],
         | 
| 20 | 
            +
                  adminlock_codeword: params[:adminlock_codeword]
         | 
| 21 | 
            +
                )
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def cookie_lifetime
         | 
| 25 | 
            +
                @cookie_lifetime ||=
         | 
| 26 | 
            +
                  ENV['COOKIE_LIFETIME_IN_WEEKS'] ||
         | 
| 27 | 
            +
                  ENV['cookie_lifetime_in_weeks'] ||
         | 
| 28 | 
            +
                  Adminlock.from_config(:cookie_lifetime_in_weeks, :secrets) ||
         | 
| 29 | 
            +
                  Adminlock.from_config(:cookie_lifetime_in_weeks)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def adminlock_codeword
         | 
| 33 | 
            +
                @adminlock_codeword ||=
         | 
| 34 | 
            +
                  ENV['ADMINLOCK_CODEWORD'] ||
         | 
| 35 | 
            +
                  ENV['adminlock_codeword'] ||
         | 
| 36 | 
            +
                  Adminlock.from_config(:codeword, :secrets) ||
         | 
| 37 | 
            +
                  Adminlock.from_config(:codeword)
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              def adminlock_cookie_lifetime
         | 
| 41 | 
            +
                seconds = (cookie_lifetime.to_f * 1.week).to_i
         | 
| 42 | 
            +
                if seconds > 0
         | 
| 43 | 
            +
                  seconds
         | 
| 44 | 
            +
                else
         | 
| 45 | 
            +
                  5.years
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: adminlock
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - anoop
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-11-28 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: 
         | 
| 14 | 
            +
            email: anoop0302@gmail.com
         | 
| 15 | 
            +
            executables: []
         | 
| 16 | 
            +
            extensions: []
         | 
| 17 | 
            +
            extra_rdoc_files: []
         | 
| 18 | 
            +
            files:
         | 
| 19 | 
            +
            - lib/adminlock.rb
         | 
| 20 | 
            +
            homepage: https://rubygems.org/gems/adminlock
         | 
| 21 | 
            +
            licenses:
         | 
| 22 | 
            +
            - MIT
         | 
| 23 | 
            +
            metadata: {}
         | 
| 24 | 
            +
            post_install_message: 
         | 
| 25 | 
            +
            rdoc_options: []
         | 
| 26 | 
            +
            require_paths:
         | 
| 27 | 
            +
            - lib
         | 
| 28 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 29 | 
            +
              requirements:
         | 
| 30 | 
            +
              - - ">="
         | 
| 31 | 
            +
                - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                  version: '0'
         | 
| 33 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 34 | 
            +
              requirements:
         | 
| 35 | 
            +
              - - ">="
         | 
| 36 | 
            +
                - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                  version: '0'
         | 
| 38 | 
            +
            requirements: []
         | 
| 39 | 
            +
            rubygems_version: 3.0.2
         | 
| 40 | 
            +
            signing_key: 
         | 
| 41 | 
            +
            specification_version: 4
         | 
| 42 | 
            +
            summary: lock your important links
         | 
| 43 | 
            +
            test_files: []
         |