Modernized the app with app structure from Stage Manager
This commit is contained in:
32
app/config.rb
Normal file
32
app/config.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'yaml'
|
||||
|
||||
# Configuration loader - loads config defaults and an optional config file
|
||||
class Config
|
||||
|
||||
DEFAULT_CONFIG = 'config/defaults.yaml'
|
||||
|
||||
def initialize(config_path)
|
||||
# Load the default config
|
||||
@data = YAML.load_file(DEFAULT_CONFIG)
|
||||
|
||||
# End if the optional config file doesn't exist
|
||||
return unless File.exist?(config_path)
|
||||
|
||||
# If the optional config exists, load it up!
|
||||
@data.merge!(YAML.load_file(config_path))
|
||||
end
|
||||
|
||||
def get(key)
|
||||
bits = key.split('.')
|
||||
value = @data
|
||||
|
||||
bits.each do |bit|
|
||||
value = value[bit]
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
end
|
@ -1,26 +1,33 @@
|
||||
class AuthController < Sinatra::Base
|
||||
# frozen_string_literal: true
|
||||
|
||||
get '/login' do
|
||||
erb :'auth/login', :locals => {
|
||||
:title => 'Login to your account'
|
||||
}
|
||||
end
|
||||
require 'net/ldap'
|
||||
|
||||
post '/login' do
|
||||
ldap = Net::LDAP.new
|
||||
ldap.host = cnf['ldap']['server_url']
|
||||
ldap.port = 389
|
||||
ldap.auth(params[:login_username], params[:login_password])
|
||||
if ldap.bind()
|
||||
session['ldap_uid'] = params[:username]
|
||||
redirect '/account/view'
|
||||
else
|
||||
# Authentication failure
|
||||
erb :'auth/login', :locals => {
|
||||
:title => 'Login to your account',
|
||||
:fail => true
|
||||
class Webdap
|
||||
# Handles /auth routes
|
||||
class AuthController
|
||||
|
||||
get '/login' do
|
||||
erb :'auth/login', locals: {
|
||||
title: 'Login to your account',
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
post '/login' do
|
||||
ldap = Net::LDAP.new
|
||||
ldap.host = cnf['ldap']['server_url']
|
||||
ldap.port = 389
|
||||
ldap.auth(params[:login_username], params[:login_password])
|
||||
if ldap.bind()
|
||||
session['ldap_uid'] = params[:username]
|
||||
redirect '/account/view'
|
||||
else
|
||||
# Authentication failure
|
||||
erb :'auth/login', locals: {
|
||||
title: 'Login to your account',
|
||||
fail: true,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,14 @@
|
||||
class IndexController < Sinatra::Base
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Webdap
|
||||
# Handles top-level routes
|
||||
class IndexController
|
||||
|
||||
get '/' do
|
||||
erb :index, locals: {
|
||||
title: 'Home',
|
||||
}
|
||||
end
|
||||
|
||||
get '/' do
|
||||
erb :index, :locals => {
|
||||
:title => 'Home'
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
24
app/helpers.rb
Normal file
24
app/helpers.rb
Normal file
@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# ERB view helper functions
|
||||
module Helpers
|
||||
|
||||
def nullable(value)
|
||||
# Returns the value if it actually exists
|
||||
return value if value && (value != '')
|
||||
|
||||
# Returns a default 'N/a' string
|
||||
return 'N/a'
|
||||
end
|
||||
|
||||
def date_format(date)
|
||||
dt = date.to_datetime
|
||||
return dt.strftime('%B %d, %Y, %I:%M:%S %p')
|
||||
end
|
||||
|
||||
def date_format_input(date)
|
||||
dt = date.to_datetime
|
||||
return dt.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Handles LDAP accounts
|
||||
class Account
|
||||
|
||||
def name
|
||||
return 'N/a'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,10 +0,0 @@
|
||||
class Sinatra::Base
|
||||
|
||||
configure do
|
||||
enable :sessions
|
||||
|
||||
set :views, './views'
|
||||
set :public_folder, './public'
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user