From d9598e221be8701a32e85d1de9c113b17ebb6676 Mon Sep 17 00:00:00 2001 From: Adam Gyulavari Date: Tue, 8 Oct 2019 20:32:24 +0800 Subject: [PATCH] current link and auth method --- konnekt_live.rb | 17 ++++++++++------- views/admin.haml | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/konnekt_live.rb b/konnekt_live.rb index 58e8ce3..8357ba6 100644 --- a/konnekt_live.rb +++ b/konnekt_live.rb @@ -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 @@ -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 @@ -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" @@ -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'] diff --git a/views/admin.haml b/views/admin.haml index 28e7127..96a02c9 100644 --- a/views/admin.haml +++ b/views/admin.haml @@ -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]}