sudo_rails 0.4.2 → 0.6.1

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: e04886523eeb3e505d51589c8c81977f44b18f301c232aae316e31f0381408ab
4
- data.tar.gz: 264ee3d57e0dbfe2c32cdf0b74d11d354885e51a4725b994d3c0fa78b03d8d7d
3
+ metadata.gz: 6ed6d190a51d927747f58d7ce61af01b6dd8ab0edff663969773ebbbebd21b37
4
+ data.tar.gz: 85f9dc0920bdc8226b36053b06c4304b45b55f90a4735b22faed4334a7a87ad1
5
5
  SHA512:
6
- metadata.gz: c30d7a962a06ba9919ec3950f12c1c6adae42657e4859e87e99ed7df88c79222399a122cf5feed55e876340315efabe23a232ec7f1ec611473cd44768a79eb7c
7
- data.tar.gz: b8f58cda73240aabb8ea75e0e14fd29157384d54a2feeb2b9421f9796f15cd128224e47409fd9c8fca7b236ac38961b65cc7ca61413aa82e1d17c449798c305f
6
+ metadata.gz: ef19bd450721d754b582ebe425dcdf30e91758089593743ed16fadd2400ac4cb2e898e336000a840fed37ac69124138cf5105953ff2342cdf3b37b45c6295196
7
+ data.tar.gz: 76a63a6de298a85130286495533149325a752c772bcf0a4d3d33ccb20e9645563397c9dca75f0c9174f46e9924b02d58b89a4de5919067ffd2f00cd2cd540bf7
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2019 Marc Anguera Insa @markets
1
+ Copyright 2019-2020 Marc Anguera Insa @markets
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Sudo Rails
2
2
 
