sudo_rails 0.3.2 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/app/assets/stylesheets/sudo_rails/application.scss +9 -7
- data/app/controllers/sudo_rails/application_controller.rb +1 -1
- data/lib/sudo_rails/controller_ext.rb +17 -5
- data/lib/sudo_rails/engine.rb +1 -1
- data/lib/sudo_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba7183412184ec9c6e3308162ec026f8ae7711d97513dc776b3229354853f0f6
|
4
|
+
data.tar.gz: 63ded2e09b66ea79ddca371e07d3bdf77a5b5a3c46fe61a7594268007a778d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a22d1457fe839e85ff5f0471dbce6733295afc5ce115eec7c910e94dc7d0eaca30949c954c968b00e724f8da5bdfdc66131a89e72e58b87339c39ea55e21c9
|
7
|
+
data.tar.gz: ec8f62cd6aa3befff139e64910086b3961a1f6c6850cb8260f0df5cfbbfb17d14657a8018aa00c34c2fb0744511ebeb4a17a61d2fd27511a541b371da852beb9
|
data/README.md
CHANGED
@@ -34,6 +34,13 @@ class SettingsController < ApplicationController
|
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
37
|
+
Under the hood, the `sudo` method delegates to a `before_action` callback, so you're able to pass the following options: `:only`, `:except`, `:if` and `:unless`.
|
38
|
+
|
39
|
+
The gem also provides a couple of controller helpers, useful to manually manage the `sudo` session status:
|
40
|
+
|
41
|
+
- `reset_sudo_session!`: resets the current sudo session, if any.
|
42
|
+
- `extend_sudo_session!`: marks the current session as a valid sudo session.
|
43
|
+
|
37
44
|
### Configuration
|
38
45
|
|
39
46
|
You can use the `setup` method to configure and customize different things:
|
@@ -53,11 +60,13 @@ SudoRails.setup do |config|
|
|
53
60
|
config.background_color = '#1A7191'
|
54
61
|
config.layout = 'admin'
|
55
62
|
|
56
|
-
# Confirmation strategy
|
63
|
+
# Confirmation strategy implementation
|
57
64
|
config.confirm_strategy = -> (context, password) {
|
58
65
|
user = context.current_user
|
59
66
|
user.valid_password?(password)
|
60
67
|
}
|
68
|
+
|
69
|
+
# Reset password link
|
61
70
|
config.reset_pass_link = '/users/password/new'
|
62
71
|
end
|
63
72
|
```
|
@@ -70,7 +79,7 @@ Using the `custom_logo`, `primary_color` and `background_color` options, you can
|
|
70
79
|
|
71
80
|
You should define how to validate the password using the `confirm_strategy` option. It must be a `lambda`, which will receive 2 arguments: the controller instance (`context`) and the password from the user.
|
72
81
|
|
73
|
-
By default, the gem ships with `Devise` and `Clearance` integration.
|
82
|
+
By default, the gem ships with `Devise` and `Clearance` integration. Check it [here](lib/sudo_rails/integrations/).
|
74
83
|
|
75
84
|
Implementation examples:
|
76
85
|
|
@@ -87,7 +96,7 @@ config.confirm_strategy = -> (context, password) {
|
|
87
96
|
user.authenticate(password)
|
88
97
|
}
|
89
98
|
|
90
|
-
# Other custom
|
99
|
+
# Other custom implementations
|
91
100
|
config.confirm_strategy = -> (context, password) {
|
92
101
|
user = context.current_user
|
93
102
|
user.admin? && password == ENV['SUPER_SECRET_PASSWORD']
|
@@ -10,7 +10,7 @@ a {
|
|
10
10
|
}
|
11
11
|
|
12
12
|
.sudo-header {
|
13
|
-
margin:
|
13
|
+
margin: 2em auto;
|
14
14
|
|
15
15
|
img {
|
16
16
|
margin-top: -60px;
|
@@ -21,8 +21,8 @@ a {
|
|
21
21
|
.sudo-form {
|
22
22
|
background-color: #fff;
|
23
23
|
border-radius: 5px;
|
24
|
-
padding:
|
25
|
-
margin:
|
24
|
+
padding: 2em;
|
25
|
+
margin: 0 auto;
|
26
26
|
max-width: 340px;
|
27
27
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
|
28
28
|
|
@@ -30,22 +30,24 @@ a {
|
|
30
30
|
display: block;
|
31
31
|
width: 100%;
|
32
32
|
font-size: 16px;
|
33
|
-
line-height:
|
34
|
-
padding:
|
33
|
+
line-height: 2em;
|
34
|
+
padding: 4px;
|
35
35
|
border-radius: 5px;
|
36
36
|
border: 1px solid #ececec;
|
37
37
|
}
|
38
38
|
|
39
39
|
input[type="submit"] {
|
40
|
-
|
40
|
+
cursor: pointer;
|
41
|
+
margin: 1em auto;
|
41
42
|
width: 60%;
|
42
43
|
padding: 4px;
|
43
44
|
background-color: #ececec;
|
44
45
|
border-radius: 25px;
|
46
|
+
border: none;
|
45
47
|
}
|
46
48
|
}
|
47
49
|
|
48
50
|
.sudo-tip {
|
49
|
-
margin-top:
|
51
|
+
margin-top: 2em;
|
50
52
|
font-size: 14px;
|
51
53
|
}
|
@@ -4,7 +4,7 @@ module SudoRails
|
|
4
4
|
|
5
5
|
def confirm
|
6
6
|
if request.post? && SudoRails.confirm?(self, params[:password])
|
7
|
-
session[:
|
7
|
+
session[:sudo_session] = Time.zone.now.to_s
|
8
8
|
redirect_to params[:target_path]
|
9
9
|
else
|
10
10
|
render 'sudo_rails/confirm_form', layout: SudoRails.get_layout
|
@@ -1,12 +1,24 @@
|
|
1
1
|
module SudoRails
|
2
2
|
module ControllerExt
|
3
|
-
|
4
|
-
before_action(options) do
|
5
|
-
next unless SudoRails.enabled
|
6
|
-
next if SudoRails.valid_sudo_session?(session[:sudo_rails_session])
|
3
|
+
extend ActiveSupport::Concern
|
7
4
|
|
8
|
-
|
5
|
+
class_methods do
|
6
|
+
def sudo(options = {})
|
7
|
+
before_action(options) do
|
8
|
+
next unless SudoRails.enabled
|
9
|
+
next if SudoRails.valid_sudo_session?(session[:sudo_session])
|
10
|
+
|
11
|
+
render 'sudo_rails/confirm_form', layout: SudoRails.get_layout
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
15
|
+
|
16
|
+
def reset_sudo_session!
|
17
|
+
session[:sudo_session] = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def extend_sudo_session!
|
21
|
+
session[:sudo_session] = Time.zone.now.to_s
|
22
|
+
end
|
11
23
|
end
|
12
24
|
end
|
data/lib/sudo_rails/engine.rb
CHANGED
data/lib/sudo_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sudo_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|