module Shield
  module Sinatra
    module Default
      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.enable :sessions

        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 settings.shield_redirect_after_login
          else
            session[:error] = settings.shield_auth_failure
            redirect "/login"
          end
        end

        m.get "/logout" do
          logout(User)
          redirect settings.shield_redirect_after_logout
        end
      end
    end
  end
end
module Shield
  module Sinatra
    module Default
      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.enable :sessions

        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
    end
  end
end
Fix the redirection login in the /login route.
Fix the redirection login in the /login route.
