simple_auth 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +7 -1
- data/README.md +16 -1
- data/Rakefile +4 -1
- data/lib/simple_auth.rb +1 -0
- data/lib/simple_auth/action_controller.rb +2 -1
- data/lib/simple_auth/config.rb +4 -0
- data/lib/simple_auth/templates/install/initializer.rb +4 -0
- data/lib/simple_auth/version.rb +1 -1
- data/test/controllers/pages_controller_test.rb +11 -0
- data/test/test_helper.rb +4 -2
- 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: 3d766e5009401ad9ed59c71e123f83046e23ea750ed8cc1f0aa7d3d3953f4185
|
4
|
+
data.tar.gz: fefbd6744a260ded45f3cb53db8fb5d407b0b4c8ac1fac606a9d49ce3321379c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b07279571d5d771fe036f2102a4c9c0333aea5eb8c87816a37c5c1742fd365b60926dd59dfe5e9cd265019a99035b41d250a2d939d711836ce50d50dfcc1ba0
|
7
|
+
data.tar.gz: 896be7f120ffe8154a7b3cdf7b90b4782b9b2f5914454ed8745051c9b1e612180afd0929cb2cd6c5f1286a6179b92e766a697e77b17fab3905e470ec9589d5ab
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# v3.1.2
|
2
|
+
|
3
|
+
- Make flash message key configurable via
|
4
|
+
`SimpleAuth::Config#flash_message_key`.
|
5
|
+
|
1
6
|
# v3.1.1
|
2
7
|
|
3
8
|
- Catch exceptions related to record not found when session tries to load a
|
@@ -18,7 +23,8 @@
|
|
18
23
|
|
19
24
|
# v2.0.3
|
20
25
|
|
21
|
-
- Assign the raw password/confirmation, so we can apply validations on the raw
|
26
|
+
- Assign the raw password/confirmation, so we can apply validations on the raw
|
27
|
+
value.
|
22
28
|
|
23
29
|
# v2.0.2
|
24
30
|
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ SimpleAuth.setup do |config|
|
|
32
32
|
config.scopes = %i[user admin]
|
33
33
|
config.login_url = proc { login_path }
|
34
34
|
config.logged_url = proc { dashboard_path }
|
35
|
+
config.flash_message_key = :alert
|
35
36
|
|
36
37
|
config.install_helpers!
|
37
38
|
end
|
@@ -143,12 +144,26 @@ These are the translations you'll need:
|
|
143
144
|
en:
|
144
145
|
simple_auth:
|
145
146
|
user:
|
146
|
-
need_to_be_logged_in: "You need to be logged"
|
147
|
+
need_to_be_logged_in: "You need to be logged in"
|
147
148
|
not_authorized: "You don't have permission to access this page"
|
148
149
|
```
|
149
150
|
|
150
151
|
If you don't set these translations, a default message will be used.
|
151
152
|
|
153
|
+
To display the error message, use something like `<%= flash[:alert] %>`. If you
|
154
|
+
want to use a custom key, say `:error`, use the configuration file
|
155
|
+
`config/initializers/simple_auth.rb` to define the new key:
|
156
|
+
|
157
|
+
# config/initializers/simple_auth.rb
|
158
|
+
SimpleAuth.setup do |config|
|
159
|
+
# ...
|
160
|
+
|
161
|
+
config.flash_message_key = :error
|
162
|
+
|
163
|
+
# ...
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
152
167
|
## Maintainer
|
153
168
|
|
154
169
|
* Nando Vieira (<http://nandovieira.com>)
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rake/testtask"
|
5
|
+
require "rubocop/rake_task"
|
5
6
|
|
6
7
|
Rake::TestTask.new(:test) do |t|
|
7
8
|
t.libs << "test"
|
@@ -9,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
9
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: %i[test rubocop]
|
data/lib/simple_auth.rb
CHANGED
@@ -55,10 +55,11 @@ module SimpleAuth
|
|
55
55
|
|
56
56
|
private def simple_auth_require_logged_scope(scope)
|
57
57
|
action = RequireLoginAction.new(self, scope)
|
58
|
+
|
58
59
|
return if action.valid?
|
59
60
|
|
60
61
|
reset_session
|
61
|
-
flash[
|
62
|
+
flash[simple_auth.flash_message_key] = action.message
|
62
63
|
session[:return_to] = request.fullpath if request.get?
|
63
64
|
redirect_to instance_eval(&simple_auth.login_url)
|
64
65
|
end
|
data/lib/simple_auth/config.rb
CHANGED
@@ -16,6 +16,10 @@ module SimpleAuth
|
|
16
16
|
# Default to `dashboard_path`.
|
17
17
|
attr_accessor :logged_url
|
18
18
|
|
19
|
+
# Set the flash message key.
|
20
|
+
# This will be used when setting messages for unlogged/unauthorized users.
|
21
|
+
attr_accessor :flash_message_key
|
22
|
+
|
19
23
|
def install_helpers!
|
20
24
|
::ActionController::Base.include SimpleAuth::ActionController
|
21
25
|
end
|
@@ -20,6 +20,10 @@ SimpleAuth.setup do |config|
|
|
20
20
|
# when `before_action :redirect_logged_user` filter is used.
|
21
21
|
config.logged_url = proc { dashboard_path }
|
22
22
|
|
23
|
+
# Set the flash message key.
|
24
|
+
# This will be used when setting messages for unlogged/unauthorized users.
|
25
|
+
config.flash_message_key = :alert
|
26
|
+
|
23
27
|
# Install SimpleAuth helpers to the controllers.
|
24
28
|
config.install_helpers!
|
25
29
|
end
|
data/lib/simple_auth/version.rb
CHANGED
@@ -10,11 +10,22 @@ class PagesControllerTest < ActionController::TestCase
|
|
10
10
|
User.delete_all
|
11
11
|
end
|
12
12
|
|
13
|
+
teardown do
|
14
|
+
SimpleAuth.config.flash_message_key = :alert
|
15
|
+
end
|
16
|
+
|
13
17
|
test "sets flash message while redirecting unlogged user" do
|
14
18
|
get :index
|
15
19
|
assert_equal "You must be logged in to access this page.", flash[:alert]
|
16
20
|
end
|
17
21
|
|
22
|
+
test "sets flash message using custom key" do
|
23
|
+
SimpleAuth.config.flash_message_key = :error
|
24
|
+
|
25
|
+
get :index
|
26
|
+
assert_equal "You must be logged in to access this page.", flash[:error]
|
27
|
+
end
|
28
|
+
|
18
29
|
test "redirects to login url" do
|
19
30
|
get :index
|
20
31
|
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "simplecov"
|
4
|
-
SimpleCov.start
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/test/"
|
6
|
+
end
|
5
7
|
|
6
8
|
require "bundler/setup"
|
7
9
|
require "rack/test"
|
@@ -16,4 +18,4 @@ require "active_record"
|
|
16
18
|
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
17
19
|
require "./test/support/schema"
|
18
20
|
|
19
|
-
Dir["./test/support/**/*.rb"].each {|file| require file }
|
21
|
+
Dir["./test/support/**/*.rb"].sort.each {|file| require file }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: globalid
|