forked from swanson/LandingPad.rb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlandingpad.rb
More file actions
76 lines (64 loc) · 1.99 KB
/
Copy pathlandingpad.rb
File metadata and controls
76 lines (64 loc) · 1.99 KB
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
require 'rubygems'
require 'sinatra/base'
require 'uri'
require 'mongo'
require 'erb'
require 'json'
class LandingPad < Sinatra::Base
set :static, true
set :public, 'public'
configure do
# Admin settings - used to access contacts
$admin_acct_name = 'admin'
$admin_acct_passwd = 'admin'
# Page settings - used to configure your landing page
$page_title = 'LandingPad.rb | Just add water landing pages'
$app_title = 'LandingPad.rb'
$app_summary = 'Get a page up and running in minutes and
start collecting contacts immediately!'
#your google analyics tracking key, if applicable
$google_analyics_key = 'UA-XXXXXX-X'
$bg_color = '#2B2F3D'
$app_title_color = '#FFFFFF'
#see http://code.google.com/webfonts for available fonts
$app_title_font = 'Philosopher'
# Database settings - do NOT change these
uri = URI.parse(ENV['MONGOHQ_URL'])
conn = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
db = conn.db(uri.path.gsub(/^\//, ''))
$collection = db.collection("contacts")
end
helpers do
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
throw(:halt, [401, "Not authorized\n"])
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [$admin_acct_name, $admin_acct_passwd]
end
end
get '/' do
erb :index
end
get '/contacts' do
protected!
@contacts = $collection.find()
erb :contacts
end
post '/subscribe' do
content_type :json
contact = params[:contact]
contact_type = contact.start_with?("@") ||
!contact.include?("@") ? "Twitter" : "Email"
doc = {
"name" => contact,
"type" => contact_type,
"referer" => request.referer,
}
$collection.insert(doc)
{"success" => true, "type" => contact_type}.to_json
end
end