Skip to content

Commit

Permalink
Remove my own session encryption, since Rack::Session::Cookie already…
Browse files Browse the repository at this point in the history
… takes care of it.
  • Loading branch information
kyleslattery committed Oct 22, 2010
1 parent 1d1c71c commit 6680d67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -5,4 +5,3 @@ gem 'dm-core'
gem 'dm-migrations'
gem 'dm-postgres-adapter'
gem 'dm-validations'
gem 'encryptor'
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -19,7 +19,6 @@ GEM
dm-core (~> 1.0.2)
do_postgres (0.10.2)
data_objects (= 0.10.2)
encryptor (1.1.1)
extlib (0.9.15)
rack (1.2.1)
sinatra (1.0)
Expand All @@ -33,5 +32,4 @@ DEPENDENCIES
dm-migrations
dm-postgres-adapter
dm-validations
encryptor
sinatra
16 changes: 7 additions & 9 deletions shortener.rb
Expand Up @@ -6,7 +6,6 @@
require 'dm-postgres-adapter'
require 'dm-migrations'
require 'dm-validations'
require 'encryptor'

DataMapper.setup(:default, ENV['DATABASE_URL'])

Expand All @@ -15,13 +14,12 @@
DataMapper.finalize
DataMapper.auto_upgrade!

enable :sessions
# Set the secret to the DATABASE_URL, since that's something that isn't shared
use Rack::Session::Cookie, :secret => ENV['DATABASE_URL']

def logged_in?
return true if ENV['ADMIN_USERNAME'].nil? || ENV['ADMIN_PASSWORD'].nil?
return false if session['key'].nil?

Encryptor.decrypt(:value => session['key'], :key => ENV['DATABASE_URL']) == request.ip
return true if ENV['ADMIN_USERNAME'].nil? || ENV['ADMIN_PASSWORD'].nil?
session['logged_in'] == 1
end

def require_log_in
Expand All @@ -33,7 +31,7 @@ def require_log_in
end

# Admin section
get '/-/?' do
get '/-/?' do
require_log_in

@links = Link.all(:order => [:id.desc])
Expand All @@ -52,15 +50,15 @@ def require_log_in
end

get '/-/logout' do
session['key'] = nil
session['logged_in'] = nil
redirect "/-/login"
end

post '/-/login' do
redirect '/-/login' if params[:password] != ENV['ADMIN_PASSWORD'] ||
params[:username] != ENV['ADMIN_USERNAME']

session['key'] = Encryptor.encrypt(:value => request.ip, :key => ENV['DATABASE_URL'])
session['logged_in'] = 1
redirect '/-/'
end

Expand Down

0 comments on commit 6680d67

Please sign in to comment.