-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
67 lines (57 loc) · 1.66 KB
/
web.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 'haml'
require 'mongoid'
require 'rack-flash'
require 'rack/ssl'
require 'rack/rewrite'
require 'sinatra/base'
require 'sinatra/respond_with'
require 'trello'
require_relative 'helpers'
class Ollert < Sinatra::Base
helpers OllertApp::Helpers
register Sinatra::RespondWith
configure :development do
require 'sinatra/reloader'
register Sinatra::Reloader
end
configure do
use Rack::MethodOverride
use Rack::Deflater
I18n.enforce_available_locales = true
Mongoid.logger = Logger::WARN
Mongo::Logger.logger.level = Logger::WARN
Mongoid.load! "#{File.dirname(__FILE__)}/mongoid.yml"
end
use Rack::Session::Cookie, secret: ENV['SESSION_SECRET'], expire_after: 30 * (60*60*24) # 30 days in seconds
use Rack::Flash, sweep: true
configure :production do
use Rack::SSL
use Rack::Rewrite do
r301 %r{.*}, 'https://ollertapp.com$&', :if => Proc.new {|rack_env|
rack_env['SERVER_NAME'] != 'ollertapp.com'
}
end
end
set(:auth) do |role|
condition do
@user = session[:user].nil? ? nil : User.find(session[:user])
if role == :connected
if @user.nil?
session[:user] = nil
flash[:warning] = "Hey! You should create an account to do that."
redirect '/'
end
end
end
end
error Trello::Error do
body "There's something wrong with the Trello connection. Please re-establish the connection."
status 500
end
end
Dir.glob("#{File.dirname(__FILE__)}/models/*.rb").each do |file|
require file.chomp(File.extname(file))
end
Dir.glob("#{File.dirname(__FILE__)}/routes/*.rb").each do |file|
require file.chomp(File.extname(file))
end