-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.rb
79 lines (62 loc) · 1.4 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'sinatra/base'
require 'sinatra/reloader'
require './lib/user'
require './lib/home'
class App < Sinatra::Base
enable :sessions
get '/' do
redirect to '/signup'
end
get '/signup' do
erb :signup
end
post '/signup' do
user = User.create(username: params[:username], password: params[:password], email: params[:email])
session[:user] = user
redirect to '/selection'
end
get '/login' do
erb :login
end
post '/login' do
user = User.login_find(username: params[:username], password: params[:password])
session[:user] = user
redirect to '/selection'
end
get '/selection' do
@homes = Home.all
erb :selection
end
get '/homes' do
@homes = Home.all
erb :homes
end
post '/homes' do
session[:home] = Home.select(id: params[:id])
redirect to '/request'
end
get '/request' do
@home = Home.select(id: params[:id])
erb :request
end
post '/request' do
@booking = Booking.request
redirect to '/profile'
end
post '/logout' do
session[:user] = nil
redirect to '/login'
end
get '/list' do
@homes = Home.all
erb :list
end
post '/list' do
Home.create(home_name: params[:home_name], description: params[:description], price: params[:price], owner_id: session[:user].id)
redirect to '/selection'
end
get '/profile' do
erb :profile
end
run! if app_file == $0
end