Sha256: f68765ac896bdca0fbbad8febc937f15e9bf1c7a40af128b9c194c76df1bb949

Contents?: true

Size: 1000 Bytes

Versions: 23

Compression:

Stored size: 1000 Bytes

Contents

require 'rubygems'
require 'sequel'

begin
  DB = Sequel.sqlite
rescue NoMethodError
  raise LoadError, 'Install latest Sequel gem'
end

class User < Sequel::Model(:users)
  set_schema do
    primary_key :id
    varchar :username
    varchar :password
  end
end

unless User.table_exists?
  User.create_table
  User.create :username => 'admin', :password => 'passwort'
end

require 'ramaze'

class MainController < Ramaze::Controller
  helper :auth
  layout :layout

  before(:index) { login_required }

  def index
    "Hello #{session[:username]}"
  end

  private

  def login_required
    flash[:error] = 'login required to view that page' unless logged_in?
    super
  end

  def check_auth user, pass
    return false if (not user or user.empty?) and (not pass or pass.empty?)

    if User[:username => user, :password => pass].nil?
      flash[:error] = 'invalid username or password'
      false
    else
      true
    end
  end
end

Ramaze.start :adapter => :mongrel, :load_engines => :Haml

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 examples/app/auth/auth.rb
Pistos-ramaze-2008.12 examples/app/auth/auth.rb
Pistos-ramaze-2009.01 examples/app/auth/auth.rb
Pistos-ramaze-2009.02 examples/app/auth/auth.rb
clivecrous-ramaze-0.3.9.5 examples/auth/auth.rb
manveru-ramaze-2008.07 examples/app/auth/auth.rb
manveru-ramaze-2008.08 examples/app/auth/auth.rb
manveru-ramaze-2008.09 examples/app/auth/auth.rb
manveru-ramaze-2008.10 examples/app/auth/auth.rb
manveru-ramaze-2008.12 examples/app/auth/auth.rb
manveru-ramaze-2009.01 examples/app/auth/auth.rb
ptomato-ramaze-2009.02.1 examples/app/auth/auth.rb
ptomato-ramaze-2009.02 examples/app/auth/auth.rb
ramaze-0.3.5 examples/auth/auth.rb
ramaze-0.3.0 examples/auth/auth.rb
ramaze-0.2.1 examples/auth/auth.rb
ramaze-2009.01 examples/app/auth/auth.rb
ramaze-2008.06 examples/app/auth/auth.rb
ramaze-0.3.9.1 examples/auth/auth.rb
ramaze-2008.11 examples/app/auth/auth.rb