-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
67 lines (57 loc) · 1.45 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
require "sinatra/base"
require "mustache/sinatra"
require "views/layout"
module Spurious
module Browser
class App < Sinatra::Base
register Mustache::Sinatra
set :sessions => true
set :mustache, {
:views => File.join(File.dirname(__FILE__), 'views'),
:templates => File.join(File.dirname(__FILE__), 'templates'),
:namespace => Spurious::Browser
}
register do
def auth (type)
condition do
redirect "/login" unless send("is_authenticated?")
end
end
end
helpers do
def is_authenticated?
session[:credentials]
end
end
before /^(?!\/(login))/ do
if session[:credentials]
AWS.config session[:credentials]
@logged_in = true
else
redirect '/login'
end
end
get '/' do
mustache :index
end
get '/login' do
mustache :login
end
post '/login' do
session[:credentials] = {
:access_key_id => params['accessKeyId'],
:secret_access_key => params['secretAccessKey'],
:region => params['region']
}
redirect '/'
end
get '/logout' do
session.delete(:credentials)
redirect '/login'
end
get '/secure/place' do
erb "This is a secret place that only <%=session[:identity]%> has access to!"
end
end
end
end