-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.rb
84 lines (66 loc) · 1.8 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
80
81
82
83
84
require 'sinatra/base'
require_relative './database_connection_setup.rb'
require './lib/user'
require './lib/property'
require './lib/booking'
require 'sinatra/flash'
require 'uri'
class Makersbnb < Sinatra::Base
enable :sessions
register Sinatra::Flash
get '/' do
erb :'signup'
end
post '/' do
User.create(email: params[:email], password: params[:password])
flash[:notice] = 'Account Created'
redirect '/sessions/new'
end
get '/sessions/new' do
erb :'sessions/new'
end
post '/sessions' do
user = User.authenticate(email: params[:email], password: params[:password])
if user
session[:user_id] = user.id
redirect('/property')
else
flash[:notice] = 'Please check your email or password.'
redirect('/sessions/new')
end
end
post '/sessions/destroy' do
session.clear
flash[:notice] = 'You have successfully signed out'
redirect('/')
end
get '/property' do
@user = User.find(id: session[:user_id])
@properties = Property.all
erb :'property/index'
end
post '/property' do
Property.create(name: params['name'], description: params['description'], cost: params['cost'], user_id: session[:user_id])
redirect '/property'
end
get '/property/new' do
erb :'property/new'
end
get '/property/:id/book' do
@property = Property.find(id: params[:id])
session[:property_id] = @property.id
erb :'property/request_booking'
end
post '/property/confirm' do
booking = Booking.create(property_id: session[:property_id], user_id: session[:user_id])
availability = Property.availability(id: session[:property_id])
redirect 'property/confirm'
end
get '/property/confirm' do
erb :'property/confirm'
end
get '/property' do
redirect '/property'
end
run! if app_file == $0
end