Sha256: bc8b416f2307cf15666b6244ec99c8653c5934ecee72b9457cdc86da9a71912e

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
# Copyright 2016 Liqwyd Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Cyclid
  module UI
    # Various helper methods for Sinatra controllers
    module Helpers
      # Raw CSRF token
      def csrf_token(rack_env)
        Rack::Csrf.csrf_token(rack_env)
      end

      # CSRF HTML forms tag
      def csrf_tag(rack_env)
        Rack::Csrf.csrf_tag(rack_env)
      end

      # Standard unauthenticated 401 message
      def halt_with_401
        flash[:login_error] = 'Invalid username or password'
        halt 401, flash.now[:login_error]
      end
    end

    # Sinatra Warden AuthN/AuthZ helpers
    module AuthHelpers
      # Return the current Warden scope
      def warden
        env['warden']
      end

      # Call the Warden authenticate! method
      def authenticate!
        warden.authenticate!
      end

      # Current User object from the session
      def current_user
        warden.user
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cyclid-ui-0.2.4 app/cyclid_ui/helpers.rb
cyclid-ui-0.2.3 app/cyclid_ui/helpers.rb
cyclid-ui-0.2.2 app/cyclid_ui/helpers.rb
cyclid-ui-0.2.1 app/cyclid_ui/helpers.rb
cyclid-ui-0.2.0 app/cyclid_ui/helpers.rb
cyclid-ui-0.1.1 app/cyclid_ui/helpers.rb
cyclid-ui-0.1.0 app/cyclid_ui/helpers.rb