3
3
  [![Gem](https://img.shields.io/gem/v/sudo_rails.svg?style=flat-square)](https://rubygems.org/gems/sudo_rails)
4
- [![Build Status](https://travis-ci.org/markets/sudo_rails.svg)](https://travis-ci.org/markets/sudo_rails)
4
+ [![Build Status](https://travis-ci.com/markets/sudo_rails.svg?branch=master)](https://travis-ci.com/markets/sudo_rails)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/322350adc7ab052beccb/maintainability)](https://codeclimate.com/github/markets/sudo_rails/maintainability)
6
6
 
7
7
  > Sudo mode for your Rails controllers
@@ -71,12 +71,20 @@ SudoRails.setup do |config|
71
71
  end
72
72
  ```
73
73
 
74
+ ### Sudo sessions
75
+
76
+ Using the `sudo_session_duration` option you are able to configure the `sudo` session duration (30 minutes by default).
77
+
78
+ If you set it to `nil`, your `sudo` session won't expire automatically and you will have to do it manually by using the `reset_sudo_session!` helper.
79
+
74
80
  ### Styling
75
81
 
76
82
  Using the `custom_logo`, `primary_color` and `background_color` options, you can customize the confirmation page. In case you want full control of the styles, you can use your own layout (and consequently your own styles too) using the `layout` option.
77
83
 
78
84
  See some [examples here](support/images/).
79
85
 
86
+ **NOTE** If you are using your own layout, don't forget to render the flash messages in that layout. You can do something like [this](app/views/sudo_rails/_flash_alert.html.erb).
87
+
80
88
  ### Confirmation strategy
81
89
 
82
90
  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.
@@ -2,7 +2,7 @@ body {
2
2
  text-align: center;
3
3
  font-family: Helvetica, Arial, sans-serif;
4
4
  background-color: #ececec;
5
- transform: translateY(20%);
5
+ margin: 0 auto;
6
6
  }
7
7
 
8
8
  a {
@@ -13,6 +13,10 @@ input {
13
13
  -webkit-appearance: none;
14
14
  }
15
15
 
16
+ .sudo-container {
17
+ transform: translateY(25%);
18
+ }
19
+
16
20
  .sudo-header {
17
21
  margin: 2em auto;
18
22
 
@@ -54,4 +58,11 @@ input {
54
58
  .sudo-tip {
55
59
  margin-top: 2em;
56
60
  font-size: 14px;
57
- }
61
+ }
62
+
63
+ .sudo-alert {
64
+ background: #000;
65
+ color: #fff;
66
+ padding: 10px;
67
+ font-weight: bold;
68
+ }
@@ -3,12 +3,13 @@ module SudoRails
3
3
  before_action :sudo_enabled?
4
4
 
5
5
  def confirm
6
- if request.post? && SudoRails.confirm?(self, params[:password])
6
+ if SudoRails.confirm?(self, params[:password])
7
7
  session[:sudo_session] = Time.zone.now.to_s
8
- redirect_to params[:target_path]
9
8
  else
10
- render 'sudo_rails/confirm_form', layout: SudoRails.get_layout
9
+ flash[:alert] = I18n.t('sudo_rails.invalid_pass', locale: params[:locale])
11
10
  end
11
+
12
+ redirect_to params[:target_path]
12
13
  end
13
14
 
14
15
  private
@@ -7,6 +7,9 @@
7
7
  <%= render 'sudo_rails/inject_custom_styles' if SudoRails.custom_styles? %>
8
8
  </head>
9
9
  <body>
10
- <%= yield %>
10
+ <%= render 'sudo_rails/flash_alert' %>
11
+ <div class="sudo-container">
12
+ <%= yield %>
13
+ </div>
11
14
  </body>
12
15
  </html>
@@ -0,0 +1,5 @@
1
+ <% if flash[:alert].present? %>
2
+ <div class="sudo-alert">
3
+ <span><%= flash[:alert] %></span>
4
+ </div>
5
+ <% end %>
@@ -4,6 +4,11 @@
4
4
  background-color: <%= SudoRails.background_color %>;
5
5
  color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
6
6
  }
7
+
8
+ .sudo-alert {
9
+ background-color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
10
+ color: <%= SudoRails.background_color %>;
11
+ }
7
12
  <% end %>
8
13
 
9
14
  <% if SudoRails.primary_color.present? %>
@@ -16,4 +21,4 @@
16
21
  color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
17
22
  }
18
23
  <% end %>
19
- </style>
24
+ </style>
@@ -1,13 +1,14 @@
1
- <header class='sudo-header'>
1
+ <div class='sudo-header'>
2
2
  <% if SudoRails.custom_logo %>
3
3
  <%= image_tag SudoRails.custom_logo %>
4
4
  <% end %>
5
5
 
6
6
  <h2><%= t('sudo_rails.page_header') %></h2>
7
- </header>
7
+ </div>
8
8
 
9
9
  <div class='sudo-form'>
10
10
  <%= form_tag '/sudo_rails/confirm' do |f| %>
11
+ <%= hidden_field_tag :locale, I18n.locale %>
11
12
  <%= hidden_field_tag :target_path, params[:target_path] || request.url %>
12
13
  <%= password_field_tag :password, nil, required: true, placeholder: t('sudo_rails.password') %>
13
14
  <%= submit_tag t('sudo_rails.button') %>
@@ -18,6 +19,8 @@
18
19
  <% end %>
19
20
  </div>
20
21
 
21
- <div class='sudo-tip'>
22
- <%= t('sudo_rails.tip', session_duration: time_ago_in_words(SudoRails.sudo_session_duration.ago)).html_safe %>
23
- </div>
22
+ <% unless SudoRails.sudo_session_duration.nil? %>
23
+ <div class='sudo-tip'>
24
+ <%= t('sudo_rails.tip', session_duration: time_ago_in_words(SudoRails.sudo_session_duration.ago)).html_safe %>
25
+ </div>
26
+ <% end %>
@@ -4,6 +4,7 @@ en:
4
4
  button: Confirm password
5
5
  password: Password
6
6
  forgot_pass: Forgot your password?
7
+ invalid_pass: Invalid password
7
8
  tip: |-
8
9
  You are entering <b>sudo mode</b>.<br>
9
10
  We won’t ask for your password again for <i>%{session_duration}</i>.
@@ -30,6 +30,7 @@ module SudoRails
30
30
 
31
31
  def valid_sudo_session?(started_at)
32
32
  return false unless started_at
33
+ return true if sudo_session_duration.nil?
33
34
 
34
35
  DateTime.parse(started_at) + sudo_session_duration > Time.zone.now
35
36
  end
@@ -10,7 +10,7 @@ module SudoRails
10
10
 
11
11
  initializer 'sudo_rails.routes' do |app|
12
12
  app.routes.append do
13
- match '/sudo_rails/confirm' => 'sudo_rails/application#confirm', via: [:get, :post]
13
+ post '/sudo_rails/confirm' => 'sudo_rails/application#confirm'
14
14
  end
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module SudoRails
2
- VERSION = "0.4.2"
2
+ VERSION = "0.6.1"
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.4.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-03 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,6 +65,7 @@ files:
65
65
  - app/assets/stylesheets/sudo_rails/application.scss
66
66
  - app/controllers/sudo_rails/application_controller.rb
67
67
  - app/views/layouts/sudo_rails/application.html.erb
68
+ - app/views/sudo_rails/_flash_alert.html.erb
68
69
  - app/views/sudo_rails/_inject_custom_styles.html.erb
69
70
  - app/views/sudo_rails/confirm_form.html.erb
70
71
  - config/locales/en.yml
@@ -94,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.7.6
98
+ rubygems_version: 3.0.3
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Sudo mode for Rails