Sha256: 0b50af088c01c93d4a20d97486fb3844fca4fffb2f84bcf91531bda4f7ea97a0

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

require 'omniauth'
require 'omniauth-browserid'

module Schnitzelpress
  module Actions
    module Auth
      extend ActiveSupport::Concern

      included do
        use OmniAuth::Builder do
          provider :browser_id
          if Schnitzelpress.env.development?
            provider :developer , :fields => [:email], :uid_field => :email
          end
        end

        post '/auth/:provider/callback' do
          auth = request.env['omniauth.auth']
          session[:auth] = {:provider => auth['provider'], :uid => auth['uid']}

          if admin_logged_in?
            response.set_cookie('show_admin', :value => true, :path => '/')
            redirect '/admin/'
          else
            redirect '/'
          end
        end

        get '/login' do
          haml :'login'
        end

        get '/logout' do
          session[:auth] = nil
          response.delete_cookie('show_admin')

          redirect '/login'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schnitzelpress-0.2.1 lib/schnitzelpress/actions/auth.rb
schnitzelpress-0.2.0 lib/schnitzelpress/actions/auth.rb