authentication_system 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Michael Deering
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "authentication_system"
8
+ gem.summary = "Bolt-on authentication system for use with authlogic."
9
+ gem.description = "Well rounded authenticication system for use with authlogic."
10
+ gem.email = "mdeering@mdeering.com"
11
+ gem.homepage = "http://github.com/mdeering/authentication_system"
12
+ gem.authors = ["Michael Deering"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.files = %w(install.rb install.txt LICENSE README.textile Rakefile VERSION) + Dir.glob("{rails,lib,spec}/**/*")
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "authentication_system #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0.pre1
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'install.txt'))
@@ -0,0 +1 @@
1
+ Install Text
@@ -0,0 +1,101 @@
1
+ module AuthenticationSystem
2
+
3
+ class << self
4
+ attr_accessor :configuration
5
+ end
6
+
7
+ def self.configure
8
+ self.configuration ||= Configuration.new
9
+ yield(configuration)
10
+ end
11
+
12
+ class Configuration
13
+
14
+ attr_accessor :application_name, :login_url
15
+
16
+ def initialize
17
+ @application_name = 'Application'
18
+ @login_url = 'login_url'
19
+ end
20
+
21
+ end
22
+
23
+ def self.included(base)
24
+ configure do |c|
25
+ end
26
+ base.send :helper_method, :current_user, :logged_in?
27
+ base.send :before_filter, :login_required
28
+ end
29
+
30
+ protected
31
+
32
+ def authenticated?
33
+ logged_in?
34
+ end
35
+
36
+ def authorized?
37
+ false
38
+ end
39
+
40
+ def current_user
41
+ @current_user ||= ( (current_user_session && current_user_session.record) || login_from_basic_auth)
42
+ end
43
+
44
+ def login_required
45
+ return authentication_failed unless authenticated?
46
+ return authorization_failed unless authorized?
47
+ true
48
+ end
49
+
50
+ def logged_in?
51
+ current_user.present?
52
+ end
53
+
54
+ private
55
+
56
+ def authentication_failed
57
+ respond_to do |accepts|
58
+ accepts.html do
59
+ store_location
60
+ flash[:error] = t 'flash.authentication_failed'
61
+ redirect_to_login
62
+ end
63
+ accepts.all do
64
+ headers['WWW-Authenticate'] = "Basic realm=\"#{ AuthenticationSystem.configuration.application_name }\""
65
+ head :unauthorized
66
+ end
67
+ end
68
+ false
69
+ end
70
+
71
+ def authorization_failed
72
+ respond_to do |accepts|
73
+ accepts.html do
74
+ flash[:error] = t 'flash.authorization_failed'
75
+ redirect_to_login
76
+ end
77
+ accepts.all { head :forbidden }
78
+ end
79
+ false
80
+ end
81
+
82
+ def current_user_session
83
+ @current_user_session ||= UserSession.find
84
+ end
85
+
86
+ def login_from_basic_auth
87
+ authenticate_with_http_basic do |email, password|
88
+ @current_user_session = UserSession.create(email, password)
89
+ @current_user_session.record
90
+ end
91
+ end
92
+
93
+ def redirect_to_login
94
+ redirect_to request.env['HTTP_REFERER'] || send(AuthenticationSystem.configuration.login_url)
95
+ end
96
+
97
+ def store_location
98
+ session[:return_to] = request.request_uri
99
+ end
100
+
101
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. lib authentication_system])
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "AuthenticationSystem" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'authentication_system'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authentication_system
3
+ version: !ruby/object:Gem::Version
4
+ hash: -1876988184
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ - pre1
11
+ version: 0.1.0.pre1
12
+ platform: ruby
13
+ authors:
14
+ - Michael Deering
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-08-06 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 13
31
+ segments:
32
+ - 1
33
+ - 2
34
+ - 9
35
+ version: 1.2.9
36
+ type: :development
37
+ version_requirements: *id001
38
+ description: Well rounded authenticication system for use with authlogic.
39
+ email: mdeering@mdeering.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - LICENSE
46
+ - README.textile
47
+ files:
48
+ - LICENSE
49
+ - README.textile
50
+ - Rakefile
51
+ - VERSION
52
+ - install.rb
53
+ - install.txt
54
+ - lib/authentication_system.rb
55
+ - rails/init.rb
56
+ - spec/authentication_system_spec.rb
57
+ - spec/spec.opts
58
+ - spec/spec_helper.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/mdeering/authentication_system
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ hash: 25
83
+ segments:
84
+ - 1
85
+ - 3
86
+ - 1
87
+ version: 1.3.1
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Bolt-on authentication system for use with authlogic.
95
+ test_files:
96
+ - spec/authentication_system_spec.rb
97
+ - spec/spec_helper.rb