Module: Buzzard::Security::Extension

Defined in:
lib/buzzard/security.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



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
# File 'lib/buzzard/security.rb', line 12

def self.registered(app)
  app.get("/login") do
    redirect "/" if logged_in?

    erb :login
  end

  app.post("/login") do
    redirect "/" if logged_in?

    user = authenticate(params[:username], params[:password])
    if !user.nil?
      session[:user] = user
      redirect post_auth_url
    else
      flash[:errors] = ["Invalid username or password"]
      redirect "/login"
    end
  end

  app.get("/logout") do
    redirect "/" if !logged_in?

    session.delete(:user)
    flash[:messages] = ["You have been logged out"]
    redirect "/login"
  end
end