lock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.1.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.1"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.1.0)
13
+ rspec-core (~> 2.1.0)
14
+ rspec-expectations (~> 2.1.0)
15
+ rspec-mocks (~> 2.1.0)
16
+ rspec-core (2.1.0)
17
+ rspec-expectations (2.1.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.1.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.5.1)
27
+ rcov
28
+ rspec (~> 2.1.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 cowboycoded
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.
@@ -0,0 +1,19 @@
1
+ = lock
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to lock
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 cowboycoded. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "lock"
16
+ gem.homepage = "http://github.com/cowboycoded/lock"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Restrict access to controllers or actions using a single password}
19
+ gem.description = %Q{Simple engine that can lock down controllers/actions with a password. Useful for locking a new feature (or an entire site) while it is being beta tested.}
20
+ gem.email = "john.mcaliley@gmail.com"
21
+ gem.authors = ["cowboycoded"]
22
+ gem.add_dependency 'bcrypt-ruby'
23
+ gem.files.exclude 'test_app'
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rspec/core'
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
+ spec.pattern = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "lock #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,21 @@
1
+ module LockApplicationController
2
+ module ClassMethods
3
+ def lock(opts={})
4
+ before_filter { |c| c.lock_filter opts[:actions] }
5
+ end
6
+ end
7
+
8
+ module InstanceMethods
9
+ def lock_filter(actions=nil)
10
+ if locked_action?(actions) and session[:lock_opened]!=true
11
+ redirect_to unlock_refused_url
12
+ end
13
+ #otherwise proceed to where ya going
14
+ end
15
+
16
+ def locked_action?(actions)
17
+ return false if controller_name=="lock"
18
+ actions.blank? or actions.include?("#{controller_name}") or actions.include?("#{controller_name}##{action_name}")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class LockController < ApplicationController
2
+ def unlock
3
+ if Lock.passwords_match?(params[:password])
4
+ session[:lock_opened] = true
5
+ else
6
+ redirect_to :action=>:login
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ <div class="lock-login" id="lock-login-form">
2
+ <%= form_tag unlock_url do %>
3
+ <%=password_field_tag "password" %>
4
+ <%=submit_tag "Unlock"%>
5
+ <% end %>
6
+ </div>
@@ -0,0 +1 @@
1
+ This page is locked.
@@ -0,0 +1,3 @@
1
+ Unlocked!
2
+ <br/>
3
+ <%=link_to "Go to home page", "/" %>
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ match "lock/login", :to=>"lock#login", :as=>"lock_login", :via=>:get
3
+ match "lock/refused", :to=>"lock#refused", :as=>"unlock_refused", :via=>:get
4
+ match "lock/unlock", :to=>"lock#unlock", :as=>"unlock", :via=>:post
5
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ The lock generator is used to create an encrypted password and store it in config/lock_password
3
+
4
+ Example:
5
+ rails g lock:create_password_file mypassword
@@ -0,0 +1,14 @@
1
+ require 'bcrypt'
2
+
3
+ module Lock
4
+ class CreatePasswordFileGenerator < Rails::Generators::Base
5
+ argument :password, :type => :string
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_password_file
9
+ password_salt = BCrypt::Engine.generate_salt
10
+ password_hash = BCrypt::Engine.hash_secret(password, password_salt)
11
+ create_file "config/lock_password", "#{password_hash}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ LOCK_PATH = File.dirname(__FILE__) + "/lock"
2
+ require "#{LOCK_PATH}/engine.rb"
3
+ require "bcrypt"
4
+
5
+ module Lock
6
+ def self.passwords_match?(password)
7
+ begin
8
+ hashed_combo = IO.read("#{Rails.root}/config/lock_password")
9
+ rescue
10
+ return false
11
+ end
12
+ salt = hashed_combo[0,29]
13
+ hashed_combo==BCrypt::Engine.hash_secret(password, salt)
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require "lock"
2
+ require "rails"
3
+
4
+ module Lock
5
+ class Engine < Rails::Engine
6
+ initializer "lock.extend_application_controller" do
7
+ ActiveSupport.on_load(:action_controller) do
8
+ include LockApplicationController::InstanceMethods
9
+ extend LockApplicationController::ClassMethods
10
+ end
11
+ end
12
+ end
13
+ end
File without changes
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lock}
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 = ["cowboycoded"]
12
+ s.date = %q{2011-03-07}
13
+ s.description = %q{Simple engine that can lock down controllers/actions with a password. Useful for locking a new feature (or an entire site) while it is being beta tested.}
14
+ s.email = %q{john.mcaliley@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "app/controllers/lock_application_controller.rb",
29
+ "app/controllers/lock_controller.rb",
30
+ "app/views/lock/login.html.erb",
31
+ "app/views/lock/refused.html.erb",
32
+ "app/views/lock/unlock.html.erb",
33
+ "config/routes.rb",
34
+ "lib/generators/lock/create_password_file/USAGE",
35
+ "lib/generators/lock/create_password_file/create_password_file_generator.rb",
36
+ "lib/lock.rb",
37
+ "lib/lock/engine.rb",
38
+ "lib/lock/railties/tasks.rake",
39
+ "lock.gemspec"
40
+ ]
41
+ s.homepage = %q{http://github.com/cowboycoded/lock}
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.7}
45
+ s.summary = %q{Restrict access to controllers or actions using a single password}
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
56
+ s.add_runtime_dependency(%q<bcrypt-ruby>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
70
+ end
71
+ end
72
+
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - cowboycoded
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-07 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 0
31
+ version: 2.1.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 1
61
+ version: 1.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rcov
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: bcrypt-ruby
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *id005
91
+ description: Simple engine that can lock down controllers/actions with a password. Useful for locking a new feature (or an entire site) while it is being beta tested.
92
+ email: john.mcaliley@gmail.com
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - LICENSE.txt
99
+ - README.rdoc
100
+ files:
101
+ - .document
102
+ - .rspec
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - app/controllers/lock_application_controller.rb
110
+ - app/controllers/lock_controller.rb
111
+ - app/views/lock/login.html.erb
112
+ - app/views/lock/refused.html.erb
113
+ - app/views/lock/unlock.html.erb
114
+ - config/routes.rb
115
+ - lib/generators/lock/create_password_file/USAGE
116
+ - lib/generators/lock/create_password_file/create_password_file_generator.rb
117
+ - lib/lock.rb
118
+ - lib/lock/engine.rb
119
+ - lib/lock/railties/tasks.rake
120
+ - lock.gemspec
121
+ has_rdoc: true
122
+ homepage: http://github.com/cowboycoded/lock
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 4265520529100098285
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Restrict access to controllers or actions using a single password
154
+ test_files: []
155
+