-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.rb
executable file
·51 lines (39 loc) · 1.04 KB
/
site.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
#!/usr/bin/env ruby
require 'sinatra'
require 'dotenv/load'
require_relative 'auth'
require_relative 'helpers'
require_relative 'api'
require_relative 'db'
configure do
enable :sessions
end
get '/' do
erb :index
end
get '/user' do
authenticate!
# Used by search bar
redirect "/user/#{params[:login]}" unless params[:login].nil?
# Redirect to the authorized user's page
redirect "/user/#{get_login(session[:token])}"
end
get '/user/:login' do
authenticate!
erb :user, locals: { name: params[:login] }
end
post '/user/:login/read' do
read_cache(params[:login])
end
# TODO: don't need to populate here, since /update is called when the page loads
# so we know populate has already been called.
post '/user/:login/forceupdate' do
populate_cache(session[:token], params[:login])
force_update_cache(session[:token], params[:login])
read_cache(params[:login])
end
post '/user/:login/update' do
populate_cache(session[:token], params[:login])
update_cache(session[:token], params[:login])
read_cache(params[:login])
end