islock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,13 @@
1
+ README.rdoc
2
+ Rakefile
3
+ app/controllers/lock_application_controller.rb
4
+ app/controllers/lock_controller.rb
5
+ app/views/lock/login.html.erb
6
+ app/views/lock/refused.html.erb
7
+ app/views/lock/unlock.html.erb
8
+ config/routes.rb
9
+ lib/generators/lock/create_password_file/USAGE
10
+ lib/generators/lock/create_password_file/create_password_file_generator.rb
11
+ lib/lock.rb
12
+ lib/lock/engine.rb
13
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = lock
2
+
3
+ This is a minor modification to lock gem by cowboycoded
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
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'psych'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('islock', '0.1.0') do |p|
7
+ p.description = "lock gem for is_bf."
8
+ p.summary = "summary"
9
+ p.url = "http://github.com/istan/islock"
10
+ p.author = "i. stan."
11
+ p.email = "ian@bostonflip.com"
12
+ p.development_dependencies = []
13
+ end
14
+
@@ -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 lock_login_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,10 @@
1
+ class LockController < ApplicationController
2
+ def unlock
3
+ if Lock.passwords_match?(params[:password])
4
+ session[:lock_opened] = true
5
+ redirect_to root_path
6
+ else
7
+ redirect_to :action=>:login
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ <div class="lock-login" id="lock-login-form">
2
+ <p>What's the secret ingedient?</p>
3
+ <%= form_tag unlock_url do %>
4
+ <%=password_field_tag "password" %>
5
+ <%=submit_tag "Go"%>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1 @@
1
+ <p>This page is locked.</p>
@@ -0,0 +1,3 @@
1
+ <p>
2
+ <%=link_to "Go to home page", "/" %>
3
+ </p>
data/config/routes.rb ADDED
@@ -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,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
data/lib/lock.rb ADDED
@@ -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
+ README.rdoc
2
+ Rakefile
3
+ app/controllers/lock_application_controller.rb
4
+ app/controllers/lock_controller.rb
5
+ app/views/lock/login.html.erb
6
+ app/views/lock/refused.html.erb
7
+ app/views/lock/unlock.html.erb
8
+ config/routes.rb
9
+ lib/generators/lock/create_password_file/USAGE
10
+ lib/generators/lock/create_password_file/create_password_file_generator.rb
11
+ lib/lock.rb
12
+ lib/lock/engine.rb
13
+ Manifest
@@ -0,0 +1,19 @@
1
+ = lock
2
+
3
+ This is a minor modification to lock gem by cowboycoded
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,14 @@
1
+ require 'psych'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('islock', '0.1.0') do |p|
7
+ p.description = "lock gem for is_bf."
8
+ p.summary = "summary"
9
+ p.url = "http://github.com/istan/islock"
10
+ p.author = "i. stan."
11
+ p.email = "ian@bostonflip.com"
12
+ p.development_dependencies = []
13
+ end
14
+
@@ -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 lock_login_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,10 @@
1
+ class LockController < ApplicationController
2
+ def unlock
3
+ if Lock.passwords_match?(params[:password])
4
+ session[:lock_opened] = true
5
+ redirect_to root_path
6
+ else
7
+ redirect_to :action=>:login
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ <div class="lock-login" id="lock-login-form">
2
+ <p>What's the secret ingedient?</p>
3
+ <%= form_tag unlock_url do %>
4
+ <%=password_field_tag "password" %>
5
+ <%=submit_tag "Go"%>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1 @@
1
+ <p>This page is locked.</p>
@@ -0,0 +1,3 @@
1
+ <p>
2
+ <%=link_to "Go to home page", "/" %>
3
+ </p>
@@ -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,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{islock}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{i. stan.}]
9
+ s.date = %q{2011-07-05}
10
+ s.description = %q{lock gem for is_bf.}
11
+ s.email = %q{ian@bostonflip.com}
12
+ s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/generators/lock/create_password_file/USAGE}, %q{lib/generators/lock/create_password_file/create_password_file_generator.rb}, %q{lib/lock.rb}, %q{lib/lock/engine.rb}]
13
+ s.files = [%q{README.rdoc}, %q{Rakefile}, %q{app/controllers/lock_application_controller.rb}, %q{app/controllers/lock_controller.rb}, %q{app/views/lock/login.html.erb}, %q{app/views/lock/refused.html.erb}, %q{app/views/lock/unlock.html.erb}, %q{config/routes.rb}, %q{lib/generators/lock/create_password_file/USAGE}, %q{lib/generators/lock/create_password_file/create_password_file_generator.rb}, %q{lib/lock.rb}, %q{lib/lock/engine.rb}, %q{Manifest}, %q{islock.gemspec}]
14
+ s.homepage = %q{http://github.com/istan/islock}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Islock}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{islock}
18
+ s.rubygems_version = %q{1.8.5}
19
+ s.summary = %q{summary}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ 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,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
@@ -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
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: islock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - i.stanczyk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-05 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: ''
15
+ email:
16
+ - ian.stanczyk@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Manifest
22
+ - README.rdoc
23
+ - Rakefile
24
+ - app/controllers/lock_application_controller.rb
25
+ - app/controllers/lock_controller.rb
26
+ - app/views/lock/login.html.erb
27
+ - app/views/lock/refused.html.erb
28
+ - app/views/lock/unlock.html.erb
29
+ - config/routes.rb
30
+ - lib/generators/lock/create_password_file/USAGE
31
+ - lib/generators/lock/create_password_file/create_password_file_generator.rb
32
+ - lib/lock.rb
33
+ - lib/lock/engine.rb
34
+ - pkg/islock-0.1.0.gem
35
+ - pkg/islock-0.1.0.tar.gz
36
+ - pkg/islock-0.1.0/Manifest
37
+ - pkg/islock-0.1.0/README.rdoc
38
+ - pkg/islock-0.1.0/Rakefile
39
+ - pkg/islock-0.1.0/app/controllers/lock_application_controller.rb
40
+ - pkg/islock-0.1.0/app/controllers/lock_controller.rb
41
+ - pkg/islock-0.1.0/app/views/lock/login.html.erb
42
+ - pkg/islock-0.1.0/app/views/lock/refused.html.erb
43
+ - pkg/islock-0.1.0/app/views/lock/unlock.html.erb
44
+ - pkg/islock-0.1.0/config/routes.rb
45
+ - pkg/islock-0.1.0/islock.gemspec
46
+ - pkg/islock-0.1.0/lib/generators/lock/create_password_file/USAGE
47
+ - pkg/islock-0.1.0/lib/generators/lock/create_password_file/create_password_file_generator.rb
48
+ - pkg/islock-0.1.0/lib/lock.rb
49
+ - pkg/islock-0.1.0/lib/lock/engine.rb
50
+ homepage: http://github.com/istan/islock
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.6
68
+ requirements: []
69
+ rubyforge_project: islock
70
+ rubygems_version: 1.8.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: modified lock gem
74
+ test_files: []