-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
42 lines (31 loc) · 861 Bytes
/
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
require 'bundler'
Bundler.require :default
set :port, 8080
set :static, true
set :public_folder, 'static'
set :views, 'views'
get '/' do
haml :register_form
end
post '/register' do
email = params[:name]
name = params[:email]
hash = JSON.parse(File.read('./secrets.json'))
session = GoogleDrive.saved_session('config.json')
ws = session.spreadsheet_by_key(hash['spreadsheet_id']).worksheets[0]
next_empty_row = ws.num_rows + 1
ws[next_empty_row, 1] = email
ws[next_empty_row, 2] = name
ws.save
end
get '/check' do
email = params[:email]
hash = JSON.parse(File.read('./secrets.json'))
session = GoogleDrive.saved_session('config.json')
ws = session.spreadsheet_by_key(hash['spreadsheet_id']).worksheets[0]
ws.num_rows.times do |i|
cell = ws[i + 1, 2]
return 'Email exists' if cell == email
end
return 'OK'
end