-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
69 lines (58 loc) · 1.17 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
64
65
66
67
68
69
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
# require 'sinatra/reloader' if development?
require 'sass'
require 'slim'
require './song'
configure :development do
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
enable :sessions
set :username, 'frank'
set :password, 'sinatra'
end
configure :production do
DataMapper.setup(:default, ENV['DATABASE_URL'])
enable :sessions
set :username, 'frank'
set :password, 'sinatra'
end
get '/styles.css' do
scss :styles
end
get '/' do
slim :home
# erb :home
end
get '/about' do
@title = "All About This WebSite"
slim :about
# erb :about
end
get '/contact' do
slim :contact
# erb :contact
end
get '/set/:name' do
session[:name] = params[:name]
end
get '/get/hello' do
"Hello #{session[:name]}"
end
get '/login' do
slim :login
# erb :login
end
post '/login' do
if params[:username] == settings.username && params[:password] == settings.password
session[:admin] = true
redirect to('/songs')
else
slim :login
# erb :login
end
end
get '/logout' do
session.clear
redirect to('/login')
end