-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
58 lines (47 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
require 'sinatra'
require 'sinatra/reloader'
require 'sinatra/activerecord'
require 'sinatra/flash'
require 'carrierwave'
require 'carrierwave/orm/activerecord'
require 'carrierwave/processing/mini_magick'
require 'i18n'
require 'i18n/backend/fallbacks'
require 'will_paginate'
require 'will_paginate/active_record'
helpers do
def authenticated?
session.include? :id
end
def admin?
session[:admin]
end
def student?
authenticated? && !admin?
end
end
register do
def allow(*roles)
condition do
if roles.include? :user
redirect '/user/login' unless authenticated?
elsif roles.include? :admin
redirect back unless admin?
end
end
end
end
Dir["#{__dir__}/models/*.rb"].each { |file| require_relative file }
Dir["#{__dir__}/routes/*.rb"].each { |file| require_relative file }
set :environment, :development
enable :sessions
set :session_secret, '*&(^B234'
configure do
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = Dir[File.join(settings.root, 'config', 'locales', '*.yml')]
I18n.backend.load_translations
I18n.config.available_locales = %i[en bg]
end
get '/' do
erb :index
end