sudo_mode 0.0.1
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/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/sudo_mode/application.js +15 -0
- data/app/assets/stylesheets/sudo_mode/application.css +13 -0
- data/app/controllers/sudo_mode/application_controller.rb +4 -0
- data/app/controllers/sudo_mode/concerns/require_password_confirmation.rb +21 -0
- data/app/controllers/sudo_mode/confirmation_controller.rb +10 -0
- data/app/helpers/sudo_mode/application_helper.rb +4 -0
- data/app/views/sudo_mode/confirmation/new.html.erb +13 -0
- data/config/locales/en.yml +7 -0
- data/config/routes.rb +3 -0
- data/lib/sudo_mode/engine.rb +11 -0
- data/lib/sudo_mode/version.rb +3 -0
- data/lib/sudo_mode.rb +4 -0
- data/lib/tasks/sudo_mode_tasks.rake +4 -0
- metadata +85 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sudo Mode
|
2
|
+
|
3
|
+
Sudo Mode helps you easily require a password confirmation before any controller action of your choice.
|
4
|
+
|
5
|
+
This is inspired (heavily) by [Github's implementation](https://github.com/blog/1513-introducing-github-sudo-mode).
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class FooController
|
11
|
+
require_password_confirmation_for :destroy
|
12
|
+
|
13
|
+
def destroy
|
14
|
+
# Bad things happen here
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
## Internationalization
|
20
|
+
|
21
|
+
Override these keys in your locale files:
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
sudo_mode:
|
25
|
+
confirmation:
|
26
|
+
new:
|
27
|
+
confirmation_heading: "Confirm your Password"
|
28
|
+
check_password_button: "Check"
|
29
|
+
```
|
30
|
+
|
31
|
+
## Limitations
|
32
|
+
|
33
|
+
- Requires [`has_secure_password`](http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html)
|
34
|
+
- Requires `ApplicationController` to have a `current_user` method
|
35
|
+
- Styling for the confirmation page is not taken care of
|
36
|
+
|
37
|
+
## Credits
|
38
|
+
|
39
|
+
[](http://nilenso.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
require "bundler/gem_tasks"
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module SudoMode
|
4
|
+
module Concerns
|
5
|
+
module RequirePasswordConfirmation
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def require_password_confirmation_for(action)
|
10
|
+
before_filter :check_password, :only => action
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_password
|
15
|
+
unless current_user.authenticate(params[:password])
|
16
|
+
redirect_to sudo_mode.new_confirmation_path(:redirect_to => request.path, :method => request.request_method)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<header>
|
2
|
+
<h2><%= t ".confirmation_heading" %></h2>
|
3
|
+
</header>
|
4
|
+
|
5
|
+
<div class="confirmation">
|
6
|
+
<%= form_tag @submit_path, :class => "confirmation-form", :method => @method do %>
|
7
|
+
<div class="confirmation-fieldset">
|
8
|
+
<%= label_tag :password, "Password", :class => "confirmation-label" %>
|
9
|
+
<%= password_field_tag :password, nil, :class => "confirmation-password" %>
|
10
|
+
</div>
|
11
|
+
<%= submit_tag t(".check_password_button"), :class => "confirmation-submit" %>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
data/config/routes.rb
ADDED
data/lib/sudo_mode.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sudo_mode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Timothy Andrew
|
9
|
+
- Jithu Gopal
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.2'
|
31
|
+
description:
|
32
|
+
email:
|
33
|
+
- mail@timothyandrew.net
|
34
|
+
- jithug87@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- app/assets/javascripts/sudo_mode/application.js
|
40
|
+
- app/assets/stylesheets/sudo_mode/application.css
|
41
|
+
- app/controllers/sudo_mode/application_controller.rb
|
42
|
+
- app/controllers/sudo_mode/concerns/require_password_confirmation.rb
|
43
|
+
- app/controllers/sudo_mode/confirmation_controller.rb
|
44
|
+
- app/helpers/sudo_mode/application_helper.rb
|
45
|
+
- app/views/sudo_mode/confirmation/new.html.erb
|
46
|
+
- config/locales/en.yml
|
47
|
+
- config/routes.rb
|
48
|
+
- lib/sudo_mode/engine.rb
|
49
|
+
- lib/sudo_mode/version.rb
|
50
|
+
- lib/sudo_mode.rb
|
51
|
+
- lib/tasks/sudo_mode_tasks.rake
|
52
|
+
- MIT-LICENSE
|
53
|
+
- Rakefile
|
54
|
+
- README.md
|
55
|
+
homepage: http://github.com/nilenso/sudo_mode
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: -4507150748124203788
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: -4507150748124203788
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Sudo mode for your devilish deeds.
|
85
|
+
test_files: []
|