-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathapp.rb
47 lines (40 loc) · 843 Bytes
/
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
require 'sinatra'
require 'sass'
class Capybara101 < Sinatra::Base
enable :sessions
helpers do
def logged_in?
session[:user]
end
end
get "/" do
haml :index
end
post '/login' do
if params[:username] == params[:password]
session[:user] = params[:username]
redirect to '/dashboard'
else
@message = 'Your username & password did not match'
haml :index
end
end
get '/logout' do
@message = 'You have been logged out'
session.clear
haml :index
end
get "/dashboard" do
#@username = session[:user]
#haml :dashboard
#first check if user is authenticated or not
if logged_in?
@username = session[:user]
haml :dashboard
else
@message = 'Unauthorized access!'
#redirect to home page
haml :index
end
end
end