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
|
# File 'lib/shield/contrib/sinatra/default.rb', line 4
def self.registered(m)
m.set :shield_redirect_after_login, "/"
m.set :shield_redirect_after_logout, "/"
m.set :shield_auth_failure, "Wrong Username and/or Password combination."
m.helpers Shield::Helpers
m.helpers do
def current_user
authenticated(User)
end
def is_logged_in?
!! current_user
end
def ensure_authenticated(model = User)
super
end
def authenticated?(model = User)
authenticated(model)
end
end
m.get "/login" do
haml :login
end
m.post "/login" do
if login(User, params[:username], params[:password])
redirect_to_stored(settings.shield_redirect_after_login)
else
session[:error] = settings.shield_auth_failure
redirect_to_login
end
end
m.get "/logout" do
logout(User)
redirect settings.shield_redirect_after_logout
end
end
|