-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifesto.rb
74 lines (62 loc) · 1.64 KB
/
manifesto.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
require 'rubygems'
require 'sinatra'
require 'json'
require 'omniauth'
require 'omniauth-twitter'
require 'mongoid'
require './signee'
require 'dotenv'
Dotenv.load
Mongoid.load!('mongoid.yml')
DOMAIN = ENV['DOMAIN'] || 'cleanweb.org.uk'
configure do
set :sessions, true
set :inline_templates, true
set :root, File.dirname(__FILE__)
end
use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_CONSUMER_KEY'], ENV['TWITTER_CONSUMER_SECRET']
end
get '/' do
erb :index
end
get '/auth/:provider/callback' do
# Get omniauth data
auth_data = request.env['omniauth.auth']
session[:user] = "#{auth_data['provider']}:#{auth_data['uid']}"
# Store signature
if Signee.find_by(:twitter_id => auth_data['uid']).nil?
s = Signee.create(
:twitter_id => auth_data['uid'],
:name => auth_data['info']['name'],
:nickname => auth_data['info']['nickname'],
:location => auth_data['info']['location'],
:description => auth_data['info']['description'],
:image => auth_data['info']['image'],
:twitter_url => auth_data['info']['urls']['Twitter'],
:website => auth_data['info']['urls']['Website']
)
end
# Redirect to signed page
redirect '/signed'
end
get '/auth/failure' do
erb :auth_failed
end
get '/auth/:provider/deauthorized' do
erb :deauthorized
end
get '/signed' do
redirect '/' and return unless session[:user]
@count = Signee.count
erb :signed
end
get '/signatories' do
@count = Signee.count
@signatories = Signee.all.reverse
erb :signatories, :layout => false
end
get '/count' do
@count = Signee.count
erb :count, :layout => false
end