-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.rb
53 lines (42 loc) · 787 Bytes
/
store.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
# dev hint: shotgun login.rb
require 'rubygems'
require 'sinatra'
require 'rest-client'
require 'json'
require 'rack-flash'
require 'lib/auth/auth.rb'
class Store < Sinatra::Base
use Rack::Flash
use Auth
enable :sessions
helpers do
def logged_in?(user)
token = User.get_token(user)
request.cookies[user] == token
end
def protected!
redirect '/login' unless logged_in?(session[:user])
end
end
configure do
set :public_folder, Proc.new { File.join(root, "static") }
end
get '/' do
protected!
@title = 'shop'
@sidebar = 'side'
erb 'ciao'
end
get '/register' do
erb :register
end
get '/login' do
erb :login
end
get '/logout' do
@name = session[:user]
response.set_cookie(@name, nil)
session[:user] = nil
redirect '/'
end
end