Skip to content

@regedarek /hkshop.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Warden + md5
%w[rubygems digest/md5 sinatra haml sass warden rack/flash ./db/database].each{ |gem| require gem }
require "sinatra/reloader" if development?
set :root, File.dirname(__FILE__)
set :views, "views"
get '/main.css' do
header 'Content-Type' => 'text/css; charset=utf-8'
sass :main
end
class User < ActiveRecord::Base
def self.authenticate(name, password)
user = self.find_by_name(name)
user if user && ::Digest::MD5.hexdigest(::Digest::MD5.hexdigest(password)) == user.password
end
end
get '/' do
@users = User.all
haml :index
end
builder = Rack::Builder.new do
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User[id] }
Warden::Strategies.add(:password) do
def valid?
params['user'] && params['user']['name'] && params['user']['password']
end
def authenticate!
user = User.find_by_name(['name'])
if user && user.authenticate(['password'])
success! user
else
fail "invalid"
end
user.nil? ? fail!('Could not log in') : success!(user, 'Successfully logged in')
end
end
use Rack::MethodOverride
use Rack::Session::Cookie
use Rack::Flash, accessorize: [:error, :success]
use Warden::Manager do |config|
config.default_strategies :password
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.