-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
75 lines (68 loc) · 1.83 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
68
69
70
71
72
73
74
75
require 'sinatra'
require 'digest'
require 'rufus/scheduler'
require './template'
require './local_sequel'
require './ping_self'
require './markdown-sinatra'
require 'pony'
require 'pp'
require 'yaml'
require 'cgi' #SOOO MANY LIBRARIEZZZZZ!
require 'json'
require 'rack/recaptcha'
require './check_migrations' #OH NO! CHECKING MIGRATIONS!
require './check_votes'
require './site_setup'
$development = development?
if development?
require 'sinatra/reloader'
also_reload './template.rb'
end
def valid_email?(email)
#return true unless ENV['TESTING_ENV'].nil?
return true unless email.match(/^\w*@\w*\.\w{2,5}(\.\w{2,5})?$/).nil?
return false
end
def valid_username?(name)
return true unless name.match(/^[\w_^\- ]{1,20}$/).nil?
return false
end
before do
if request.host == "storybouncer.com"
redirect request.url.gsub("storybouncer.com","www.storybouncer.com"),301
end
if $development
headers("Cache-Control" => "no-cache, no-store, must-revalidate",
"Pragma" => "no-cache",
"Expires" => "0")
end
@user = nil
if session[:userid]
begin
user = User.new(session[:userid])
@user = user
session[:user] = user.name
session[:logged] = true
rescue ItemDoesntExist
session.clear
end
elsif session[:logged] #but NO userid!
session.clear
end
if @user and @user.name.downcase == "epicricekakes" and !request.url.include?('/fuck-you-youre-banned')
redirect to("/fuck-you-youre-banned")
end
end
get '/fuck-you-youre-banned' do
error 404 unless @user and @user.name.downcase == "epicricekakes"
template("You are now banned.") do |h|
h.h1{"You are now banned."}
h.p{"If you wish to repeal your ban, please contact [email protected]"}
end
end
Dir['./pages/*.rb'].each do |f|
puts "Loading #{f}"
require f
also_reload f if development?
end