sudo_rails 0.4.3 → 0.7.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: 1f7a8416a4685bd103980482f9dcdc2a8a9a49d797c6b80e698e60710584e357
4
- data.tar.gz: df751eb16572abea6960f841c66eeb4deaa8ca004e33ce9814358786c53e3060
3
+ metadata.gz: 9b83893c9eec976687c8c2025317dc0e3b0b3174cc128868a0d4cdb079c83bfc
4
+ data.tar.gz: cf24b4e05521fc40d24e31e061c5fc71efb0b63af7eacfcff0164d35d60ac0e4
5
5
  SHA512:
6
- metadata.gz: 2b9b0765a6fab1787773fe471d53acc2a5795f4911b6e92074e7bea14066f1b43581a8ee506dfda2fe9affb9648cf9bc1cb778dda490997a241d64f9a259971b
7
- data.tar.gz: c9e88bc579d08dd794e883431042a83ed890470845fa8e76fdf1fb57936e3c40963ff9acc761e267a7e3c8d866f832a43be74783e91bb43e89b6f156a2d4eceb
6
+ metadata.gz: 650c2237a64d202041e45f50b3831362af5077d5f1b35e56482d7c93326482c1b022896cd39a215e199c8a52aaf638db7db0b6a90bf7d5bbbb3e37dddf8e32fb
7
+ data.tar.gz: 25f83106ff3762ff132b442f186f2f82966595a82ee7390fef99a9b3a415b87a6cf882adadf14fb6e283a2f35c2b786673f0ff50bd8230cba7e329cff1bd803c
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
@@ -55,9 +55,9 @@ SudoRails.setup do |config|
55
55
  config.sudo_session_duration = 10.minutes
56
56
 
57
57
  # Confirmation page styling
58
- config.custom_logo = 'logos/medium_dark.png'
59
- config.primary_color = '#1A7191'
60
- config.background_color = '#1A7191'
58
+ config.custom_logo = '/images/logo_medium.png'
59
+ config.primary_color = '#1a7191'
60
+ config.background_color = '#1a1a1a'
61
61
  config.layout = 'admin'
62
62
 
63
63
  # Confirmation strategy implementation
@@ -71,11 +71,19 @@ 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
- See some [examples here](support/images/).
84
+ See some :camera: [examples here](support/images/).
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).
79
87
 
80
88
  ### Confirmation strategy
81
89
 
@@ -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
@@ -3,10 +3,12 @@
3
3
  <head>
4
4
  <title><%= t('sudo_rails.page_header') %></title>
5
5
  <%= csrf_meta_tags %>
6
- <%= stylesheet_link_tag "sudo_rails/application", media: "all" %>
7
- <%= render 'sudo_rails/inject_custom_styles' if SudoRails.custom_styles? %>
6
+ <%= render 'sudo_rails/stylesheet' %>
8
7
  </head>
9
8
  <body>
10
- <%= yield %>
9
+ <%= render 'sudo_rails/flash_alert' %>
10
+ <div class="sudo-container">
11
+ <%= yield %>
12
+ </div>
11
13
  </body>
12
14
  </html>
@@ -0,0 +1,5 @@
1
+ <% if flash[:alert].present? %>
2
+ <div class="sudo-alert">
3
+ <span><%= flash[:alert] %></span>
4
+ </div>
5
+ <% end %>
@@ -0,0 +1,93 @@
1
+ <style type="text/css">
2
+ body {
3
+ text-align: center;
4
+ font-family: Helvetica, Arial, sans-serif;
5
+ background-color: #ececec;
6
+ margin: 0 auto;
7
+ }
8
+
9
+ a {
10
+ color: #000;
11
+ }
12
+
13
+ input {
14
+ -webkit-appearance: none;
15
+ }
16
+
17
+ .sudo-container {
18
+ transform: translateY(25%);
19
+ }
20
+
21
+ .sudo-header {
22
+ margin: 2em auto;
23
+ }
24
+
25
+ .sudo-header img {
26
+ margin-top: -60px;
27
+ max-width: 280px;
28
+ }
29
+
30
+ .sudo-form {
31
+ background-color: #fff;
32
+ border-radius: 5px;
33
+ padding: 2em;
34
+ margin: 0 auto;
35
+ max-width: 340px;
36
+ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
37
+ }
38
+
39
+ .sudo-form input {
40
+ display: block;
41
+ width: 100%;
42
+ font-size: 16px;
43
+ line-height: 2em;
44
+ padding: 4px;
45
+ border-radius: 5px;
46
+ border: 1px solid #ececec;
47
+ }
48
+
49
+ .sudo-form input[type="submit"] {
50
+ cursor: pointer;
51
+ margin: 1em auto;
52
+ width: 60%;
53
+ padding: 4px;
54
+ background-color: #ececec;
55
+ border-radius: 25px;
56
+ border: none;
57
+ }
58
+
59
+ .sudo-tip {
60
+ margin-top: 2em;
61
+ font-size: 14px;
62
+ }
63
+
64
+ .sudo-alert {
65
+ background: #000;
66
+ color: #fff;
67
+ padding: 10px;
68
+ font-weight: bold;
69
+ }
70
+
71
+ <% if SudoRails.background_color.present? %>
72
+ body {
73
+ background-color: <%= SudoRails.background_color %>;
74
+ color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
75
+ }
76
+
77
+ .sudo-alert {
78
+ background-color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
79
+ color: <%= SudoRails.background_color %>;
80
+ }
81
+ <% end %>
82
+
83
+ <% if SudoRails.primary_color.present? %>
84
+ a {
85
+ color: <%= SudoRails.primary_color %>;
86
+ }
87
+
88
+ .sudo-form input[type="submit"] {
89
+ background-color: <%= SudoRails.primary_color %>;
90
+ color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
91
+ }
92
+ <% end %>
93
+ </style>
@@ -1,6 +1,6 @@
1
1
  <div class='sudo-header'>
