sudo_rails 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2821f59e07ff5cf145c875ae4d4c0b07050c497049b7af81021d16a83f236e8
4
- data.tar.gz: 43013b0b6fe93d5e4545ea99349377471143319387c25db87883e62fb879d89b
3
+ metadata.gz: ba7183412184ec9c6e3308162ec026f8ae7711d97513dc776b3229354853f0f6
4
+ data.tar.gz: 63ded2e09b66ea79ddca371e07d3bdf77a5b5a3c46fe61a7594268007a778d6a
5
5
  SHA512:
6
- metadata.gz: d1b5922d85d60a7860a8a18ad6b98077bcd27a17a1947b64a2b1989ee5e47a6a17c48607c669442b57c6f259c9d64fef0822dc951f933474687549f82c93fefc
7
- data.tar.gz: 78a9a940361f6091376ebeecacc41cce005070bdbff78780f6cb0027f9c4955fc37b8f468af414181a0a95a2cda3e40b8fedbb836df0943777c3c97658cbdccc
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 implementation
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: 40px auto;
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: 20px;
25
- margin: 10px auto;
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: 30px;
34
- padding: 2px;
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
- margin: 20px auto;
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: 30px;
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[:sudo_rails_session] = Time.zone.now.to_s
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
- def sudo(options = {})
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
- render 'sudo_rails/confirm_form', layout: SudoRails.get_layout
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
@@ -4,7 +4,7 @@ module SudoRails
4
4
 
5
5
  initializer "sudo_rails.controller_ext" do
6
6
  ActiveSupport.on_load(:action_controller) do
7
- extend SudoRails::ControllerExt
7
+ include SudoRails::ControllerExt
8
8
  end
9
9
  end
10
10
 
@@ -1,3 +1,3 @@
1
1
  module SudoRails
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.2
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-14 00:00:00.000000000 Z
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails