summary refs log tree commit diff stats
path: root/web/web.rb
blob: 15c088e78c659e01e9f08ec7d8fc7e9a3614485d (plain) (blame)
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
require 'rack/cache'
require 'yaml'

require 'rubygems'
require 'bundler/setup'
Bundler.require :default

use Rack::Cache

config = YAML.load(open("config.yml"))
db = Sequel.connect("sqlite://#{config["database"]}")

class LingoScore < Sequel::Model
end

get '/' do
  @scores = LingoScore.reverse_order(:score)

  haml :index
end

post '/update' do
  if params[:secret_code] != config["secret_code"] then
    403
  else
    if LingoScore.where(user_id: params[:user_id]).count == 0
      score = LingoScore.new(score: 0)
    else
      score = LingoScore.first(user_id: params[:user_id])
    end
    score.username = params[:username]
    score.avatar_url = CGI.unescape(params[:avatar_url])
    score.score += 1
    score.save

    201
  end
end

get '/style.css' do
  cache_control :public, :max_age => 36000

  scss :style
end