Skip to content

Commit

Permalink
Erste Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Braun committed May 9, 2011
0 parents commit 014e885
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.sw?
10 changes: 10 additions & 0 deletions Gemfile
@@ -0,0 +1,10 @@
# A sample Gemfile
source "http://rubygems.org"

# gem "rails"

gem "sinatra"
gem "sinatra-reloader"
gem "dm-core"
gem "dm-migrations"
gem "dm-sqlite-adapter"
46 changes: 46 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,46 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.5)
backports (2.1.0)
data_objects (0.10.5)
addressable (~> 2.1)
dm-core (1.1.0)
addressable (~> 2.2.4)
dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
dm-core (~> 1.1.0)
dm-migrations (1.1.0)
dm-core (~> 1.1.0)
dm-sqlite-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_sqlite3 (~> 0.10.2)
do_sqlite3 (0.10.5)
data_objects (= 0.10.5)
monkey-lib (0.5.4)
backports
rack (1.2.2)
sinatra (1.2.6)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
sinatra-advanced-routes (0.5.1)
monkey-lib (~> 0.5.0)
sinatra (~> 1.0)
sinatra-sugar (~> 0.5.0)
sinatra-reloader (0.5.0)
sinatra (~> 1.0)
sinatra-advanced-routes (~> 0.5.0)
sinatra-sugar (0.5.1)
monkey-lib (~> 0.5.0)
sinatra (~> 1.0)
tilt (1.3)

PLATFORMS
ruby

DEPENDENCIES
dm-core
dm-migrations
dm-sqlite-adapter
sinatra
sinatra-reloader
5 changes: 5 additions & 0 deletions app.rb
@@ -0,0 +1,5 @@
require "digest/sha1"

require "./helpers/login.rb"
require "./models/user.rb"
require "./config/db.rb"
10 changes: 10 additions & 0 deletions config.ru
@@ -0,0 +1,10 @@
require "rubygems"
require "bundler"

Bundler.require
require "sinatra/reloader" if development?


require "./app.rb"

run Sinatra::Application
2 changes: 2 additions & 0 deletions config/db.rb
@@ -0,0 +1,2 @@
DataMapper.setup(:default, "sqlite3:db/data.db")
DataMapper.auto_upgrade!
Binary file added db/data.db
Binary file not shown.
24 changes: 24 additions & 0 deletions helpers/login.rb
@@ -0,0 +1,24 @@
helpers do

def logged_in?
session[:user_id]
end

def log_in(params)
user = User.authenticate(params)
user ? session[:user_id] = user.id : false
end

def log_out
session[:user_id] = nil
end

def current_user
if logged_in?
User.get(session[:user_id])
else
nil
end
end

end
21 changes: 21 additions & 0 deletions models/user.rb
@@ -0,0 +1,21 @@
class User
include DataMapper::Resource

property :id, Serial
property :email, String
property :password_hash, String

def self.authenticate(params)
User.first(:email => params[:email], :password_hash => encode(params[:password]))
end

def password=(pw)
self.password_hash = encode(pw)
end

private

def self.encode(str)
Digest::SHA1.hexdigest(str)
end
end
Empty file added public/.gitkeep
Empty file.
Empty file added views/.gitkeep
Empty file.

0 comments on commit 014e885

Please sign in to comment.