-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
executable file
·103 lines (93 loc) · 2.95 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
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
require 'sinatra/base'
require 'erb'
require 'ohm'
require 'mail'
require 'cgi'
require 'uri'
require 'differ'
require 'base64'
require 'json'
require 'dalli'
require 'rack-cache'
require 'sinatra/assetpack'
require_relative 'helpers/tzinfo_timezone'
class ItymsApp < Sinatra::Application
set :root, File.dirname(__FILE__)
register Sinatra::AssetPack
set :sessions, true
set :protection, :except => [:remote_token, :json_csrf]
APP_CONFIG = YAML.load_file("config/environment.yml")['production']
configure :production do
$testing = false
set :raise_errors, false
set :show_exceptions, false
require 'newrelic_rpm'
set :cache, Dalli::Client.new
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.sendgrid.net',
:port => 587,
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true }
end
end
configure :development do
require 'better_errors'
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path("..", __FILE__)
$testing = true
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true }
end
end
assets {
js :validate, ['js/validate.min.js']
css :application, [
'css/base.css',
'css/layout.css',
'css/skeleton.css',
'css/custom.css'
]
js_compression :jsmin
css_compression :simple
}
$mail_username = ENV['SENDGRID_USERNAME']
$top_domain = APP_CONFIG['top_domain']
$timezone_set = false
$timezoneoffset = TzinfoTimezone.new("Eastern Time (US & Canada)").dst_utc_offset
Differ.format = :html
$plugin_link = "https://chrome.google.com/webstore/detail/ityms/dmfehapjdpdelmpikcbdicfmolflpckg"
before do
#cache_control :public, max_age: 60
if (@logged_in_user = User[session["user_id"]] and @logged_in_user.activated == "true")
unless $timezone_set
$timezone_set = true
$timezoneoffset = TzinfoTimezone.new(@logged_in_user.timezone).dst_utc_offset
end
if %w(/admin).include?(request.path_info) and
@logged_in_user.permission_level != "admin"
goto_login "You don't have the permission to access that page."
end
else
unless %w(/login /signup /resetpassword /getactivationlink /unactivated /about /terms /privacy /contact /changedpassword).include?(request.path_info) or
request.path_info =~ /\.(css|js|png|ico)$/ or request.path_info =~ /(activate|api|changepassword)/ or request.path_info == '/'
redirect '/login', 303
end
end
end
helpers do
end
end
require_relative 'helpers/init'
require_relative 'routes/init'
require_relative 'models/init'