Sha256: 6aac021171b1a7830402004140015c5a2349ecc9b50f71163c09937eb54485a4

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true
require 'proxes/controllers/application'

module ProxES
  # Manage your Elasticsearch cluster, user and user sessions
  class App < Application
    get '/' do
      authenticate!
      haml :index, locals: { title: 'Dashboard' }
    end

    ['/unauthenticated', '/_proxes/unauthenticated'].each do |path|
      get path do
        redirect '/auth/identity'
      end
    end

    post '/auth/identity/new' do
      identity = Identity.new(params['identity'])
      if identity.valid? && identity.save
        user = User.find_or_create(email: identity.username)
        user.add_identity identity

        log_action(:identity_register, user: user)
        flash[:info] = 'Successfully Registered. Please log in'
        redirect '/auth/identity'
      else
        flash.now[:warning] = 'Could not complete the registration. Please try again.'
        haml :'identity/register', locals: { identity: identity }
      end
    end

    post '/auth/identity/callback' do
      user = User.find(email: env['omniauth.auth']['info']['email'])
      self.current_user = user
      log_action(:identity_login, user: user)
      flash[:success] = 'Logged In'
      redirect '/_proxes'
    end

    delete '/auth/identity' do
      log_action(:identity_logout)
      logout
      flash[:info] = 'Logged Out'

      redirect '/_proxes'
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
proxes-0.4.0 lib/proxes/app.rb
proxes-0.3.6 lib/proxes/app.rb
proxes-0.3.5 lib/proxes/app.rb
proxes-0.3.3 lib/proxes/app.rb
proxes-0.3.2 lib/proxes/app.rb
proxes-0.3.1 lib/proxes/app.rb
proxes-0.3.0 lib/proxes/app.rb
proxes-0.2.0 lib/proxes/app.rb