-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
50 lines (42 loc) · 1000 Bytes
/
server.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
require 'sinatra'
require 'sinatra/flash'
require 'sinatra/partial'
require_relative './lib/client.rb'
require_relative './lib/file_meta.rb'
enable :sessions, :method_override
set :session_secret, 'super secret'
set :partial_template_engine, :erb
get '/' do
erb :index
end
post '/session' do
email, password = params[:email], params[:password]
client = Client.new(email, password)
client.login
session['email'] = email
session['password'] = password
redirect to '/files'
end
get '/files' do
if session['email']
client = Client.new(session['email'], session['password'])
client.login
files = client.get_files
@data = FileMeta.new(files)
erb :files
else
erb :restricted
end
end
delete '/session' do
client = Client.new(session[:email], session[:password])
client.login
client.logout
session[:email] = nil
session[:password] = nil
flash[:next] = "Thank you for using File Gravity, goodbye."
redirect to '/'
end
error do
erb :error
end