-
Notifications
You must be signed in to change notification settings - Fork 0
/
eve-web.rb
69 lines (52 loc) · 1.48 KB
/
eve-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
%w[sinatra sequel slim json active_support/inflector].each { |lib| require lib }
# CONFIG
##############################################
Sequel.connect ENV["DATABASE_URL"]
# load models after connection was established
%w[serial_number kagi_response account shortcut].each { |model| require "./models/#{model}" }
# WEB
##############################################
get "/" do
@title = "Get Started"
slim :index
end
get "/shortcuts" do
@title = "Online DB"
@shortcuts = Shortcut.where(:AppName => Shortcut::STANDARD_APPS).order(:AppName).to_a.group_by(&:AppName)
slim :shortcuts
end
get "/:site" do |site|
@title = ActiveSupport::Inflector.titleize(site)
layout = (params["plain"] == "true" ? :plain : :layout)
slim site.to_sym, layout: layout
end
get "/apps" do
@title = "Apps"
slim :apps
end
# API
##############################################
post "/lcg" do
begin
if params.fetch("ACG:Flags", "").include?("Test=1")
accounts = [Account.example]
else
accounts = Account.generate(params)
end
KagiResponse.success(accounts)
rescue Sequel::InvalidValue
KagiResponse.failed("Incomplete request. Did you submit an email?")
end
end
post "/verify" do
begin
Account.verify JSON.parse(request.body.read.to_s)
200
rescue JSON::ParserError
[400, "Malformed request / JSON can't be parsed"]
rescue Account::Unknown, Account::EmptyMac => e
[406, e.message]
rescue Account::LicenceLimit => e
[403, e.message]
end
end