2
2
  <% if SudoRails.custom_logo %>
3
- <%= image_tag SudoRails.custom_logo %>
3
+ <img src="<%= SudoRails.custom_logo %>">
4
4
  <% end %>
5
5
 
6
6
  <h2><%= t('sudo_rails.page_header') %></h2>
@@ -8,6 +8,7 @@
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>.
data/lib/sudo_rails.rb CHANGED
@@ -2,7 +2,6 @@ require "sudo_rails/version"
2
2
  require "sudo_rails/controller_ext"
3
3
  require "sudo_rails/styling"
4
4
  require "sudo_rails/engine"
5
- require "sassc-rails"
6
5
 
7
6
  module SudoRails
8
7
  class << self
@@ -30,6 +29,7 @@ module SudoRails
30
29
 
31
30
  def valid_sudo_session?(started_at)
32
31
  return false unless started_at
32
+ return true if sudo_session_duration.nil?
33
33
 
34
34
  DateTime.parse(started_at) + sudo_session_duration > Time.zone.now
35
35
  end
@@ -10,12 +10,8 @@ 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
-
17
- config.assets.precompile << %w(
18
- sudo_rails/application.css
19
- )
20
16
  end
21
17
  end
@@ -4,15 +4,10 @@ module SudoRails
4
4
  SudoRails.layout || 'sudo_rails/application'
5
5
  end
6
6
 
7
- def custom_styles?
8
- SudoRails.primary_color.present? || SudoRails.background_color.present?
9
- end
10
-
11
- # Ref: https://gist.github.com/charliepark/480358
12
7
  def color_contrast(hex_color)
13
8
  return nil unless hex_color.include?('#')
14
9
 
15
- hex_color.delete('#').scan(/../).sum { |color| color.hex } > 382.5 ? '#000' : '#FFF'
10
+ hex_color.delete('#').scan(/../).sum { |color| color.hex } > 382.5 ? '#000' : '#fff'
16
11
  end
17
12
  end
18
13
  end
@@ -1,3 +1,3 @@
1
1
  module SudoRails
2
- VERSION = "0.4.3"
2
+ VERSION = "0.7.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.4.3
4
+ version: 0.7.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-06-04 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
- - !ruby/object:Gem::Dependency
28
- name: sassc-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec-rails
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,10 +48,10 @@ files:
62
48
  - LICENSE
63
49
  - README.md
64
50
  - Rakefile
65
- - app/assets/stylesheets/sudo_rails/application.scss
66
51
  - app/controllers/sudo_rails/application_controller.rb
67
52
  - app/views/layouts/sudo_rails/application.html.erb
68
- - app/views/sudo_rails/_inject_custom_styles.html.erb
53
+ - app/views/sudo_rails/_flash_alert.html.erb
54
+ - app/views/sudo_rails/_stylesheet.html.erb
69
55
  - app/views/sudo_rails/confirm_form.html.erb
70
56
  - config/locales/en.yml
71
57
  - lib/sudo_rails.rb
@@ -94,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
80
  - !ruby/object:Gem::Version
95
81
  version: '0'
96
82
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.7.6
83
+ rubygems_version: 3.0.3
99
84
  signing_key:
100
85
  specification_version: 4
101
86
  summary: Sudo mode for Rails
@@ -1,57 +0,0 @@
1
- body {
2
- text-align: center;
3
- font-family: Helvetica, Arial, sans-serif;
4
- background-color: #ececec;
5
- transform: translateY(20%);
6
- }
7
-
8
- a {
9
- color: #000;
10
- }
11
-
12
- input {
13
- -webkit-appearance: none;
14
- }
15
-
16
- .sudo-header {
17
- margin: 2em auto;
18
-
19
- img {
20
- margin-top: -60px;
21
- max-width: 280px;
22
- }
23
- }
24
-
25
- .sudo-form {
26
- background-color: #fff;
27
- border-radius: 5px;
28
- padding: 2em;
29
- margin: 0 auto;
30
- max-width: 340px;
31
- box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
32
-
33
- input {
34
- display: block;
35
- width: 100%;
36
- font-size: 16px;
37
- line-height: 2em;
38
- padding: 4px;
39
- border-radius: 5px;
40
- border: 1px solid #ececec;
41
- }
42
-
43
- input[type="submit"] {
44
- cursor: pointer;
45
- margin: 1em auto;
46
- width: 60%;
47
- padding: 4px;
48
- background-color: #ececec;
49
- border-radius: 25px;
50
- border: none;
51
- }
52
- }
53
-
54
- .sudo-tip {
55
- margin-top: 2em;
56
- font-size: 14px;
57
- }
@@ -1,19 +0,0 @@
1
- <style type="text/css">
2
- <% if SudoRails.background_color.present? %>
3
- body {
4
- background-color: <%= SudoRails.background_color %>;
5
- color: <%= SudoRails.color_contrast(SudoRails.background_color) %>;
6
- }
7
- <% end %>
8
-
9
- <% if SudoRails.primary_color.present? %>
10
- a {
11
- color: <%= SudoRails.primary_color %>;
12
- }
13
-
14
- .sudo-form input[type="submit"] {
15
- background-color: <%= SudoRails.primary_color %>;
16
- color: <%= SudoRails.color_contrast(SudoRails.primary_color) %>;
17
- }
18
- <% end %>
19
- </style>