Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Feb 23, 2016
1 parent 4a762e2 commit b499fa4
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions app/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Web < Common

configure do
set :session_secret, settings.configdata['session_seed']
set :public_folder, Proc.new { File.join(root, "public") }
set :views_folder, Proc.new { File.join(root, "views") }
set :public_folder, -> { File.join(root, 'public') }
set :views_folder, -> { File.join(root, 'views') }
set :erb, layout: :_layout
enable :sessions
end
Expand Down Expand Up @@ -51,7 +51,7 @@ def check_authorization

use Rack::Auth::Basic, "Puppet Private Access" do |user, pass|
user == settings.configdata['http_auth']['username'] &&
pass == settings.configdata['http_auth']['password']
pass == settings.configdata['http_auth']['password']
end

get '/logout' do
Expand All @@ -60,7 +60,7 @@ def check_authorization

helpers do
def check_authorization
if !session['access_token']
unless session['access_token']
session[:access_token] = settings.configdata['http_auth']['access_token']
end
settings.configdata['http_auth']['username']
Expand All @@ -74,20 +74,20 @@ def check_authorization
helpers do

def check_authorization
if !session['access_token']
redirect settings.oauth.login_url(request)
else
if session['access_token']
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
if !session_info
if !settings.oauth.authorized?(session['access_token'])
flash[:fatal] = "Sorry you are not authorized to read puppet repo on gitlab."
flash[:fatal] = 'Sorry you are not authorized to read puppet repo on gitlab.'
redirect '/'
else
Hieraviz::Store.set session['access_token'], settings.oauth.user_info(session['access_token'])
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
end
end
session_info['username']
else
redirect settings.oauth.login_url(request)
end
end
end
Expand All @@ -100,7 +100,7 @@ def check_authorization
access_token = settings.oauth.access_token(request, params[:code])
session[:access_token] = access_token.token
Hieraviz::Store.set access_token.token, settings.oauth.user_info(access_token.token)
flash['info'] = "Successfully authenticated with the server"
flash['info'] = 'Successfully authenticated with the server'
redirect '/'
end

Expand All @@ -109,15 +109,13 @@ def check_authorization
redirect '/'
end

else
end

get '/' do
if settings.basepaths
redirect "/#{File.basename(settings.configdata['basepath'])}"
else
@username = username
hieracles_config = prepare_config(nil)
erb :home
end
end
Expand All @@ -136,27 +134,27 @@ def check_authorization
erb :farms
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/modules} do |base|
get %r{^/?([-_\.a-zA-Z0-9]+)?/modules} do
@username = check_authorization
erb :modules
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/resources} do |base|
get %r{^/?([-_\.a-zA-Z0-9]+)?/resources} do
@username = check_authorization
erb :resources
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/user} do |base|
get %r{^/?([-_\.a-zA-Z0-9]+)?/user} do
@username = check_authorization
if session[:access_token]
@userinfo = userinfo
@userinfo = userinfo
else
@userinfo = {}
end
erb :user
end

get %r{^/([-_\.a-zA-Z0-9]+)$} do |base|
get %r{^/([-_\.a-zA-Z0-9]+)$} do
@username = username
erb :home
end
Expand All @@ -180,6 +178,5 @@ def check_authorization
erb :not_found, layout: :_layout
end


end
end

0 comments on commit b499fa4

Please sign in to comment.