|
@@ -38,7 +38,6 @@ end
|
|
|
|
|
|
class SV < Sinatra::Application
|
|
|
configure do
|
|
|
- STOP_ZEIT = 'Oct 3, 2017, 18:00'
|
|
|
enable :sessions
|
|
|
set :session_secret, (ENV['SV_SESSION_SECRET'] || 'your_secret')
|
|
|
Slim::Engine.set_options pretty: true
|
|
@@ -51,8 +50,17 @@ class SV < Sinatra::Application
|
|
|
end
|
|
|
|
|
|
helpers do
|
|
|
- def ende
|
|
|
- Time.now > time_for(STOP_ZEIT)
|
|
|
+ def vor_der_wahl?
|
|
|
+ Time.now < time_for(ENV['SV_WAHL_BEGINN'])
|
|
|
+ end
|
|
|
+
|
|
|
+ def nach_der_wahl?
|
|
|
+ Time.now > time_for(ENV['SV_WAHL_ENDE'])
|
|
|
+ end
|
|
|
+
|
|
|
+ def wahlzeit?
|
|
|
+ zeit = Time.now
|
|
|
+ (zeit > Time.parse(ENV["SV_WAHL_BEGINN"])) and (zeit < Time.parse(ENV["SV_WAHL_ENDE"]))
|
|
|
end
|
|
|
|
|
|
def protected!
|
|
@@ -82,7 +90,7 @@ class SV < Sinatra::Application
|
|
|
end
|
|
|
|
|
|
get '/' do
|
|
|
- if ende
|
|
|
+ if nach_der_wahl?
|
|
|
redirect to("/ergebnis")
|
|
|
end
|
|
|
infos = Info.all
|
|
@@ -94,7 +102,7 @@ class SV < Sinatra::Application
|
|
|
end
|
|
|
|
|
|
post "/wahl" do
|
|
|
- if ende
|
|
|
+ if wahlzeit?
|
|
|
session[:flash] = [0, "Sie können sich nicht mehr aufstellen lassen, die Wahl hat bereits begonnen"]
|
|
|
redirect back
|
|
|
end
|
|
@@ -130,7 +138,7 @@ class SV < Sinatra::Application
|
|
|
end
|
|
|
|
|
|
get '/ergebnis' do
|
|
|
- protected! if !ende
|
|
|
+ protected! unless nach_der_wahl?
|
|
|
sprecher, schuko, lehrer, waehler = [], [], [], 0
|
|
|
DB.transaction do
|
|
|
sprecher = Schueler.where(:sprecher => true).all
|
|
@@ -164,11 +172,11 @@ class SV < Sinatra::Application
|
|
|
end
|
|
|
|
|
|
post "/:hashid" do
|
|
|
- if ende
|
|
|
- session[:flash] = [0, "Der Wahlzeitraum ist seit 3. Oktober 18:00 Uhr abgelaufen."]
|
|
|
+ if nach_der_wahl?
|
|
|
+ session[:flash] = [0, "Der Wahlzeitraum ist bereits abgelaufen."]
|
|
|
redirect back
|
|
|
- else
|
|
|
- session[:flash] = [0, "Der Wahlzeitraum beginnt erst am 30. September um 18:00 Uhr."]
|
|
|
+ elsif vor_der_wahl?
|
|
|
+ session[:flash] = [0, "Der Wahlzeitraum hat noch nicht begonnen."]
|
|
|
redirect back
|
|
|
end
|
|
|
|