-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.rb
132 lines (102 loc) · 3.25 KB
/
application.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
require 'bundler/setup'
require 'dependor/shorty'
Bundler.require
module Repositories; end
module Connections; end
module RaspberryPi; end
module Presenters; end
module Components; end
module Uploaders; end
module Parsers; end
module Skirace; end
auto_load_paths = %w(../config/initializers/*.rb ../app/**/*.rb ../lib/**/*.rb).each do |path|
Dir[File.expand_path(path, __FILE__)].each do |file|
next if file.include?('routes')
require file
end
end
class Skirace::Application < Sinatra::Base
set :static, :enable
set :views, Proc.new { File.join(root, "app", "views") }
set :public_folder, File.join(root, "public")
set :assets_prefix, '/assets'
set :assets_path, File.join(public_folder, assets_prefix)
set :sprockets, Sprockets::Environment.new(root)
set :precompile, [ /\w+\.(?!js\.coffee).+/, /application\.js$/ ]
set :digest_assets, production?
helpers do
include ApplicationHelper
include Sprockets::Helpers
end
injector do |objects|
Injector.new(objects)
end
configure :development, :production do
enable :logging
log_file = File.new('./log/application.log', 'a+')
log_file.sync = true
use Rack::CommonLogger, log_file
use Rack::Session::Memcache, memcache_server: 'localhost:11211', namespace: 'skirace'
use Warden::Manager do |config|
config.serialize_into_session do |user|
user.auth_token
end
config.serialize_from_session do |token|
User.find(auth_token: token)
end
config.scope_defaults :default, strategies: [:password], action: '/forbidden'
config.failure_app = self
end
Warden::Strategies.add(:password) do
def valid?
@params = parse_params
@params['username'] && @params['password']
end
def authenticate!
user = injector.user_repository.get_by_username(@params['username'])
if injector.authentication_service.authenticate(user, @params['password'])
success!(user)
else
fail!
end
end
private
def injector
@injector ||= Injector.new
end
def parse_params
injector.json_parser.parse(request.body.read)
rescue
{}
end
end
sprockets.append_path File.join(root, 'app', 'assets', 'javascripts')
sprockets.append_path File.join(root, 'app', 'assets', 'stylesheets')
sprockets.append_path File.dirname(HamlCoffeeAssets.helpers_path)
Sprockets::Helpers.configure do |config|
config.environment = sprockets
config.environment.js_compressor = :uglify
config.environment.css_compressor = :scss
config.prefix = assets_prefix
config.digest = digest_assets
config.public_path = public_folder
end
end
def production?
ENV['RACK_ENV'] == 'production'
end
get '/' do
haml "home/index".to_sym, layout: :website
end
get '/forbidden' do
haml :forbidden
end
end
require_relative 'app/routes/login'
require_relative 'app/routes/users'
require_relative 'app/routes/export'
require_relative 'app/routes/import'
require_relative 'app/routes/settings'
require_relative 'app/routes/contests'
require_relative 'app/routes/contestants'
require_relative 'app/routes/api/endtime'