Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roger Braun
committed
May 9, 2011
0 parents
commit 014e885
Showing
11 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "digest/sha1" | ||
|
||
require "./helpers/login.rb" | ||
require "./models/user.rb" | ||
require "./config/db.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "rubygems" | ||
require "bundler" | ||
|
||
Bundler.require | ||
require "sinatra/reloader" if development? | ||
|
||
|
||
require "./app.rb" | ||
|
||
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DataMapper.setup(:default, "sqlite3:db/data.db") | ||
DataMapper.auto_upgrade! |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Empty file.