-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
63 lines (56 loc) · 1.2 KB
/
main.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
require 'sinatra'
require_relative 'shared.rb'
require_relative 'models/users.rb'
require_relative 'models/product.rb'
require_relative 'models/orders.rb'
require_relative 'controllers/product.rb'
require_relative 'controllers/user.rb'
require_relative 'controllers/orders.rb'
if development?
require 'sinatra/reloader'
require 'pry'
also_reload 'shared.rb'
also_reload 'models/users'
also_reload 'models/product.rb'
also_reload 'models/orders.rb'
also_reload 'controllers/product.rb'
also_reload 'controllers/user.rb'
also_reload 'controllers/orders.rb'
end
enable :sessions
get '/' do
if session[:role] == 'admin'
redirect '/admin'
elsif session[:role] == 'customer'
redirect '/customer'
else
resetsession()
erb :index
end
end
post '/' do
login_user(params[:uname],params[:psw])
end
get '/admin' do
if session[:role] == 'admin'
@open_orders = get_open_orders()
#binding.pry
erb :admin
else
resetsession()
redirect '/'
end
end
get '/customer' do
if session[:role] == 'customer'
@products = show_all_product()
erb :customer
else
resetsession()
redirect '/'
end
end
delete '/session' do
resetsession()
redirect '/'
end