sinatra_warden 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,16 +1,16 @@
1
1
  source "http://gemcutter.org"
2
2
 
3
- gem 'sinatra', '~> 0.9.4'
4
- gem 'warden', '~> 0.5.0'
3
+ gem 'sinatra', '>= 0.9.4'
4
+ gem 'warden', '~> 0.5.0'
5
5
 
6
- gem 'rake', :only => [:test]
7
- gem 'rspec', '~> 1.2.9', :only => [:test], :require_as => 'spec'
8
- gem 'yard', :only => [:test]
9
- gem 'rack-test', '~> 0.5.0', :only => [:test], :require_as => 'rack/test'
10
- gem 'rcov', :only => [:test]
6
+ gem 'rake', :only => :testing
7
+ gem 'rspec', '~> 1.2.9', :only => :testing, :require_as => 'spec'
8
+ gem 'yard', :only => :testing
9
+ gem 'rack-test', '~> 0.5.0', :only => :testing, :require_as => 'rack/test'
10
+ gem 'rcov', :only => :testing
11
11
 
12
- gem 'do_sqlite3', '~> 0.10.0', :only => [:test]
13
- gem 'dm-core', '~> 0.10.1', :only => [:test]
14
- gem 'bcrypt-ruby', :only => [:test], :require_as => 'bcrypt'
12
+ gem 'do_sqlite3', '~> 0.10.0', :only => :testing
13
+ gem 'dm-core', '~> 0.10.1', :only => :testing
14
+ gem 'bcrypt-ruby', :only => :testing, :require_as => 'bcrypt'
15
15
 
16
- disable_system_gems
16
+ disable_system_gems
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 jsmestad
1
+ Copyright (c) 2009 Justin Smestad
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,8 +1,6 @@
1
- = sinatra_warden
1
+ = Sinatra::Warden
2
2
 
