-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
183 lines (148 loc) · 4.08 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env ruby
require 'sinatra/base'
require 'sinatra/reloader'
require 'sinatra/flash'
require_relative 'app/helpers/app_helper'
require_relative 'app/helpers/overlord_helpers'
require_relative 'app/models/trigger'
require_relative 'app/models/timer'
require_relative 'app/models/bomb'
module Project
class Veilus < Sinatra::Base
register Sinatra::Reloader
register Sinatra::Flash
helpers AppHelpers
helpers OverlordHelpers
configure do
enable :sessions
enable :logging
enable :dump_errors
enable :method_override
set :server, :puma
set :name, "Spec Workshop"
set :views, "app/views"
set :username, "admin"
set :password, "admin"
set :start_time, Time.now
set :session_secret, "spatially foliated hypersurfaces with acausal temporal coordinates"
end
#before do
# last_modified settings.start_time
# etag settings.start_time.to_s
# cache_control :public, :must_revalidate
#end
get '/' do
erb :index, layout: :initial
end
post '/' do
if (params[:username] == settings.username && params[:password] == settings.password)
session[:admin] = true
flash[:notice] = "You are now logged in as #{params[:username]}."
session[:current_user] = params[:username]
redirect to('/home')
elsif (params[:username] == "tester" && params[:password] == "testing")
session[:tester] = true
flash[:notice] = "You are now logged in as #{params[:username]}."
session[:current_user] = params[:username]
redirect to('/home')
else
if params[:username].empty?
flash[:error] = "No login name was specified."
else
flash[:error] = "Unable to login as #{params[:username]}."
end
redirect to('/')
end
end
get '/home/?' do
protected!
title 'Home'
erb :home
end
get '/logout' do
session.clear
flash[:notice] = 'You have been logged out.'
redirect to('/')
end
get '/stardate/?' do
protected!
title 'Stardate Calculator'
erb :stardate
end
get '/planets/?' do
protected!
title 'Planet Weight Calculator'
erb :planets
end
get '/warp/?' do
protected!
title 'Warp Factor Calculator'
erb :warp
end
get '/warcraft/?' do
protected!
title 'World of Warcraft'
erb :warcraft
end
# Start: Practice
get '/practice/?' do
title 'Practice Page'
erb :practice
end
get '/practice/drag_and_drop' do
title 'Practice - Drag and Drop'
erb :'practice/drag_and_drop'
end
get '/practice/js_alerts' do
title 'Practice - JavaScript Alerts'
erb :'practice/js_alerts'
end
get '/practice/dynamic_controls' do
title 'Practice - Dynamic Controls'
erb :'practice/dynamic_controls'
end
get '/practice/dynamic_events' do
title 'Practice - Dynamic Events'
erb :'practice/dynamic_events'
end
# Finish: Practice
# Start: Overlord
get '/overlord/?' do
admin_protected!
title 'Project Overlord'
erb :overlord
end
post '/overlord' do
session[:activate] = params[:activation_code]
session[:deactivate] = params[:deactivation_code]
session[:countdown] = params[:countdown_value]
redirect to('/bomb')
end
post '/set/:seconds' do
@bomb = session[:bomb]
timer.reset(params[:seconds].to_i)
end
get '/enter/:code?' do
@bomb = session[:bomb]
if trigger.valid?(params[:code])
trigger_bomb_state(trigger, timer)
else
flash[:invalid_code] = 'The code must be four numeric characters.'
end
redirect to('/bomb')
end
get '/bomb' do
@bomb = session[:bomb] || provide_bomb
session[:bomb] = @bomb
erb :'overlord/bomb'
end
def trigger
@bomb.components[:trigger]
end
def timer
@bomb.components[:timer]
end
# Finish: Overlord
end
end
Project::Veilus.run! port: 9292 if __FILE__ == $PROGRAM_NAME