Skip to content

Commit

Permalink
current link and auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gyulavari committed Oct 8, 2019
1 parent 3173824 commit d9598e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions konnekt_live.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# require './dummy_database'

class KonnektLive < Sinatra::Base
private_secrets = JSON.parse(File.open('config/secrets.json').read)

def initialize
super
@private_secrets = JSON.parse(File.open('config/secrets.json').read)
@db = Database.new
end

Expand Down Expand Up @@ -99,9 +99,7 @@ def sort_by(hash, by)
end

get '/admin' do
if params['key'] != private_secrets['admin_key']
redirect '/'
end
authorize!

get_admin_data
setup
Expand All @@ -110,9 +108,8 @@ def sort_by(hash, by)
end

get '/csv' do
if params['key'] != private_secrets['admin_key']
redirect '/'
end
authorize!

content_type 'application/csv'
attachment "konnekt_live_registrations-#{Time.now.strftime("%Y%m%d-%H%M")}.csv"

Expand All @@ -129,6 +126,12 @@ def sort_by(hash, by)

private

def authorize!
if params['key'] != @private_secrets['admin_key']
redirect '/'
end
end

def get_admin_data
prefix = ''
if params['year']
Expand Down
3 changes: 3 additions & 0 deletions views/admin.haml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
%section.title
%h3.rotate-r1.blue Archives
.profs
%h4.purple
%a{href: '/admin?key=' + params[:key]}
Current
- @archives.each do |archive|
%h4.purple
%a{href: '/admin?key=' + params[:key] + '&year=' + archive[0]}
Expand Down

0 comments on commit d9598e2

Please sign in to comment.