3
- Provides a module for basic helpers and actions needed for user
4
- authentication using Warden with Sinatra. In addition to a
5
- collection of authentication strategies.
3
+ A Sinatra (http://github.com/sinatra/sinatra) module that provides authentication for your Sinatra application through Warden (http://github.com/hassox/warden).
6
4
 
7
5
  == Usage
8
6
 
@@ -10,7 +8,7 @@ collection of authentication strategies.
10
8
  require 'sinatra_warden'
11
9
 
12
10
  class Application < Sinatra::Base
13
- register SinatraWarden
11
+ register Sinatra::Warden
14
12
 
15
13
  get '/admin' do
16
14
  authorize!('/login') # require session, redirect to '/login' instead of work
@@ -22,22 +20,32 @@ collection of authentication strategies.
22
20
  haml :dashboard
23
21
  end
24
22
  end
23
+
24
+ == More Information
25
25
 
26
- == Issues
27
-
28
- * Currently assumes you have a model named 'User' and an email & password field.
26
+ Please read the wiki (http://wiki.github.com/jsmestad/sinatra_warden) for more information on more advanced configurations.
29
27
 
30
28
  == Note on Patches/Pull Requests
31
-
29
+
30
+ We use bundler on this project and disable system gems. Contributers should do the following:
31
+
32
+ $ git clone git://github.com/jsmestad/sinatra_warden.git
33
+ $ cd sinatra_warden
34
+ $ gem bundle
35
+ $ rake
36
+
32
37
  * Fork the project.
33
38
  * Make your feature addition or bug fix.
34
- * Add tests for it. This is important so I don't break it in a
35
- future version unintentionally.
39
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
36
40
  * Commit, do not mess with rakefile, version, or history.
37
- (if you want to have your own version, that is fine but
38
- bump version in a commit by itself I can ignore when I pull)
39
41
  * Send me a pull request. Bonus points for topic branches.
40
42
 
43
+ == Contributors
44
+
45
+ * Justin Smestad (http://github.com/jsmestad)
46
+ * Daniel Neighman (http://github.com/hassox)
47
+ * Shane Hanna (http://github.com/shanna)
48
+
41
49
  == Copyright
42
50
 
43
51
  Copyright (c) 2009 Justin Smestad. See LICENSE for details.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.description = %Q{basic helpers and authentication methods for using warden with sinatra also providing some hooks into Rack::Flash}
11
11
  gem.email = "justin.smestad@gmail.com"
12
12
  gem.homepage = "http://github.com/jsmestad/sinatra_warden"
13
- gem.authors = ["Justin Smestad"]
13
+ gem.authors = ["Justin Smestad", "Daniel Neighman"]
14
14
 
15
15
  manifest = Bundler::Environment.load(File.dirname(__FILE__) + '/Gemfile')
16
16
  manifest.dependencies.each do |d|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,9 +1,7 @@
1
- require 'sinatra'
2
- require 'warden'
1
+ Bundler.require_env
2
+ require File.join(File.dirname(__FILE__), 'sinatra_warden', 'sinatra')
3
3
 
4
- require File.join(File.dirname(__FILE__) + '/sinatra_warden/sinatra')
5
-
6
- Warden::Manager.before_failure do |env,opts|
4
+ Warden::Manager.before_failure do |env, opts|
7
5
  # Sinatra is very sensitive to the request method
8
6
  # since authentication could fail on any type of method, we need
9
7
  # to set it for the failure app so it is routed to the correct block
@@ -1,57 +1,72 @@
1
- module SinatraWarden
2
- module Helpers
3
- # The main accessor for the warden proxy instance
4
- def warden
5
- request.env['warden']
6
- end
1
+ module Sinatra
2
+ module Warden
3
+ module Helpers
4
+
5
+ # The main accessor for the warden proxy instance
6
+ def warden
7
+ request.env['warden']
8
+ end
7
9
 
8
- # Proxy to the authenticated? method on warden
9
- def authenticated?(*args)
10
- warden.authenticated?(*args)
11
- end
12
- alias_method :logged_in?, :authenticated?
10
+ # Proxy to the authenticated? method on warden
11
+ def authenticated?(*args)
12
+ warden.authenticated?(*args)
13
+ end
14
+ alias_method :logged_in?, :authenticated?
13
15
 
14
- # Access the currently logged in user
15
- def user(*args)
16
- warden.user(*args)
17
- end
18
- alias_method :current_user, :user
16
+ # Access the currently logged in user
17
+ def user(*args)
18
+ warden.user(*args)
19
+ end
20
+ alias_method :current_user, :user
19
21
 
20
- # Set the currently logged in user
21
- def user=(user)
22
- warden.set_user user
23
- end
24
- alias_method :current_user=, :user=
22
+ # Set the currently logged in user
23
+ # @params [User] the user you want to log in
24
+ def user=(user)
25
+ warden.set_user user
26
+ end
27
+ alias_method :current_user=, :user=
25
28
 
26
- # Require authorization for an action
27
- def authorize!(failure_path=nil)
28
- redirect(failure_path ? failure_path : '/') unless authenticated?
29
+ # Require authorization for an action
30
+ # @params [String] path to redirect to if user is unauthenticated
31
+ def authorize!(failure_path=nil)
32
+ redirect(failure_path ? failure_path : options.auth_failure_path) unless authenticated?
33
+ end
29
34
  end
30
- end
31
35
 
32
- def self.registered(app)
33
- app.helpers SinatraWarden::Helpers
36
+ def self.registered(app)
37
+ app.helpers Warden::Helpers
38
+
39
+ app.set :auth_failure_path, '/'
40
+ app.set :auth_success_path, lambda{ back }
34
41
 
35
- app.post '/unauthenticated/?' do
36
- status 401
37
- flash[:error] = "Could not log you in" if defined?(Rack::Flash)
38
- haml :login
39
- end
42
+ app.set :auth_error_message, "Could not log you in."
43
+ app.set :auth_success_message, "You have logged in successfully."
44
+ app.set :auth_use_erb, false
45
+ app.set :auth_login_template, :login
40
46
 
41
- app.get '/login/?' do
42
- haml :login
43
- end
47
+ app.post '/unauthenticated/?' do
48
+ status 401
49
+ flash[:error] = "Could not log you in." if defined?(Rack::Flash)
50
+ options.auth_use_erb ? erb(options.auth_login_template) : haml(options.auth_login_template)
51
+ end
44
52
 
45
- app.post '/login/?' do
46
- env['warden'].authenticate!
47
- flash[:success] = "You have logged in successfully." if defined?(Rack::Flash)
48
- redirect back
49
- end
53
+ app.get '/login/?' do
54
+ options.auth_use_erb ? erb(options.auth_login_template) : haml(options.auth_login_template)
55
+ end
50
56
 
51
- app.get '/logout/?' do
52
- env['warden'].logout
53
- flash[:success] = "You are now logged out." if defined?(Rack::Flash)
54
- redirect back
57
+ app.post '/login/?' do
58
+ env['warden'].authenticate!
59
+ flash[:success] = options.auth_success_message if defined?(Rack::Flash)
60
+ redirect options.auth_success_path
61
+ end
62
+
63
+ app.get '/logout/?' do
64
+ env['warden'].logout
65
+ flash[:success] = options.auth_error_message if defined?(Rack::Flash)
66
+ redirect options.auth_success_path
67
+ end
55
68
  end
56
- end
57
- end
69
+ end # Warden
70
+
71
+ register Warden
72
+ end # Sinatra
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra_warden}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin Smestad", "Daniel Neighman"]
12
+ s.date = %q{2009-11-03}
13
+ s.description = %q{basic helpers and authentication methods for using warden with sinatra also providing some hooks into Rack::Flash}
14
+ s.email = %q{justin.smestad@gmail.com}
15
+ s.executables = ["autospec", "rackup", "rake", "rcov", "spec", "yard-graph", "yardoc", "yri"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/sinatra_warden.rb",
29
+ "lib/sinatra_warden/sinatra.rb",
30
+ "sinatra_warden.gemspec",
31
+ "spec/fixtures/bcrypt_strategy.rb",
32
+ "spec/fixtures/testing_login.rb",
33
+ "spec/fixtures/user.rb",
34
+ "spec/sinatra_warden_spec.rb",
35
+ "spec/spec.opts",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/jsmestad/sinatra_warden}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{authentication system for using warden with sinatra}
43
+ s.test_files = [
44
+ "spec/fixtures/bcrypt_strategy.rb",
45
+ "spec/fixtures/testing_login.rb",
46
+ "spec/fixtures/user.rb",
47
+ "spec/sinatra_warden_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
57
+ s.add_runtime_dependency(%q<warden>, ["~> 0.5.0"])
58
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
59
+ s.add_runtime_dependency(%q<rspec>, ["~> 1.2.9"])
60
+ s.add_runtime_dependency(%q<yard>, [">= 0"])
61
+ s.add_runtime_dependency(%q<rack-test>, ["~> 0.5.0"])
62
+ s.add_runtime_dependency(%q<rcov>, [">= 0"])
63
+ s.add_runtime_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
64
+ s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.1"])
65
+ s.add_runtime_dependency(%q<bcrypt-ruby>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
68
+ s.add_dependency(%q<warden>, ["~> 0.5.0"])
69
+ s.add_dependency(%q<rake>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["~> 1.2.9"])
71
+ s.add_dependency(%q<yard>, [">= 0"])
72
+ s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
75
+ s.add_dependency(%q<dm-core>, ["~> 0.10.1"])
76
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
77
+ end
78
+ else
79
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
80
+ s.add_dependency(%q<warden>, ["~> 0.5.0"])
81
+ s.add_dependency(%q<rake>, [">= 0"])
82
+ s.add_dependency(%q<rspec>, ["~> 1.2.9"])
83
+ s.add_dependency(%q<yard>, [">= 0"])
84
+ s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
85
+ s.add_dependency(%q<rcov>, [">= 0"])
86
+ s.add_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
87
+ s.add_dependency(%q<dm-core>, ["~> 0.10.1"])
88
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
89
+ end
90
+ end
91
+
@@ -1,5 +1,5 @@
1
1
  class TestingLogin < Sinatra::Base
2
- register SinatraWarden
2
+ register Sinatra::Warden
3
3
 
4
4
  get '/dashboard' do
5
5
  authorize!('/login')
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  ENV['RACK_ENV'] ||= 'test'
5
5
  project_root = File.expand_path(File.dirname(__FILE__))
6
6
  require File.join(project_root, '..', 'vendor', 'gems', 'environment')
7
- Bundler.require_env(:test)
7
+ Bundler.require_env(:testing)
8
8
 
9
9
  require 'sinatra_warden'
10
10
  require 'spec'
@@ -13,7 +13,7 @@ require 'spec/autorun'
13
13
  DataMapper.setup(:default, 'sqlite3::memory:')
14
14
 
15
15
  %w(fixtures support).each do |path|
16
- Dir[ File.join( project_root, path, '/**/*.rb') ].each do |m|
16
+ Dir[ File.join(project_root, path, '/**/*.rb') ].each do |m|
17
17
  require m
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
8
+ - Daniel Neighman
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-10-26 00:00:00 -06:00
13
+ date: 2009-11-03 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -18,7 +19,7 @@ dependencies:
18
19
  version_requirement:
19
20
  version_requirements: !ruby/object:Gem::Requirement
20
21
  requirements:
21
- - - ~>
22
+ - - ">="
22
23
  - !ruby/object:Gem::Version
23
24
  version: 0.9.4
24
25
  version:
@@ -32,6 +33,86 @@ dependencies:
32
33
  - !ruby/object:Gem::Version
33
34
  version: 0.5.0
34
35
  version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.9
55
+ version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: yard
58
+ type: :runtime
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ - !ruby/object:Gem::Dependency
67
+ name: rack-test
68
+ type: :runtime
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: 0.5.0
75
+ version:
76
+ - !ruby/object:Gem::Dependency
77
+ name: rcov
78
+ type: :runtime
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ - !ruby/object:Gem::Dependency
87
+ name: do_sqlite3
88
+ type: :runtime
89
+ version_requirement:
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 0.10.0
95
+ version:
96
+ - !ruby/object:Gem::Dependency
97
+ name: dm-core
98
+ type: :runtime
99
+ version_requirement:
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: 0.10.1
105
+ version:
106
+ - !ruby/object:Gem::Dependency
107
+ name: bcrypt-ruby
108
+ type: :runtime
109
+ version_requirement:
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
35
116
  description: basic helpers and authentication methods for using warden with sinatra also providing some hooks into Rack::Flash
36
117
  email: justin.smestad@gmail.com
37
118
  executables:
@@ -58,8 +139,7 @@ files:
58
139
  - VERSION
59
140
  - lib/sinatra_warden.rb
60
141
  - lib/sinatra_warden/sinatra.rb
61
- - lib/sinatra_warden/strategies/bcrypt_activerecord.rb
62
- - lib/sinatra_warden/strategies/bcrypt_datamapper.rb
142
+ - sinatra_warden.gemspec
63
143
  - spec/fixtures/bcrypt_strategy.rb
64
144
  - spec/fixtures/testing_login.rb
65
145
  - spec/fixtures/user.rb
@@ -1,21 +0,0 @@
1
- Warden::Manager.serialize_into_session{ |user| [user.class, user.id] }
2
- Warden::Manager.serialize_from_session{ |klass, id| klass.find(id) }
3
-
4
- Warden::Strategies.add(:bcrypt_activerecord) do
5
-
6
- def valid?
7
- params["login"] || params["password"]
8
- end
9
-
10
- def authenticate!
11
- return fail! unless user = User.find(params["login"])
12
-
13
- if user.password == params["password"]
14
- success!(user)
15
- else
16
- errors.add(:login, "Login or Password incorrect")
17
- fail!
18
- end
19
- end
20
-
21
- end
@@ -1,16 +0,0 @@
1
- require 'dm-core'
2
- require 'bcrypt'
3
-
4
- Warden::Manager.serialize_into_session{|user| user.id }
5
- Warden::Manager.serialize_from_session{|id| User.get(id) }
6
-
7
- Warden::Strategies.add(:bcrypt_datamapper) do
8
- def valid?
9
- params["email"] || params["password"]
10
- end
11
-
12
- def authenticate!
13
- return fail!("Could not log in") unless user = User.first(:email => params["email"])
14
- user.password == params["password"] ? success!(user) : fail!("Could not log in")
15
- end
16
- end