-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.rb
58 lines (46 loc) · 1.17 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
# frozen_string_literal: true
require 'sinatra'
class App < Sinatra::Base
# TODO: Configure and helpers to a folder. Clean up!
configure do
enable :sessions
end
helpers do
def username
erb :'layout/username'
end
end
# TODO: Error must be ERB (as posible)
before '/secure/*' do
unless session[:identity]
session[:previous_url] = request.path
@error = print_error(request.path)
halt erb(:login_form)
end
end
# GET methods
get('/') { redirect '/inicio' } # Home website
# Private Zone
get('/secure/place') { erb :'private/secreto' }
get('/login/form') { erb :login_form }
get '/logout' do
session.delete(:identity)
erb :'alerts/logout'
end
# Templates with double-routing
get '/:view/:param' do |view, _param|
preview(view)
end
# Templates with simple root-viewer
get '/:view' do |view|
preview(view)
end
# POST methods
post('/calculador') { preview('calculador') }
post('/buscar') { preview('heroes') }
post '/login/attempt' do
session[:identity] = params['username']
where_user_came_from = session[:previous_url] || '/'
redirect to where_user_came_from
end
end